muse/book-reading-clip-lamp

A tscircuit package created by muse.

Version
0.4.6
License
unset
Stars
0

firmware/rgb-bringup/rgb-bringup.ino

// Standalone RGB hardware test for Lamp Clip. Arduino ESP32-S3.
// Run BEFORE integrating camera firmware. Do not initialize a second I2C
// controller on these pins in the integrated app: share the camera's bus/lock.
#include <Wire.h>
constexpr uint8_t RGB_ADDR = 0x62; // 7-bit PCA9632DP1 address
bool writeRegister(uint8_t reg, uint8_t value) {
  Wire.beginTransmission(RGB_ADDR);
  Wire.write(reg);
  Wire.write(value);
  return Wire.endTransmission() == 0;
}
bool color(uint8_t red, uint8_t green, uint8_t blue) {
  return writeRegister(0x02, red) && writeRegister(0x03, green) && writeRegister(0x04, blue);
}
void setup() {
  Serial.begin(115200);
  Wire.begin(40, 39, 100000); // GPIO40 SDA; GPIO39 SCL; 3.3 V MCU side
  bool ok = writeRegister(0x00, 0x00); // wake; disable All Call
  delay(1); // datasheet: up to 500 us oscillator startup
  ok = ok && writeRegister(0x01, 0x01); // open drain, non-inverted; reserved bits retained
  ok = ok && color(0, 0, 0);
  ok = ok && writeRegister(0x08, 0x2A); // LED0/1/2 individual PWM; LED3 OFF
  Serial.println(ok ? "RGB driver ready" : "RGB I2C error: check 3.3V and wiring");
}
void loop() {
  color(255, 0, 0); delay(500);
  color(0, 255, 0); delay(500);
  color(0, 0, 255); delay(500);
  color(0, 0, 0); delay(500);
}