pca9635.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. //Source: https://github.com/rambo/pca9635
  2. // safety againts double-include
  3. #ifndef pca9635_h
  4. #define pca9635_h
  5. #include <Arduino.h>
  6. #include <Wire.h>
  7. #define NUM_CHANNELS 16
  8. #define MODE_REGISTERS 4
  9. // Stub extension for now
  10. class pca9635 {
  11. public:
  12. pca9635(); // We need this so we can set default address to the all-call one for the PCA9635 instance
  13. void begin(byte dev_addr, boolean wire_begin);
  14. void begin(byte dev_addr, boolean wire_begin, boolean init); // Variant to allow skipiing init (needed by the RGB board)
  15. boolean set_led_mode(byte ledno, byte mode);
  16. boolean set_led_mode(byte mode); // Variant to set all leds to same mode
  17. boolean set_all_led_modes(uint8_t cnt, uint8_t leds[], uint8_t modes[]);
  18. boolean set_led_pwm(byte ledno, byte cycle);
  19. boolean set_all_led_pwm(uint8_t start_led, uint8_t cnt, uint8_t *cycles);
  20. boolean set_group_dimming(uint8_t cycle); //190.7Hz (5.24ms) signal, duty = cycle * 2 * 256 * 40ns
  21. boolean set_group_blinking(uint8_t freq); //freq * 41.6 ms
  22. boolean set_driver_mode(byte mode);
  23. boolean set_invert_output(byte mode);
  24. boolean set_output_not_active_state(byte mode);
  25. boolean set_group_control(byte mode);
  26. boolean set_sleep(byte sleep);
  27. boolean enable_subaddr(byte addr);
  28. boolean isAvailable();
  29. uint8_t getPWMValue(uint8_t channel);
  30. boolean reset(); // NOTE: This resets all PCA9635 devices on the bus
  31. private:
  32. uint8_t device_address;
  33. uint8_t autoincrement_bits;
  34. boolean available;
  35. uint8_t pwm_values[NUM_CHANNELS];
  36. uint8_t led_mode_regs[MODE_REGISTERS];
  37. boolean readSingleReg(uint8_t reg, uint8_t *data);
  38. boolean writeSingleReg(uint8_t reg, uint8_t data);
  39. boolean writeManyReg(uint8_t reg, uint8_t cnt, uint8_t *data);
  40. void exchangeValueReg(uint8_t *reg, uint8_t mask, uint8_t value);
  41. boolean readModifyWriteReg(uint8_t reg, uint8_t mask, uint8_t value);
  42. boolean reset(uint8_t addr);
  43. };
  44. extern pca9635 PCA9635;
  45. #endif
  46. // *********** END OF CODE **********