From 1d31318c7bedfd3f43575b5bc9135fd8a38ddd1a Mon Sep 17 00:00:00 2001 From: Joachim Hummel Date: Mon, 4 Dec 2023 18:00:57 +0000 Subject: [PATCH] Added 4 December Scripts --- 4-dezember-led-blinken.py | 28 ++++++++++++++++++++++++++++ 4-dezember-led-regelung.py | 28 ++++++++++++++++++++++++++++ README.md | 14 ++++++++++++++ 3 files changed, 70 insertions(+) create mode 100644 4-dezember-led-blinken.py create mode 100644 4-dezember-led-regelung.py diff --git a/4-dezember-led-blinken.py b/4-dezember-led-blinken.py new file mode 100644 index 0000000..e8a18d0 --- /dev/null +++ b/4-dezember-led-blinken.py @@ -0,0 +1,28 @@ +from machine import ADC, Pin, PWM +import time + +# Anschluss Poti an GP27 und an Plus 3.3 Volt und Minus +poti = ADC(Pin(27)) + +# LED +gruen = PWM(Pin(18)) +gelb = PWM(Pin(19)) +rot = PWM(Pin(20)) + +# Variable mdelay = 0 +gruen.freq(1000) +gelb.freq(1000) +rot.freq(1000) + +reading = 0 + +while True: + + reading = poti.read_u16() + print(reading) + gruen.duty_u16(reading) + gelb.duty_u16(reading) + rot.duty_u16(reading) + time.sleep(0.001) + + diff --git a/4-dezember-led-regelung.py b/4-dezember-led-regelung.py new file mode 100644 index 0000000..e8a18d0 --- /dev/null +++ b/4-dezember-led-regelung.py @@ -0,0 +1,28 @@ +from machine import ADC, Pin, PWM +import time + +# Anschluss Poti an GP27 und an Plus 3.3 Volt und Minus +poti = ADC(Pin(27)) + +# LED +gruen = PWM(Pin(18)) +gelb = PWM(Pin(19)) +rot = PWM(Pin(20)) + +# Variable mdelay = 0 +gruen.freq(1000) +gelb.freq(1000) +rot.freq(1000) + +reading = 0 + +while True: + + reading = poti.read_u16() + print(reading) + gruen.duty_u16(reading) + gelb.duty_u16(reading) + rot.duty_u16(reading) + time.sleep(0.001) + + diff --git a/README.md b/README.md index c2d8110..7b6e28f 100644 --- a/README.md +++ b/README.md @@ -25,5 +25,19 @@ Today you have learnt: ------------------------------------------------------------------------------------------------------- +Day 4 Complete! + +Well done makers! We know today was a little heavier as we introduced slightly more advanced topics such as analogue and PWM, so take the time to go back over today's examples and play with the code if you'd like more practice - make it, break it, fix it, learn! + +Today you have: + + Learnt about analogue and the difference between analogue and digital signals + Built a circuit with a potentiometer + Leant how to use the ADC built into the Raspberry Pi Pico + Controlled LEDs with an analogue signal + Learnt about PWM including duty cycle and frequency + +------------------------------------------------------------------------------------------------------ +