Chris Styles / Mbed 2 deprecated PCA9532_HelloWorld

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 /* mbed PCA9532 LED Driver Library - Hello World Example
00002  *
00003  * Copyright (c) 2010, cstyles (http://mbed.org)
00004  *
00005  * Permission is hereby granted, free of charge, to any person obtaining a copy
00006  * of this software and associated documentation files (the "Software"), to deal
00007  * in the Software without restriction, including without limitation the rights
00008  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00009  * copies of the Software, and to permit persons to whom the Software is
00010  * furnished to do so, subject to the following conditions:
00011  *
00012  * The above copyright notice and this permission notice shall be included in
00013  * all copies or substantial portions of the Software.
00014  *
00015  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00016  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00017  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00018  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00019  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00020  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00021  * THE SOFTWARE.
00022  */
00023 
00024 #include "mbed.h"
00025 #include "PCA9532.h"
00026 
00027 PCA9532 leds (p28, p27, 0xc0);
00028 
00029 int main() {
00030 
00031     // Set LED15 to blink
00032     leds.Period(1, 0.1);
00033     leds.Duty(1, 0.5);
00034     leds.SetLed(15, MODE_PWM1);
00035 
00036     // LED0-14 will fade up in turn
00037     while (1) {
00038 
00039         // 0x7FFF enables LED 0-14, which are being switched off
00040         leds.SetMode(0x7fff, MODE_OFF);
00041 
00042         // For each LED in turn
00043         for (int i = 0 ; i < 15 ; i++) {
00044 
00045             // Switch PWM to off, and connect LED(i)
00046             leds.Duty(0, 0.0);
00047             leds.SetLed(i, MODE_PWM0);
00048 
00049             // Fade LED(i) from 0 to 1.0
00050             for (float j = 0.0 ; j < 1.0 ; j+=0.01) {
00051                 leds.Duty(0,j);
00052                 wait(0.005);
00053             }
00054 
00055             // Set LED(i) to continuously ON
00056             // this stops it fading out and in again with LED(i+1)
00057             leds.SetLed(i, MODE_ON);
00058             wait (0.01);
00059 
00060         }
00061 
00062     } // while(1)
00063 } // main
00064