Add a few scripts to the list I had thrown on the pi pico already.
Working on Lights on and off at intervals. Not sure how I want to format it. I'll probably have different scripts and a text file with variables that can be loaded remotely or something. Maybe call each script into the main.py so main.py doesn't get god awfully long. On branch main Your branch is up to date with 'origin/main'. Changes to be committed: new file: Scripts/Flash-on-board-and-led.py modified: Scripts/Lights-on-off-intervals.py new file: Scripts/blink-onboard-led.py new file: Scripts/flashing-led.py new file: Scripts/flowing-lights.py new file: Scripts/led-blink.py new file: Scripts/lightOn.py new file: Scripts/main.py new file: Scripts/pwm.py new file: Scripts/random-number.py new file: Scripts/rgb-led-randomcolor.py
This commit is contained in:
parent
5a4c60b897
commit
9723de2b8c
11
Scripts/Flash-on-board-and-led.py
Normal file
11
Scripts/Flash-on-board-and-led.py
Normal file
@ -0,0 +1,11 @@
|
||||
from machine import Pin, Timer
|
||||
|
||||
ledMachine = machine.Pin("LED", machine.Pin.OUT)
|
||||
led = Pin(12, Pin.OUT)
|
||||
timer = Timer()
|
||||
|
||||
def blink(timer):
|
||||
led.toggle()
|
||||
ledMachine.toggle()
|
||||
|
||||
timer.init(freq=2.5, mode=Timer.PERIODIC, callback=blink)
|
||||
@ -1,4 +1,9 @@
|
||||
import machine
|
||||
led = machine.Pin("LED", machine.Pin.OUT)
|
||||
led.off()
|
||||
led.on()
|
||||
led.off() # Make sure off
|
||||
led.on() # Turn on last command, stays on
|
||||
|
||||
contactorV12 = Pin(12, Pin.OUT)
|
||||
|
||||
contactorV12.off()
|
||||
contactorV12.on()
|
||||
8
Scripts/blink-onboard-led.py
Normal file
8
Scripts/blink-onboard-led.py
Normal file
@ -0,0 +1,8 @@
|
||||
from machine import Pin, Timer
|
||||
led = machine.Pin("LED", machine.Pin.OUT)
|
||||
timer = Timer()
|
||||
|
||||
def blink(timer):
|
||||
led.toggle()
|
||||
|
||||
timer.init(freq=2.5, mode=Timer.PERIODIC, callback=blink)
|
||||
14
Scripts/flashing-led.py
Normal file
14
Scripts/flashing-led.py
Normal file
@ -0,0 +1,14 @@
|
||||
from machine import Pin, PWM
|
||||
from time import sleep
|
||||
|
||||
pwm = PWM(Pin(12))
|
||||
|
||||
pwm.freq(5000)
|
||||
|
||||
while True:
|
||||
for duty in range(65025):
|
||||
pwm.duty_u16(duty)
|
||||
sleep(0.0005)
|
||||
for duty in range(65025, 0, -1):
|
||||
pwm.duty_u16(duty)
|
||||
sleep(0.0005)
|
||||
22
Scripts/flowing-lights.py
Normal file
22
Scripts/flowing-lights.py
Normal file
@ -0,0 +1,22 @@
|
||||
from machine import Pin,PWM
|
||||
from pwm import myPWM
|
||||
import time
|
||||
|
||||
mypwm = myPWM(16, 17, 18, 19, 20, 21, 22, 26, 27, 28)
|
||||
chns = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
|
||||
dutys = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 65535, 32768, 16384, 8192, 4096, 2048, 1024, 512, 256, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
|
||||
delayTimes = 50
|
||||
|
||||
try:
|
||||
while True:
|
||||
for i in range(0, 20):
|
||||
for j in range(0, 10):
|
||||
mypwm.ledcWrite(chns[j], dutys[i+j])
|
||||
time.sleep_ms(delayTimes)
|
||||
|
||||
for i in range(0, 20):
|
||||
for j in range(0, 10):
|
||||
mypwm.ledcWrite(chns[9 -j], dutys[i+j])
|
||||
time.sleep_ms(delayTimes)
|
||||
except:
|
||||
mypwm.deinit()
|
||||
8
Scripts/led-blink.py
Normal file
8
Scripts/led-blink.py
Normal file
@ -0,0 +1,8 @@
|
||||
from machine import Pin, Timer
|
||||
led = Pin(15, Pin.OUT)
|
||||
timer = Timer()
|
||||
|
||||
def blink(timer):
|
||||
led.toggle()
|
||||
|
||||
timer.init(freq=2.5, mode=Timer.PERIODIC, callback=blink)
|
||||
4
Scripts/lightOn.py
Normal file
4
Scripts/lightOn.py
Normal file
@ -0,0 +1,4 @@
|
||||
import machine
|
||||
led = machine.Pin("LED", machine.Pin.OUT)
|
||||
led.off()
|
||||
led.on()
|
||||
12
Scripts/main.py
Normal file
12
Scripts/main.py
Normal file
@ -0,0 +1,12 @@
|
||||
from machine import Pin, Timer
|
||||
|
||||
# First Testing Env
|
||||
# ledMachine = machine.Pin("LED", machine.Pin.OUT)
|
||||
# led = Pin(12, Pin.OUT)
|
||||
# timer = Timer()
|
||||
|
||||
# def blink(timer):
|
||||
# led.toggle()
|
||||
# ledMachine.toggle()
|
||||
|
||||
# timer.init(freq=2.5, mode=Timer.PERIODIC, callback=blink)
|
||||
63
Scripts/pwm.py
Normal file
63
Scripts/pwm.py
Normal file
@ -0,0 +1,63 @@
|
||||
from machine import Pin,PWM
|
||||
|
||||
|
||||
class myPWM():
|
||||
def __init__(self, pwm0: int=16, pwm1: int=17, pwm2: int=18, pwm3: int=19, pwm4: int=20, pwm5: int=21, pwm6: int=22, pwm7: int=26, pwm8: int=27, pwm9: int=28, freq_num: int=10000):
|
||||
self._pwm0 = PWM(Pin(pwm0))
|
||||
self._pwm0.freq(freq_num)
|
||||
self._pwm1 = PWM(Pin(pwm1))
|
||||
self._pwm1.freq(freq_num)
|
||||
self._pwm2 = PWM(Pin(pwm2))
|
||||
self._pwm2.freq(freq_num)
|
||||
self._pwm3 = PWM(Pin(pwm3))
|
||||
self._pwm3.freq(freq_num)
|
||||
self._pwm4 = PWM(Pin(pwm4))
|
||||
self._pwm4.freq(freq_num)
|
||||
self._pwm5 = PWM(Pin(pwm5))
|
||||
self._pwm5.freq(freq_num)
|
||||
self._pwm6 = PWM(Pin(pwm6))
|
||||
self._pwm6.freq(freq_num)
|
||||
self._pwm7 = PWM(Pin(pwm7))
|
||||
self._pwm7.freq(freq_num)
|
||||
self._pwm8 = PWM(Pin(pwm8))
|
||||
self._pwm8.freq(freq_num)
|
||||
self._pwm9 = PWM(Pin(pwm9))
|
||||
self._pwm9.freq(freq_num)
|
||||
|
||||
def ledcWrite(self,chn,value):
|
||||
if chn == 0:
|
||||
self._pwm0.duty_u16(value)
|
||||
elif chn == 1:
|
||||
self._pwm1.duty_u16(value)
|
||||
elif chn == 2:
|
||||
self._pwm2.duty_u16(value)
|
||||
elif chn == 3:
|
||||
self._pwm3.duty_u16(value)
|
||||
elif chn == 4:
|
||||
self._pwm4.duty_u16(value)
|
||||
elif chn == 5:
|
||||
self._pwm5.duty_u16(value)
|
||||
elif chn == 6:
|
||||
self._pwm6.duty_u16(value)
|
||||
elif chn == 7:
|
||||
self._pwm7.duty_u16(value)
|
||||
elif chn == 8:
|
||||
self._pwm8.duty_u16(value)
|
||||
elif chn == 9:
|
||||
self._pwm9.duty_u16(value)
|
||||
|
||||
|
||||
|
||||
def deinit(self):
|
||||
self._pwm0.deinit()
|
||||
self._pwm1.deinit()
|
||||
self._pwm2.deinit()
|
||||
self._pwm3.deinit()
|
||||
self._pwm4.deinit()
|
||||
self._pwm5.deinit()
|
||||
self._pwm6.deinit()
|
||||
self._pwm7.deinit()
|
||||
self._pwm8.deinit()
|
||||
self._pwm9.deinit()
|
||||
|
||||
|
||||
3
Scripts/random-number.py
Normal file
3
Scripts/random-number.py
Normal file
@ -0,0 +1,3 @@
|
||||
from random import randint as rand
|
||||
num = rand(1, 100)
|
||||
print(num)
|
||||
33
Scripts/rgb-led-randomcolor.py
Normal file
33
Scripts/rgb-led-randomcolor.py
Normal file
@ -0,0 +1,33 @@
|
||||
from machine import Pin, PWM
|
||||
from random import randint
|
||||
import time
|
||||
|
||||
pins = [15, 14, 13]
|
||||
freq_num = 10000
|
||||
|
||||
pwm0 = PWM(Pin(pins[0])) #set PWM
|
||||
pwm1 = PWM(Pin(pins[1]))
|
||||
pwm2 = PWM(Pin(pins[2]))
|
||||
pwm0.freq(freq_num)
|
||||
pwm1.freq(freq_num)
|
||||
pwm2.freq(freq_num)
|
||||
|
||||
def setColor(r, g, b):
|
||||
pwm0.duty_u16(65535 - r)
|
||||
pwm1.duty_u16(65535 - g)
|
||||
pwm2.duty_u16(65535 - b)
|
||||
|
||||
try:
|
||||
while True:
|
||||
red = randint(0, 65535)
|
||||
green = randint(0, 65535)
|
||||
blue = randint(0, 65535)
|
||||
setColor(red, green, blue)
|
||||
print(red,"Red")
|
||||
print(green,"Green")
|
||||
print(blue,"Blue")
|
||||
time.sleep_ms(200)
|
||||
except:
|
||||
pwm0.deinit()
|
||||
pwm1.deinit()
|
||||
pwm2.deinit()
|
||||
Loading…
x
Reference in New Issue
Block a user