Chris Styles
/
EA_LEDS
Using the I2C LED driver on the Embedded Artists baseboard to control the LEDS.
main.cpp@0:5d07670e5b83, 2010-03-02 (annotated)
- Committer:
- chris
- Date:
- Tue Mar 02 07:40:02 2010 +0000
- Revision:
- 0:5d07670e5b83
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
chris | 0:5d07670e5b83 | 1 | #include "mbed.h" |
chris | 0:5d07670e5b83 | 2 | #include "PCA9532.h" |
chris | 0:5d07670e5b83 | 3 | |
chris | 0:5d07670e5b83 | 4 | DigitalOut myled(LED1); |
chris | 0:5d07670e5b83 | 5 | |
chris | 0:5d07670e5b83 | 6 | PCA9532 leds (p28,p27,0xc0); |
chris | 0:5d07670e5b83 | 7 | |
chris | 0:5d07670e5b83 | 8 | int main() { |
chris | 0:5d07670e5b83 | 9 | |
chris | 0:5d07670e5b83 | 10 | |
chris | 0:5d07670e5b83 | 11 | // set leds 15-12 to PWM1 channel |
chris | 0:5d07670e5b83 | 12 | leds.pwm1(0xf000); |
chris | 0:5d07670e5b83 | 13 | |
chris | 0:5d07670e5b83 | 14 | // set leds 11-8 to PWM0 channel |
chris | 0:5d07670e5b83 | 15 | leds.pwm0(0x0f00); |
chris | 0:5d07670e5b83 | 16 | |
chris | 0:5d07670e5b83 | 17 | // set leds 7-4 to "off" |
chris | 0:5d07670e5b83 | 18 | leds.clear(0x00f0); |
chris | 0:5d07670e5b83 | 19 | |
chris | 0:5d07670e5b83 | 20 | // set leds 7-4 to "on" |
chris | 0:5d07670e5b83 | 21 | leds.set(0xf); |
chris | 0:5d07670e5b83 | 22 | |
chris | 0:5d07670e5b83 | 23 | |
chris | 0:5d07670e5b83 | 24 | while (1) { |
chris | 0:5d07670e5b83 | 25 | |
chris | 0:5d07670e5b83 | 26 | for (float i = 0.0 ; i < 1.0 ; i+=0.01) { |
chris | 0:5d07670e5b83 | 27 | leds.duty0(i); // PWM0 brighter |
chris | 0:5d07670e5b83 | 28 | leds.duty1(1.0-i); // PWM1 dimmer |
chris | 0:5d07670e5b83 | 29 | wait (0.01); |
chris | 0:5d07670e5b83 | 30 | } |
chris | 0:5d07670e5b83 | 31 | |
chris | 0:5d07670e5b83 | 32 | leds.clear(0xf); // Toggle LEDS |
chris | 0:5d07670e5b83 | 33 | leds.set(0x00f0); |
chris | 0:5d07670e5b83 | 34 | |
chris | 0:5d07670e5b83 | 35 | for (float i = 1.0 ; i > 0.0 ; i-=0.01) { |
chris | 0:5d07670e5b83 | 36 | leds.duty0(i); // PWM0 dimmer |
chris | 0:5d07670e5b83 | 37 | leds.duty1(1.0-i); // PWM1 brighter |
chris | 0:5d07670e5b83 | 38 | |
chris | 0:5d07670e5b83 | 39 | wait (0.01); |
chris | 0:5d07670e5b83 | 40 | } |
chris | 0:5d07670e5b83 | 41 | |
chris | 0:5d07670e5b83 | 42 | leds.clear(0x00f0); // Toggle LEDS |
chris | 0:5d07670e5b83 | 43 | leds.set(0x000f); |
chris | 0:5d07670e5b83 | 44 | |
chris | 0:5d07670e5b83 | 45 | |
chris | 0:5d07670e5b83 | 46 | |
chris | 0:5d07670e5b83 | 47 | } |
chris | 0:5d07670e5b83 | 48 | |
chris | 0:5d07670e5b83 | 49 | } |
chris | 0:5d07670e5b83 | 50 |