PbHUB.ino 886 B

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