In Chapter 6, PWM – Writing Analog Information we saw that to control analog devices, BeagleBone uses a PWM subsystem. It generates analog values on some specific pins turning that pin HIGH
and LOW
very fast in patterns. Learning PWM involved learning about frequency, period, duty cycle and average voltage in Chapter 6. The resultant voltage is proportional to the duty cycle. If the duty cycle is increased, the resultant voltage will increase. We generated a range of resultant analog voltage on pin by changing the duty cycle. We did a LED fade in and fade out exercise using PWM. Let's do that program again in Python.
Connect an LED to P9_21
as shown in the diagram in Chapter 6. Type the following program in Cloud9, save it as LED_fade.py
and run. You should be able to see the LED fading in and out for some time.
The following code is for LED_fade.py
:
#!/usr/bin/python import Adafruit_BBIO.PWM as PWM from time import sleep led = "P9_21" PWM.start(led) for...