-
Notifications
You must be signed in to change notification settings - Fork 0
/
banaNEEC_2019.ino
52 lines (46 loc) · 1.44 KB
/
banaNEEC_2019.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
// define as portas analógicas de 0 a 3 como as bananas 0 a 3
int banana0 = A0;
int banana1 = A1;
int banana2 = A2;
int banana3 = A3;
// a rotina de setup corre uma vez no início do programa e sempre que o butão reset é pressionado
void setup() {
Serial.begin(9600);
// define as bananas como portas INPUT_PULLUP
pinMode(banana0, INPUT_PULLUP);
pinMode(banana1, INPUT_PULLUP);
pinMode(banana2, INPUT_PULLUP);
pinMode(banana3, INPUT_PULLUP);
pinMode(0,OUTPUT);
}
// a rotina loop corre infinitamente até que o o botão reset seja pressionado
void loop() {
// get readings from analog ports
int reading0 = analogRead(banana0);
int reading1 = analogRead(banana1);
int reading2 = analogRead(banana2);
int reading3 = analogRead(banana3);
// Convert the analog readings (which goes from 0 - 1023) to a voltage (0 - 5V):
float voltage0 = reading0 * (5.0 / 1023.0);
float voltage1 = reading1 * (5.0 / 1023.0);
float voltage2 = reading2 * (5.0 / 1023.0);
float voltage3 = reading3 * (5.0 / 1023.0);
// check voltages to determine which banana was pressed and play tone associated with it
if(voltage0 < 4.9){
tone(10, 1000);
}
else if(voltage1 < 4.9){
tone(10, 800);
}
else if(voltage2 < 4.9){
tone(10, 600);
}
else if(voltage3 < 4.9){
tone(10, 400);
}
else{
noTone(10);
}
// print out the value you read:
Serial.println(voltage0);
}