Chris Styles
/
PCA9532_HelloWorld
Hello World example for PCA9532 Library
main.cpp@0:836d73d25007, 2010-05-07 (annotated)
- Committer:
- chris
- Date:
- Fri May 07 10:30:15 2010 +0000
- Revision:
- 0:836d73d25007
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
chris | 0:836d73d25007 | 1 | /* mbed PCA9532 LED Driver Library - Hello World Example |
chris | 0:836d73d25007 | 2 | * |
chris | 0:836d73d25007 | 3 | * Copyright (c) 2010, cstyles (http://mbed.org) |
chris | 0:836d73d25007 | 4 | * |
chris | 0:836d73d25007 | 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
chris | 0:836d73d25007 | 6 | * of this software and associated documentation files (the "Software"), to deal |
chris | 0:836d73d25007 | 7 | * in the Software without restriction, including without limitation the rights |
chris | 0:836d73d25007 | 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
chris | 0:836d73d25007 | 9 | * copies of the Software, and to permit persons to whom the Software is |
chris | 0:836d73d25007 | 10 | * furnished to do so, subject to the following conditions: |
chris | 0:836d73d25007 | 11 | * |
chris | 0:836d73d25007 | 12 | * The above copyright notice and this permission notice shall be included in |
chris | 0:836d73d25007 | 13 | * all copies or substantial portions of the Software. |
chris | 0:836d73d25007 | 14 | * |
chris | 0:836d73d25007 | 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
chris | 0:836d73d25007 | 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
chris | 0:836d73d25007 | 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
chris | 0:836d73d25007 | 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
chris | 0:836d73d25007 | 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
chris | 0:836d73d25007 | 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
chris | 0:836d73d25007 | 21 | * THE SOFTWARE. |
chris | 0:836d73d25007 | 22 | */ |
chris | 0:836d73d25007 | 23 | |
chris | 0:836d73d25007 | 24 | #include "mbed.h" |
chris | 0:836d73d25007 | 25 | #include "PCA9532.h" |
chris | 0:836d73d25007 | 26 | |
chris | 0:836d73d25007 | 27 | PCA9532 leds (p28, p27, 0xc0); |
chris | 0:836d73d25007 | 28 | |
chris | 0:836d73d25007 | 29 | int main() { |
chris | 0:836d73d25007 | 30 | |
chris | 0:836d73d25007 | 31 | // Set LED15 to blink |
chris | 0:836d73d25007 | 32 | leds.Period(1, 0.1); |
chris | 0:836d73d25007 | 33 | leds.Duty(1, 0.5); |
chris | 0:836d73d25007 | 34 | leds.SetLed(15, MODE_PWM1); |
chris | 0:836d73d25007 | 35 | |
chris | 0:836d73d25007 | 36 | // LED0-14 will fade up in turn |
chris | 0:836d73d25007 | 37 | while (1) { |
chris | 0:836d73d25007 | 38 | |
chris | 0:836d73d25007 | 39 | // 0x7FFF enables LED 0-14, which are being switched off |
chris | 0:836d73d25007 | 40 | leds.SetMode(0x7fff, MODE_OFF); |
chris | 0:836d73d25007 | 41 | |
chris | 0:836d73d25007 | 42 | // For each LED in turn |
chris | 0:836d73d25007 | 43 | for (int i = 0 ; i < 15 ; i++) { |
chris | 0:836d73d25007 | 44 | |
chris | 0:836d73d25007 | 45 | // Switch PWM to off, and connect LED(i) |
chris | 0:836d73d25007 | 46 | leds.Duty(0, 0.0); |
chris | 0:836d73d25007 | 47 | leds.SetLed(i, MODE_PWM0); |
chris | 0:836d73d25007 | 48 | |
chris | 0:836d73d25007 | 49 | // Fade LED(i) from 0 to 1.0 |
chris | 0:836d73d25007 | 50 | for (float j = 0.0 ; j < 1.0 ; j+=0.01) { |
chris | 0:836d73d25007 | 51 | leds.Duty(0,j); |
chris | 0:836d73d25007 | 52 | wait(0.005); |
chris | 0:836d73d25007 | 53 | } |
chris | 0:836d73d25007 | 54 | |
chris | 0:836d73d25007 | 55 | // Set LED(i) to continuously ON |
chris | 0:836d73d25007 | 56 | // this stops it fading out and in again with LED(i+1) |
chris | 0:836d73d25007 | 57 | leds.SetLed(i, MODE_ON); |
chris | 0:836d73d25007 | 58 | wait (0.01); |
chris | 0:836d73d25007 | 59 | |
chris | 0:836d73d25007 | 60 | } |
chris | 0:836d73d25007 | 61 | |
chris | 0:836d73d25007 | 62 | } // while(1) |
chris | 0:836d73d25007 | 63 | } // main |
chris | 0:836d73d25007 | 64 |