A simple serial test program for the PCA9952/55 library.

Dependencies:   PCA9955 mbed

Committer:
neilt6
Date:
Tue Apr 08 15:22:37 2014 +0000
Revision:
4:0b1798094768
Parent:
2:3bf093141522
Child:
5:e0d366e2a7f0
Added 5ms wait after reset()

Who changed what in which revision?

UserRevisionLine numberNew contents of line
neilt6 0:6ef5b29b9e14 1 #include "mbed.h"
neilt6 0:6ef5b29b9e14 2 #include "PCA9955.h"
neilt6 0:6ef5b29b9e14 3
neilt6 2:3bf093141522 4 //Create a PCA9955 object using the LED All Call address
neilt6 4:0b1798094768 5 PCA9955 driver(P0_5, P0_4, PCA9955::ADDRESS_ALL);
neilt6 0:6ef5b29b9e14 6
neilt6 0:6ef5b29b9e14 7 int main()
neilt6 0:6ef5b29b9e14 8 {
neilt6 0:6ef5b29b9e14 9 //Try to open the PCA9955
neilt6 0:6ef5b29b9e14 10 if (driver.open()) {
neilt6 0:6ef5b29b9e14 11 printf("Device detected!\n");
neilt6 0:6ef5b29b9e14 12
neilt6 0:6ef5b29b9e14 13 //Reset the device
neilt6 0:6ef5b29b9e14 14 //NOTE: This might reset other I2C devices as well!
neilt6 0:6ef5b29b9e14 15 driver.reset();
neilt6 4:0b1798094768 16 wait_ms(5);
neilt6 0:6ef5b29b9e14 17
neilt6 2:3bf093141522 18 //Set all of the output states to PWM mode
neilt6 0:6ef5b29b9e14 19 driver.allOutputStates(PCA9955::OUTPUT_PWM);
neilt6 0:6ef5b29b9e14 20
neilt6 2:3bf093141522 21 //Set all of the output currents to maximum
neilt6 0:6ef5b29b9e14 22 driver.allOutputCurrents(1.0);
neilt6 0:6ef5b29b9e14 23
neilt6 0:6ef5b29b9e14 24 while (1) {
neilt6 0:6ef5b29b9e14 25 //Generate a breathing effect on all of the outputs
neilt6 0:6ef5b29b9e14 26 for (float i = 0.0f; i < 360.0f; i += 0.1f) {
neilt6 1:899dbe28da72 27 driver = 0.5 * (sinf(i * 3.14159265f / 180.0f) + 1);
neilt6 0:6ef5b29b9e14 28 }
neilt6 0:6ef5b29b9e14 29 }
neilt6 0:6ef5b29b9e14 30 } else {
neilt6 0:6ef5b29b9e14 31 error("Device not detected!\n");
neilt6 0:6ef5b29b9e14 32 }
neilt6 0:6ef5b29b9e14 33 }