Compare commits

...

5 Commits

Author SHA1 Message Date
Jimmy d803fd81a5 Add pwm examples 2021-06-17 19:52:50 +12:00
Jimmy de247b3354 Put reading in a loop 2021-06-17 19:52:27 +12:00
Jimmy 164d686df3 Add pin change interrupt 2021-06-17 19:52:02 +12:00
Jimmy 4b49cfc8b5 Change pin. Add try catch 2021-06-17 19:51:37 +12:00
Jimmy a5547b3b45 Add button example 2021-06-17 19:51:13 +12:00
6 changed files with 70 additions and 5 deletions

10
button/button.py Normal file
View File

@ -0,0 +1,10 @@
from machine import Pin
from time import sleep
button = Pin(13, Pin.IN) #D7
button2 = Pin(14, Pin.IN) #d5
while True:
print(button.value(), button2.value())
sleep(1)

View File

@ -1,7 +1,10 @@
import dht
import machine
d = dht.DHT11(machine.Pin(16))
d = dht.DHT11(machine.Pin(12))
d.measure()
print(d.temperature())
print(d.humidity())
try:
d.measure()
print(d.temperature())
print(d.humidity())
except Exception as e:
print(e)

17
interrupt/external.py Normal file
View File

@ -0,0 +1,17 @@
from machine import Pin
from time import sleep
led = Pin(2, Pin.OUT)
def callback(p):
print('pin change', p, p.value())
sleep(0.1)
button1 = Pin(13, Pin.IN)
button1.irq(trigger=Pin.IRQ_FALLING, handler=callback)
button2 = Pin(14, Pin.IN)
button2.irq(trigger=Pin.IRQ_FALLING, handler=callback)
while True:
pass

View File

@ -1,5 +1,8 @@
from machine import ADC
from time import sleep
ldr = ADC(0)
print(ldr.read())
while True:
print(ldr.read())
sleep(1)

15
pwm/led.py Normal file
View File

@ -0,0 +1,15 @@
from machine import Pin
from machine import PWM
from time import sleep
led = PWM(Pin(0, Pin.OUT))
for i in range(-1, 1024, 8):
led.duty(i)
print(i)
sleep(0.1)
for i in range(1023, -1, -8):
led.duty(i)
print(i)
sleep(0.1)

17
pwm/rgb.py Normal file
View File

@ -0,0 +1,17 @@
from machine import Pin
from time import sleep
blue = Pin(0, Pin.OUT)
green = Pin(4, Pin.OUT)
red = Pin(5, Pin.OUT)
blue.off()
red.on()
sleep(1)
red.off()
green.on()
sleep(1)
green.off()
blue.on()
sleep(1)
blue.off()