diff --git a/Scripts/Flash-on-board-and-led.py b/Scripts/Flash-on-board-and-led.py new file mode 100644 index 0000000..6ce1933 --- /dev/null +++ b/Scripts/Flash-on-board-and-led.py @@ -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) \ No newline at end of file diff --git a/Scripts/Lights-on-off-intervals.py b/Scripts/Lights-on-off-intervals.py index d0d97f9..412649d 100644 --- a/Scripts/Lights-on-off-intervals.py +++ b/Scripts/Lights-on-off-intervals.py @@ -1,4 +1,9 @@ import machine led = machine.Pin("LED", machine.Pin.OUT) -led.off() -led.on() \ No newline at end of file +led.off() # Make sure off +led.on() # Turn on last command, stays on + +contactorV12 = Pin(12, Pin.OUT) + +contactorV12.off() +contactorV12.on() \ No newline at end of file diff --git a/Scripts/blink-onboard-led.py b/Scripts/blink-onboard-led.py new file mode 100644 index 0000000..38c7251 --- /dev/null +++ b/Scripts/blink-onboard-led.py @@ -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) \ No newline at end of file diff --git a/Scripts/flashing-led.py b/Scripts/flashing-led.py new file mode 100644 index 0000000..ddcbf50 --- /dev/null +++ b/Scripts/flashing-led.py @@ -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) \ No newline at end of file diff --git a/Scripts/flowing-lights.py b/Scripts/flowing-lights.py new file mode 100644 index 0000000..35e0a3c --- /dev/null +++ b/Scripts/flowing-lights.py @@ -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() diff --git a/Scripts/led-blink.py b/Scripts/led-blink.py new file mode 100644 index 0000000..6543f13 --- /dev/null +++ b/Scripts/led-blink.py @@ -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) \ No newline at end of file diff --git a/Scripts/lightOn.py b/Scripts/lightOn.py new file mode 100644 index 0000000..d0d97f9 --- /dev/null +++ b/Scripts/lightOn.py @@ -0,0 +1,4 @@ +import machine +led = machine.Pin("LED", machine.Pin.OUT) +led.off() +led.on() \ No newline at end of file diff --git a/Scripts/main.py b/Scripts/main.py new file mode 100644 index 0000000..6f20322 --- /dev/null +++ b/Scripts/main.py @@ -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) diff --git a/Scripts/pwm.py b/Scripts/pwm.py new file mode 100644 index 0000000..d07c7ed --- /dev/null +++ b/Scripts/pwm.py @@ -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() + + diff --git a/Scripts/random-number.py b/Scripts/random-number.py new file mode 100644 index 0000000..c66655a --- /dev/null +++ b/Scripts/random-number.py @@ -0,0 +1,3 @@ +from random import randint as rand +num = rand(1, 100) +print(num) \ No newline at end of file diff --git a/Scripts/rgb-led-randomcolor.py b/Scripts/rgb-led-randomcolor.py new file mode 100644 index 0000000..7a9a4af --- /dev/null +++ b/Scripts/rgb-led-randomcolor.py @@ -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() \ No newline at end of file