Chris Styles
/
EA_PCA9532
Example code and library for the PCF9532 I2C LED driver on the Embedded Artists baseboard
main.cpp@0:a64165168954, 2010-04-27 (annotated)
- Committer:
- chris
- Date:
- Tue Apr 27 13:03:05 2010 +0000
- Revision:
- 0:a64165168954
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
chris | 0:a64165168954 | 1 | #include "mbed.h" |
chris | 0:a64165168954 | 2 | #include "PCA9532.h" |
chris | 0:a64165168954 | 3 | |
chris | 0:a64165168954 | 4 | PCA9532 leds (p28, p27, 0xc0); |
chris | 0:a64165168954 | 5 | |
chris | 0:a64165168954 | 6 | int main() { |
chris | 0:a64165168954 | 7 | |
chris | 0:a64165168954 | 8 | // Set LED15 to blink |
chris | 0:a64165168954 | 9 | leds.Period(1, 0.1); |
chris | 0:a64165168954 | 10 | leds.Duty(1, 0.5); |
chris | 0:a64165168954 | 11 | leds.SetLed(15, MODE_PWM1); |
chris | 0:a64165168954 | 12 | |
chris | 0:a64165168954 | 13 | // LED0-14 will fade up in turn, the reset |
chris | 0:a64165168954 | 14 | |
chris | 0:a64165168954 | 15 | while (1) { |
chris | 0:a64165168954 | 16 | |
chris | 0:a64165168954 | 17 | // 0x7FFF enables LED 0-14, which are being switched off |
chris | 0:a64165168954 | 18 | leds.SetMode(0x7fff, MODE_OFF); |
chris | 0:a64165168954 | 19 | |
chris | 0:a64165168954 | 20 | // For each LED in turn |
chris | 0:a64165168954 | 21 | for (int i = 0 ; i < 15 ; i++) { |
chris | 0:a64165168954 | 22 | |
chris | 0:a64165168954 | 23 | // Switch PWM to off, and connect LED(i) |
chris | 0:a64165168954 | 24 | leds.Duty(0, 0.0); |
chris | 0:a64165168954 | 25 | leds.SetLed(i, MODE_PWM0); |
chris | 0:a64165168954 | 26 | |
chris | 0:a64165168954 | 27 | // Fade LED(i) from 0 to 1.0 |
chris | 0:a64165168954 | 28 | for (float j = 0.0 ; j < 1.0 ; j+=0.01) { |
chris | 0:a64165168954 | 29 | leds.Duty(0,j); |
chris | 0:a64165168954 | 30 | wait(0.005); |
chris | 0:a64165168954 | 31 | } |
chris | 0:a64165168954 | 32 | |
chris | 0:a64165168954 | 33 | // Set LED(i) to continuously ON |
chris | 0:a64165168954 | 34 | // this stops it fading out and in again with LED(i+1) |
chris | 0:a64165168954 | 35 | leds.SetLed(i, MODE_ON); |
chris | 0:a64165168954 | 36 | wait (0.01); |
chris | 0:a64165168954 | 37 | |
chris | 0:a64165168954 | 38 | } |
chris | 0:a64165168954 | 39 | |
chris | 0:a64165168954 | 40 | } // while(1) |
chris | 0:a64165168954 | 41 | } // main |
chris | 0:a64165168954 | 42 |