Chris Styles
/
EA_PCA9532_Example
Example of PCA9532 being used on the Embedded Artists Baseboard, this time fading up LEDs using PWM
Diff: main.cpp
- Revision:
- 0:0df46cf615c3
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Fri May 07 12:41:06 2010 +0000 @@ -0,0 +1,42 @@ +#include "mbed.h" +#include "PCA9532.h" + +PCA9532 leds (p28, p27, 0xc0); + +int main() { + + // Set LED15 to blink + leds.Period(1, 0.1); + leds.Duty(1, 0.5); + leds.SetLed(15, MODE_PWM1); + + // LED0-14 will fade up in turn, the reset + + while (1) { + + // 0x7FFF enables LED 0-14, which are being switched off + leds.SetMode(0x7fff, MODE_OFF); + + // For each LED in turn + for (int i = 0 ; i < 15 ; i++) { + + // Switch PWM to off, and connect LED(i) + leds.Duty(0, 0.0); + leds.SetLed(i, MODE_PWM0); + + // Fade LED(i) from 0 to 1.0 + for (float j = 0.0 ; j < 1.0 ; j+=0.01) { + leds.Duty(0,j); + wait(0.005); + } + + // Set LED(i) to continuously ON + // this stops it fading out and in again with LED(i+1) + leds.SetLed(i, MODE_ON); + wait (0.01); + + } + + } // while(1) +} // main +