Tags:
create new tag
view all tags

Solutions to Exercise 2: LEDs

Exercise 1:

Here is the screen dump of a REPL session switching the builtin LED on and off:

builtinLED.png

Exercise 2:

This is the most simple program in embedded systems. So... nothing much to say!

https://afnog.iotworkshop.africa/pub/IoT_Course_English/SolutionsToNopLEDsAndNopNeoPixel/blink.py.txt

Exercise 3:

Exercise 3 is not much more difficult neither. We create a function called pulse, which takes a !pulseLength as parameter. This function switches the LED on for pulseLength seconds and off again for another pulseLength seconds. This function is called 3 times with a short !pulseLength, 3 times with a long pulseLength and again 3 times with a short pulseLength.

Here is the code:

https://afnog.iotworkshop.africa/pub/IoT_Course_English/SolutionsToNopLEDsAndNopNeoPixel/sos.py.txt

Exercise 4:

This was an exercise we did during the IoT workshop at the African Internet Summit 2019 in Kampala, Uganda and the solution comes from this workshop.

It defines a function intensityCycle, which increases the PWM duty cycle in steps given by the resolution parameter and keeps this intensity stable for a duration given by the duration parameter. It does so for duty cycle 0 up to duty cycle 1 and then back to duty cyle 0.

At the Kampala workshop we also had a demo program cycling the intensity not in a linear but a sinusoidal fashion. Both programs are given here:

https://afnog.iotworkshop.africa/pub/IoT_Course_English/SolutionsToNopLEDsAndNopNeoPixel/pwmExerciseSol.py.txt : the linear cycle and

https://afnog.iotworkshop.africa/pub/IoT_Course_English/SolutionsToNopLEDsAndNopNeoPixel/pwmLED.py.txt : the sinusoidal cycle

Exercise 5:

Switching on the LEDs one by one we see that

  • address 0 corresponds to the middle LED
  • address 1 to the top LED
  • and the others in clockwise progressing around the circle
https://afnog.iotworkshop.africa/pub/IoT_Course_English/SolutionsToNopLEDsAndNopNeoPixel/ws2812Addresses.py.txt

Exercise 6 and 7:

Once we know the LED addresses it is easy to switch them on clockwise and anticlockwise

https://afnog.iotworkshop.africa/pub/IoT_Course_English/SolutionsToNopLEDsAndNopNeoPixel/ws2812Colors.py.txt

https://afnog.iotworkshop.africa/pub/IoT_Course_English/SolutionsToNopLEDsAndNopNeoPixel/ws2812ColorsCCW.py.txt

Changing the colors is done by passing the corresponding RGB (Red,Green,Blue) values to the WS2812 driver.

-- Uli Raich - 2020-05-06

Comments

Topic attachments
I Attachment History Action Size Date Who Comment
Texttxt blink.py.txt r1 manage 0.6 K 2020-05-06 - 10:00 UliRaich  
PNGpng builtinLED.png r1 manage 17.8 K 2020-05-06 - 09:47 UliRaich  
Texttxt pwmExerciseSol.py.txt r1 manage 1.3 K 2020-05-30 - 15:05 UliRaich  
Texttxt pwmLED.py.txt r1 manage 1.0 K 2020-05-30 - 15:05 UliRaich  
Texttxt sos.py.txt r1 manage 0.9 K 2020-05-30 - 15:05 UliRaich  
Texttxt ws2812Addresses.py.txt r1 manage 1.1 K 2020-05-30 - 15:05 UliRaich  
Texttxt ws2812Colors.py.txt r1 manage 1.3 K 2020-05-30 - 15:05 UliRaich  
Texttxt ws2812ColorsCCW.py.txt r1 manage 1.5 K 2020-05-30 - 15:05 UliRaich  
Edit | Attach | Watch | Print version | History: r2 < r1 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r2 - 2020-05-30 - UliRaich
 
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2024 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback