-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfinale_trans.ino
198 lines (162 loc) · 3.03 KB
/
finale_trans.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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
#define led_red 4
#define led_yellow 5
#define led_green 6
#define led_common_cathode 7
#define transmitter_1 3
#define transmitter_2 2
#define mic A1
#define mic_activator 12
#define level_1 A2
#define level_2 A3
#define level_3 A4
#define level_base A0
int shot=1;
int counter_1=0;
boolean glass_full=false;
boolean control_1=false;
boolean control_2=false;
boolean control_3=false;
boolean control_4=false;
boolean control_5=false;
boolean control_6=false;
boolean control_7=false;
void setup()
{
initialise();
}
void loop()
{
level_sense();
music();
glass_detect_oscillator();
}
void initialise()
{
Serial.begin(9600);
pinMode(led_red,OUTPUT);
pinMode(led_yellow,OUTPUT);
pinMode(led_green,OUTPUT);
pinMode(led_common_cathode,OUTPUT);
pinMode(transmitter_1,OUTPUT);
pinMode(transmitter_2,OUTPUT);
pinMode(mic_activator,OUTPUT);
pinMode(mic,INPUT);
pinMode(level_1,INPUT);
pinMode(level_2,INPUT);
pinMode(level_3,INPUT);
pinMode(level_base,OUTPUT);
digitalWrite(led_red,LOW);
digitalWrite(led_yellow,LOW);
digitalWrite(led_green,LOW);
digitalWrite(led_common_cathode,LOW);
digitalWrite(transmitter_1,HIGH);
digitalWrite(transmitter_2,HIGH);
digitalWrite(mic_activator,LOW);
analogWrite(level_1,0);
analogWrite(level_2,0);
analogWrite(level_3,0);
//analogWrite(level_base,1023);
}
void glass_detect_oscillator()
{
counter_1 = counter_1 + 1;
if (counter_1%200==0)
{
digitalWrite(transmitter_2,HIGH);
counter_1=1;
}
if (counter_1%100==0)
{
digitalWrite(transmitter_2,LOW);
}
}
int level_detect()
{
if (analogRead(level_3)>1000)
{
return(3);
}
if (analogRead(level_2)>1000)
{
return(2);
}
if (analogRead(level_1)>1000)
{
return(1);
}
else
{
return(0);
}
}
void level_sense()
{
switch(level_detect())
{
case 0:
glass_full=false;
break;
case 3:
glass_full=true;
break;
default:;
}
if (glass_full || control_1)
{
control_1=true;
if (glass_full==false || control_2)
{
control_2=true;
if (glass_full || control_3)
{
control_3=true;
shot=2;
if (glass_full==false || control_4)
{
control_4=true;
if (glass_full || control_5)
{
control_5=true;
shot=3;
if (glass_full==false || control_6)
{
control_6=true;
if (glass_full || control_7)
{
control_7=true;
shot=3;
digitalWrite(transmitter_1,LOW);
}
}
}
}
}
}
}
}
void music()
{
int mic_val = analogRead(mic);
if(mic_val>100)
{
switch(shot)
{
case 1:
digitalWrite(led_green,HIGH);
break;
case 2:
digitalWrite(led_yellow,HIGH);
break;
case 3:
digitalWrite(led_red,HIGH);
break;
delay(2);
}
}
else
{
digitalWrite(led_green,LOW);
digitalWrite(led_yellow,LOW);
digitalWrite(led_red,LOW);
}
}