-
Notifications
You must be signed in to change notification settings - Fork 4
/
ReadDualButtonViaPbHub.ino
48 lines (40 loc) · 1.25 KB
/
ReadDualButtonViaPbHub.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// Copyright (c) 2024 by GWENDESIGN. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//
// https://github.com/m5stack/M5AtomS3
// https://github.com/m5stack/M5Unified
// https://github.com/m5stack/M5GFX
// https://github.com/m5stack/M5Unit-PbHub
// https://github.com/FastLED/FastLED
//
// You need: M5AtomS3, ATOMIC ABC, PbHub unit v1.1, Dual Button unit
// Place M5AtomS3 onto ATOMIC ABC, connect PbHub to red port, connect Dual Button unit to channel 2
#include <M5AtomS3.h>
#include <M5UnitPbHub.h>
M5UnitPbHub pbhub;
#define PBHUB_CHANNEL 2 // 0 - 5
#define BUTTON_BLUE_INDEX 0
#define BUTTON_RED_INDEX 1
void setup()
{
auto cfg = M5.config();
AtomS3.begin(cfg);
if(!pbhub.begin(&Wire, UNIT_PBHUB_I2C_ADDR, 38, 39, 400000U))
{
Serial.println("Pbhub not found");
while(1) delay(1);
}
Serial.println("Pbhub found");
}
void loop()
{
if(pbhub.digitalRead(PBHUB_CHANNEL, BUTTON_BLUE_INDEX) == true)
Serial.println("Blue button released");
else
Serial.println("Blue button pressed");
if(pbhub.digitalRead(PBHUB_CHANNEL, BUTTON_RED_INDEX) == true)
Serial.println("Red button released");
else
Serial.println("Red button pressed");
delay(1000);
}