-
Notifications
You must be signed in to change notification settings - Fork 14
/
pc_latch_rgb_common_anode.ino
147 lines (121 loc) · 4.33 KB
/
pc_latch_rgb_common_anode.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
String inByte; // reading serial for powershell commands
const int button1Pin = 2; // pushbutton 1 pin
const int RED_PIN = 4; // LED for visualizer
const int GREEN_PIN = 7; // LED for visualizer
const int BLUE_PIN = 9; // LED for visualizer
int toggleState = 1;
unsigned long lastLedDisplayUpdate;
float lastVolume;
int ledDisplay;
void setup()
{
// Set up the pushbutton pins to be an input:
pinMode(button1Pin, INPUT_PULLUP);
// Set up the LEDs pin to be an outputs:
pinMode(LED_BUILTIN, OUTPUT);
pinMode(RED_PIN, OUTPUT);
pinMode(GREEN_PIN, OUTPUT);
pinMode(BLUE_PIN, OUTPUT);
// Set up the serial bus
Serial.begin(9600);
Serial.setTimeout(50); //decreases parseInt timeout
}
void loop()
{
int button1State, button2State; // variables to hold the pushbutton states
button1State = digitalRead(button1Pin);
//if there is data to display, whether it is volume or mewt state
if (Serial.available()) {
inByte = Serial.readString();
// blink unmewt light if volume level changes. I can only seem to compare this delta if they are both Bytes and not int.
float inBytefloat = inByte.toFloat();
/* if (inBytefloat != lastVolume) {
digitalWrite(GREEN_PIN, LOW); // turn the LED off
delay (50);
digitalWrite(GREEN_PIN, HIGH); // turn the LED off
delay (50);
digitalWrite(GREEN_PIN, LOW); // turn the LED off
}
lastVolume = inBytefloat;
*/
//changes Byte to string and then to int in order to faciltate comparison and lcd display
ledDisplay = String(inByte).toFloat();
if (ledDisplay == 0) {
digitalWrite(RED_PIN, LOW);
digitalWrite(LED_BUILTIN, HIGH);
digitalWrite(GREEN_PIN, HIGH);
digitalWrite(BLUE_PIN, HIGH);
}
else if (ledDisplay == 1) {
digitalWrite(RED_PIN, HIGH);
digitalWrite(LED_BUILTIN, HIGH);
digitalWrite(GREEN_PIN, HIGH);
digitalWrite(BLUE_PIN, LOW);
}
else if (ledDisplay == 101) {
digitalWrite(LED_BUILTIN, LOW);
digitalWrite(RED_PIN, HIGH);
digitalWrite(GREEN_PIN, LOW);
digitalWrite(BLUE_PIN, HIGH);
delay(300);
digitalWrite(LED_BUILTIN, HIGH);
digitalWrite(RED_PIN, HIGH);
digitalWrite(GREEN_PIN, HIGH);
digitalWrite(BLUE_PIN, HIGH);
delay(200);
digitalWrite(LED_BUILTIN, LOW);
digitalWrite(RED_PIN, HIGH);
digitalWrite(GREEN_PIN, LOW);
digitalWrite(BLUE_PIN, HIGH);
delay(300);
digitalWrite(LED_BUILTIN, HIGH);
digitalWrite(RED_PIN, HIGH);
digitalWrite(GREEN_PIN, HIGH);
digitalWrite(BLUE_PIN, HIGH);
delay(200);
digitalWrite(LED_BUILTIN, LOW);
digitalWrite(RED_PIN, HIGH);
digitalWrite(GREEN_PIN, LOW);
digitalWrite(BLUE_PIN, HIGH);
delay(300);
digitalWrite(LED_BUILTIN, HIGH);
digitalWrite(RED_PIN, HIGH);
digitalWrite(GREEN_PIN, HIGH);
digitalWrite(BLUE_PIN, HIGH);
}
else if ((ledDisplay % 3) == 0) {
digitalWrite(RED_PIN, LOW);
digitalWrite(LED_BUILTIN, HIGH);
digitalWrite(GREEN_PIN, HIGH);
digitalWrite(BLUE_PIN, LOW);
}
else if (ledDisplay % 3 == 1) {
digitalWrite(RED_PIN, HIGH);
digitalWrite(LED_BUILTIN, HIGH);
digitalWrite(GREEN_PIN, LOW);
digitalWrite(BLUE_PIN, LOW);
}
else if (ledDisplay % 3 == 2) {
digitalWrite(RED_PIN, HIGH);
digitalWrite(LED_BUILTIN, HIGH);
digitalWrite(GREEN_PIN, LOW);
digitalWrite(BLUE_PIN, HIGH);
}
//timestamps last MEWT display update
lastLedDisplayUpdate = millis();
}
//if it's been over 1 second since last MEWT display update, turn off LEDs to avoid confusion
if(millis() - lastLedDisplayUpdate > 1000) {
digitalWrite(RED_PIN, HIGH);
digitalWrite(GREEN_PIN, HIGH);
digitalWrite(BLUE_PIN, HIGH);
}
if (button1State != toggleState) // if we're pushing button 1
{
// send value to powershell to mewt
Serial.println(button1State);
toggleState = button1State;
// delay removes button bounce
delay(5);
}
}