-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnui.ino
More file actions
93 lines (79 loc) · 1.83 KB
/
Copy pathnui.ino
File metadata and controls
93 lines (79 loc) · 1.83 KB
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#include <IRremote.h>
#include <SPI.h> // include the SPI library:
// Set up all the pins!
int MUTE_PIN = 9;
int RECV_PIN = 21;
int CS_PIN = 10;
int ZC_EN = 8;
IRrecv irrecv(RECV_PIN);
decode_results results;
// Default volume (128/255)
uint8_t volume = 128;
// Mute is active low, so 1 is unmuted
uint8_t mute = 1;
void setup()
{
Serial.begin(9600);
irrecv.enableIRIn(); // Start the receiver
Serial.println("Started");
pinMode(MUTE_PIN, OUTPUT);
digitalWrite(MUTE_PIN, 1);
pinMode(CS_PIN, OUTPUT);
digitalWrite(CS_PIN, HIGH);
pinMode(ZC_EN, OUTPUT);
digitalWrite(ZC_EN, 1);
SPI.begin();
SPI.setSCK(14);
// Set initial volume
Serial.printf("Volume: %d\n", volume);
digitalWrite(CS_PIN, LOW);
SPI.transfer(volume);
SPI.transfer(volume);
digitalWrite(CS_PIN, HIGH);
}
// IR Codes for my particular remote's "Aux" mode
typedef enum {
AUX_VOL_DOWN = 0x4BB6C03F,
AUX_VOL_UP = 0x4BB640BF,
AUX_MUTE = 0x4BB6A05F
} commands_t;
void loop() {
if (irrecv.decode(&results)) {
switch (results.value) {
case AUX_VOL_DOWN:
{
Serial.println("Volume Down!");
if (volume > 0) {
volume--;
}
break;
}
case AUX_VOL_UP:
{
Serial.println("Volume Up!");
if (volume < 255) {
volume++;
}
break;
}
case AUX_MUTE:
{
Serial.println("Mute!");
mute ^= 1;
digitalWrite(MUTE_PIN, mute);
break;
}
default:
{
Serial.printf("Unknown command: 0x%08X\n", results.value);
}
}
irrecv.resume(); // Receive the next value
// Set the volume!
Serial.printf("Volume: %d\n", volume);
digitalWrite(CS_PIN, LOW);
SPI.transfer(volume);
SPI.transfer(volume);
digitalWrite(CS_PIN, HIGH);
}
}