-
Notifications
You must be signed in to change notification settings - Fork 0
/
MediaControllerAMG.ino
71 lines (56 loc) · 1.33 KB
/
MediaControllerAMG.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include <ClickEncoder.h>
#include <TimerOne.h>
#include <HID-Project.h>
#define ENCODER_DT A1
#define ENCODER_SW A2
#define PIN1 2
#define PIN2 3
#define PIN3 4
#define PIN4 5
#define ENCODER_CLK A0
ClickEncoder *encoder;
int16_t last, value;
void timerIsr() {
encoder->service();
}
void setup() {
Serial.begin(9600);
Consumer.begin();
encoder = new ClickEncoder(ENCODER_DT, ENCODER_CLK, ENCODER_SW);
Timer1.initialize(1000);
Timer1.attachInterrupt(timerIsr);
last = -1;
pinMode(PIN1, INPUT_PULLUP);
pinMode(PIN2, INPUT_PULLUP);
pinMode(PIN3, INPUT_PULLUP);
pinMode(PIN4, INPUT_PULLUP);
pinMode(9, OUTPUT);
digitalWrite(9, LOW);
}
void loop() {
value += encoder->getValue();
if (value != last) {
if(last<value) //
Consumer.write(MEDIA_VOLUME_UP);
else
Consumer.write(MEDIA_VOLUME_DOWN);
last = value;
}
if(digitalRead(PIN1)==LOW){
Consumer.write(MEDIA_PLAY_PAUSE);
delay(300);
}
if(digitalRead(PIN2)==LOW){
Consumer.write(HID_CONSUMER_SCAN_NEXT_TRACK);
delay(300);
}
if(digitalRead(PIN3)==LOW){
Consumer.write(HID_CONSUMER_SCAN_PREVIOUS_TRACK);
delay(300);
}
if(digitalRead(PIN4)==LOW){
Consumer.write(CONSUMER_EXPLORER);
delay(300);
}
delay(10);
}