-
Notifications
You must be signed in to change notification settings - Fork 0
/
trophy.ino
130 lines (88 loc) · 2.41 KB
/
trophy.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
#include "Arduino.h"
#include <inttypes.h>
// custom parts libraries :D
#include "led.h"
#include "ultrasonic.h"
#include "pushButton.h"
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
//hardware:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
// 2 PWM RGB LEDs
TriLED top[2] {
TriLED(13, 12, 11), TriLED(10, 9, 8)
};
// 4 digital RGB LEDs
// pretend its like a coordinate plane... this is bad...
DigitalTriLED base[2][2]{ // fix this in final draft...
DigitalTriLED(47, 46, 51), DigitalTriLED(42, 43, 52),
DigitalTriLED(49, 48, 50), DigitalTriLED(45, 44, 53),
};
// the ultrasonic sensor / user interface
Ultrasonic sonar(A0);
// buzzer
#define BUZZPIN 27
// audio toggle
PushButton buzzButton(23);
// audio indicator
#define BUZZLEDPIN 22
bool audioEnabled = true;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
// turn all the LEDs off
void resetLEDs(){
top[0].set(LOW);
top[1].set(LOW);
base[0][0].set(LOW);
base[0][1].set(LOW);
base[1][0].set(LOW);
base[1][1].set(LOW);
}
// burn in the led values
void refreshLEDs(){
top[0].refresh();
top[1].refresh();
base[0][0].refresh();
base[0][1].refresh();
base[1][0].refresh();
base[1][1].refresh();
}
// patterns code:
#include "patterns.h" // the definitions for the patterns
#include "pattern.h" // the common functions for patterns
// plays a frequency based on the proximity to the sensor (while in range)
void theremin(){
uint16_t resp = 0;
bool state = LOW;
while ((resp = sonar.getMicroseconds()) < 5000 && resp != 0 && audioEnabled == true) {
digitalWrite(BUZZPIN, state);
state = !state;
//delayMicroseconds(resp);
pickNextPattern();
soundCheck();
}
digitalWrite(BUZZPIN, LOW);
}
// returns true when it's time to switch patterns
bool checkInput(){
static bool previous = false;
// NOTE: this delays 4 or 8miliseconds
// if user's hand is detected
if (sonar.getCm() < 30 && previous) {
pickNextPattern(); // switches patterns
if (audioEnabled) // ring 150Hz Square tone for 10ms
theremin();//tone(BUZZPIN, 150, 50);
return true;
}
previous = sonar.getCm() < 20;
return false;
}
void soundCheck(){
audioEnabled = !buzzButton.toggle();
digitalWrite(BUZZLEDPIN, audioEnabled);
}
void setup(){
// disable pull-up resistor
pinMode(BUZZLEDPIN, OUTPUT);
pinMode(BUZZPIN, OUTPUT);
}
void loop()
{ callPattern(patternNumber); }