PbHUB.ino 941 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. /*
  2. Description: Use Pbhub to read the analog input value of the slave device,
  3. or drive multiple sets of RGB LEDs.
  4. */
  5. #include <M5Stack.h>
  6. #include <Wire.h>
  7. #include "porthub.h"
  8. #define X_OFFSET 10
  9. #define Y_OFFSET 18
  10. PortHub porthub;
  11. uint8_t HUB_ADDR[6] = {HUB1_ADDR, HUB2_ADDR, HUB3_ADDR,
  12. HUB4_ADDR, HUB5_ADDR, HUB6_ADDR};
  13. void setup() {
  14. M5.begin(true, false, true);
  15. M5.Power.begin();
  16. porthub.begin();
  17. M5.Lcd.clear(BLACK);
  18. M5.Lcd.setTextColor(WHITE);
  19. M5.Lcd.setTextSize(4);
  20. }
  21. void loop() {
  22. M5.Lcd.clear(BLACK);
  23. for (int i = 0; i < 6; i++) {
  24. M5.Lcd.setCursor(8 * X_OFFSET, (i * 2) * Y_OFFSET);
  25. M5.Lcd.printf("%d:%d", i + 1, porthub.hub_a_read_value(HUB_ADDR[i]));
  26. }
  27. for (int i = 0; i < 6; i++) {
  28. porthub.hub_wire_setBrightness(HUB_ADDR[i], 1);
  29. porthub.hub_wire_fill_color(HUB_ADDR[i], 0, 15, 250, 250, 250);
  30. }
  31. delay(1000);
  32. }