Sample code to demonstrate PCA9955A's gradation control
Diff: main.cpp
- Revision:
- 2:0cc3bba73370
- Parent:
- 0:d65648cc3923
- Child:
- 5:33de84f8a660
diff -r 47c33baeed67 -r 0cc3bba73370 main.cpp
--- a/main.cpp Thu Mar 19 10:50:17 2015 +0000
+++ b/main.cpp Thu Jun 16 23:01:19 2022 +0000
@@ -3,10 +3,17 @@
#include "PCA9955A.h"
PCA9955A led_cntlr( p28, p27, 0x02 ); // SDA, SCL, Slave_address(option)
-#define GRADATION_PERIOD 6.0
+#define GRADATION_PERIOD 6.0
+
+#define MANUAL_BLINK_PERIOD 0.1
+#define MANUAL_BLINK_ON_DURATION 0.03
int main()
{
+ // Set current ourput maximum (1.0 = 100%)
+ led_cntlr.current( ALLPORTS, 1.0 );
+
+ // Gradation control grouping
led_cntlr.gradation_group_setting( 0, 1 ); // Port 1 is assigned to group 0
led_cntlr.gradation_group_setting( 0, 5 ); // Port 5 is assigned to group 0
led_cntlr.gradation_group_setting( 0, 9 ); // Port 9 is assigned to group 0
@@ -47,15 +54,14 @@
//
// Next while loop perform manual control for Rest of ports (0, 4, 8 and 12).
// You will see the operation for manual controll ports will be stopped if the I2C line is removed.
- // But it continues the gradation control if only power supply is available
+ // But it continues the gradation control while power supply is available
//
while(1) {
- for ( int i = 1; i <= 100; i++ ) {
- led_cntlr.pwm( 0, (float)i / 100.0 );
- led_cntlr.pwm( 4, (float)i / 100.0 );
- led_cntlr.pwm( 8, (float)i / 100.0 );
- led_cntlr.pwm( 12, (float)i / 100.0 );
- wait( 0.01 );
+ for ( int i = 0; i <= 12; i += 4 ) {
+ led_cntlr.pwm( i, 1.0 );
+ wait( MANUAL_BLINK_ON_DURATION );
+ led_cntlr.pwm( i, 0.0 );
+ wait( MANUAL_BLINK_PERIOD - MANUAL_BLINK_ON_DURATION );
}
}
-}
\ No newline at end of file
+}