-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathButtons.h
65 lines (55 loc) · 1.35 KB
/
Buttons.h
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#ifndef BUTTONS_H_INCLUDED
#define BUTTONS_H_INCLUDED
#include <Arduino.h>
#include <Adafruit_NeoPixel.h>
#include "Speaker.h"
#define NUMBER_OF_BUTTONS 4
#define PIN_BUTTON_SENSE_1 A1
#define PIN_BUTTON_SENSE_2 A2
#define PIN_BUTTON_SENSE_3 A3
#define PIN_BUTTON_SENSE_4 A4
class Button {
friend class Buttons;
private:
uint8_t sense;
uint32_t note;
uint8_t ledIndex;
uint32_t color;
bool pressed;
public:
Button(uint8_t sense, uint32_t note, uint8_t ledIndex, uint32_t color);
public:
boolean wasPressed() {
bool yes = pressed;
pressed = false;
return yes;
}
};
class Buttons {
private:
Speaker *speaker;
Adafruit_NeoPixel *pixels;
Button buttons[NUMBER_OF_BUTTONS];
bool areAnyOn;
public:
Buttons(Speaker *speaker, Adafruit_NeoPixel *pixels);
public:
bool anyOn() {
return areAnyOn;
}
void off();
void setup();
void tick();
void irq();
void play(uint8_t number);
void fail();
int8_t dequeuePress() {
for (uint8_t i = 0; i < NUMBER_OF_BUTTONS; ++i) {
if (buttons[i].wasPressed()) {
return i;
}
}
return -1;
}
};
#endif