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.
Dependencies: mbed ros_lib_kinetic
PCA9634.cpp
00001 00002 #include "PCA9634.h" 00003 00004 PCA9634::PCA9634(I2C *i2c, DigitalOut *inv_out_en, int addr) 00005 : i2c_(i2c), inv_out_en_(inv_out_en), addr_(addr) { 00006 *inv_out_en_ = 0; 00007 00008 // Set Mode 1: Auto-increment on, oscillator on, do not respond to all-call 00009 writeReg(PCA9634_REG_MODE1, 0x80); 00010 // Set Mode 2: Don't invert logic, outputs change on ACK, LED outputs configured 00011 // in open-drain structure 00012 writeReg(PCA9634_REG_MODE2, 0x09); 00013 dimLEDs(); 00014 // Set all LED driver output states to PWM 00015 led_out_state_[0] = PCA9634_ALL_LED_TO_PWM; 00016 led_out_state_[1] = PCA9634_ALL_LED_TO_PWM; 00017 00018 commandLEDOutState(); 00019 } 00020 00021 void PCA9634::dimLEDs() { 00022 for (char reg = PCA_LED0; reg <= PCA_LED7; reg++) 00023 writeReg(reg, 0); 00024 } 00025 00026 void PCA9634::disableLED(ledID led) { 00027 // Set correct registers to 00 00028 if (led < LED4) { 00029 led_out_state_[0] &= ~(1UL << (2*(led-2))); 00030 led_out_state_[0] &= ~(1UL << (2*(led-2)+1)); 00031 } else { 00032 led_out_state_[1] &= ~(1UL << (2*(led-6))); 00033 led_out_state_[1] &= ~(1UL << (2*(led-6)+1)); 00034 } 00035 commandLEDOutState(); 00036 } 00037 00038 void PCA9634::enableLED(ledID led) { 00039 // Set correct registers to 01 00040 if (led < LED4) { 00041 led_out_state_[0] |= (1UL << (2*(led-2))); 00042 led_out_state_[0] &= ~(1UL << (2*(led-2)+1)); 00043 } else { 00044 led_out_state_[1] |= (1UL << (2*(led-6))); 00045 led_out_state_[1] &= ~(1UL << (2*(led-6)+1)); 00046 } 00047 commandLEDOutState(); 00048 } 00049 00050 void PCA9634::commandLEDOutState() { 00051 writeReg(PCA9634_REG_LEDOUT0, led_out_state_[0]); 00052 writeReg(PCA9634_REG_LEDOUT1, led_out_state_[1]); 00053 } 00054 00055 void PCA9634::commandLEDBrightness(ledID led, int brightness) { 00056 writeReg(led, (char) brightness); 00057 } 00058 00059 int PCA9634::writeReg(char reg, char value) { 00060 char cmd[2]; 00061 cmd[0] = reg; 00062 cmd[1] = value; 00063 return i2c_->write(addr_, cmd, 2); 00064 }
Generated on Sat Jul 23 2022 08:22:52 by
1.7.2