Example code and library for the PCF9532 I2C LED driver on the Embedded Artists baseboard
Embed:
(wiki syntax)
Show/hide line numbers
main.cpp
00001 #include "mbed.h" 00002 #include "PCA9532.h" 00003 00004 PCA9532 leds (p28, p27, 0xc0); 00005 00006 int main() { 00007 00008 // Set LED15 to blink 00009 leds.Period(1, 0.1); 00010 leds.Duty(1, 0.5); 00011 leds.SetLed(15, MODE_PWM1); 00012 00013 // LED0-14 will fade up in turn, the reset 00014 00015 while (1) { 00016 00017 // 0x7FFF enables LED 0-14, which are being switched off 00018 leds.SetMode(0x7fff, MODE_OFF); 00019 00020 // For each LED in turn 00021 for (int i = 0 ; i < 15 ; i++) { 00022 00023 // Switch PWM to off, and connect LED(i) 00024 leds.Duty(0, 0.0); 00025 leds.SetLed(i, MODE_PWM0); 00026 00027 // Fade LED(i) from 0 to 1.0 00028 for (float j = 0.0 ; j < 1.0 ; j+=0.01) { 00029 leds.Duty(0,j); 00030 wait(0.005); 00031 } 00032 00033 // Set LED(i) to continuously ON 00034 // this stops it fading out and in again with LED(i+1) 00035 leds.SetLed(i, MODE_ON); 00036 wait (0.01); 00037 00038 } 00039 00040 } // while(1) 00041 } // main 00042
Generated on Fri Aug 26 2022 16:47:10 by
1.7.2