Example of PCA9532 being used on the Embedded Artists Baseboard, this time fading up LEDs using PWM

Dependencies:   mbed

main.cpp

Committer:
chris
Date:
2010-05-07
Revision:
0:0df46cf615c3

File content as of revision 0:0df46cf615c3:

#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