Experiment - blink multiple sequences
In this experiment, I want to flash the LED three times rapidly then blink the LED continuously.I created two functions. The first function flashes a LED rapidly three times. To accomplish this, I used a for loop and the sleep function. The second function flashed the LED every second. The 'work' variable calls the two new functions.
Here is the code
Experiment - changing brightness
Let's try something a little bit more complex. I want to be able to control the brightness of the LED. The first thing I did grab the example code (api_led_brightness) from Gobot. My first attempt at running the code failed. The code compiled and seems to run but the LED would not change brightness. It took a bit of head scratching before I remembered the Gobot documentation said something about PWM.The Gobot documentation references pi-blaster. I found that I needed to setup pi-blaster to get the PWM working.
Once I got pi-blaster running on the Raspberry Pi, the example code from Gobot worked. I did encounter a minor weirdness. When I exit the running program, the LED goes to full brightness.
Resources
- Gobot raspi_blink example - https://gobot.io/documentation/examples/raspi_blink/
- Gobot rapi_led_brightness example - https://gobot.io/documentation/examples/raspi_led_brightness/
- Control Brightness of LED Using Raspberry Pi. The code example is in Python. The blog post has a nice description of PWM.
- Gobot documentation for Raspberry Pi - https://gobot.io/documentation/platforms/raspi/
- Pi-blaster - https://github.com/sarfata/pi-blaster
- Software PWM on a Raspberry Pi - http://ozzmaker.com/software-pwm-on-a-raspberry-pi/
No comments:
Post a Comment