Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: PCA9685.h
- Revision:
- 3:f69f4e2c35b6
- Parent:
- 2:fa75aff130cc
--- a/PCA9685.h Tue Nov 07 14:52:15 2017 +0000
+++ b/PCA9685.h Tue Nov 07 17:09:04 2017 +0000
@@ -22,7 +22,71 @@
/**
Example:
-[todo]
+#include "mbed.h"
+#include "PCA9685.h"
+
+PCA9685 myPWMSensor ( I2C_SDA, I2C_SCL, PCA9685::PCA9685_ADDRESS_0, 400000 );
+
+
+Ticker newPWMOutput;
+DigitalOut myled(LED1);
+
+PCA9685::PCA9685_status_t aux;
+uint8_t myState = 0;
+
+
+void changeDATA ( void )
+{
+ myState++;
+}
+
+
+int main()
+{
+ // Reset the device
+ aux = myPWMSensor.PCA9685_SoftReset ();
+ wait_us ( 5 );
+
+ // Configure the PWM frequency and wake up the device
+ aux = myPWMSensor.PCA9685_SetPWM_Freq ( 1000 ); // PWM frequency: 1kHz
+ aux = myPWMSensor.PCA9685_SetMode ( PCA9685::MODE1_SLEEP_DISABLED );
+
+
+ newPWMOutput.attach( &changeDATA, 1 ); // the address of the function to be attached ( changeDATA ) and the interval ( 1s )
+
+ // Let the callbacks take care of everything
+ while(1) {
+ sleep();
+
+ myled = 1;
+
+ switch ( myState ) {
+ default:
+ case 0:
+ // All LEDs: Delay Time = 1% | PWM duty cycle = 99%
+ aux = myPWMSensor.PCA9685_SetPWM_DutyCycle_AllLEDs ( 0, 99 );
+
+ myState = 1;
+ break;
+
+ case 1:
+ // All LEDs: Delay Time = 100% | PWM duty cycle = 1%
+ aux = myPWMSensor.PCA9685_SetPWM_DutyCycle_AllLEDs ( 100, 1 );
+
+ myState = 2;
+ break;
+
+ case 2:
+ // LED1: Delay Time = 10% | PWM duty cycle = 30%
+ aux = myPWMSensor.PCA9685_SetPWM_DutyCycle ( PCA9685::PCA9685_LED1, 10, 30 );
+
+ myState = 0;
+ break;
+ }
+
+ myled = 0;
+ }
+}
*/
@@ -157,7 +221,7 @@
*/
typedef enum {
GENERAL_CALL_ADDRESS = ( 0x00 << 1 ), /*!< Software reset */
- SWRST = ( 0x06 << 1 ) /*!< Software reset */
+ SWRST = 0x06 /*!< Software reset */
} PCA9685_software_reset_t;