Formula Student Electronics & Software
The code for the embedded software
Loading...
Searching...
No Matches
main.cpp
Go to the documentation of this file.
1
#include <Arduino.h>
2
3
#define GREEN_LED_1 4
4
#define GREEN_LED_2 5
5
#define GREEN_LED_3 6
6
#define RED_LED_1 0
7
#define RED_LED_2 1
8
#define YELLOW_LED_1 2
9
#define YELLOW_LED_2 3
10
#define BUTTON_1 7
11
#define BUTTON_2 8
12
#define BUTTON_3 9
13
#define BUTTON_4 10
14
#define BUTTON_5 11
15
#define BUTTON_6 12
16
#define POTENCIO 14
17
18
void
setup
() {
19
pinMode(
GREEN_LED_1
, OUTPUT);
20
pinMode(
GREEN_LED_2
, OUTPUT);
21
pinMode(
GREEN_LED_3
, OUTPUT);
22
pinMode(
RED_LED_1
, OUTPUT);
23
pinMode(
RED_LED_2
, OUTPUT);
24
pinMode(
YELLOW_LED_1
, OUTPUT);
25
pinMode(
YELLOW_LED_2
, OUTPUT);
26
pinMode(
BUTTON_1
, INPUT);
27
pinMode(
BUTTON_2
, INPUT);
28
pinMode(
BUTTON_3
, INPUT);
29
pinMode(
BUTTON_4
, INPUT);
30
pinMode(
BUTTON_5
, INPUT);
31
pinMode(
BUTTON_6
, INPUT);
32
pinMode(
POTENCIO
, INPUT);
33
Serial.begin(9600);
34
}
35
36
void
reset
() {
37
Serial.println(
"Reseting"
);
38
digitalWrite(
GREEN_LED_1
, LOW);
39
digitalWrite(
GREEN_LED_2
, LOW);
40
digitalWrite(
GREEN_LED_3
, LOW);
41
digitalWrite(
RED_LED_1
, LOW);
42
digitalWrite(
RED_LED_2
, LOW);
43
digitalWrite(
YELLOW_LED_1
, LOW);
44
digitalWrite(
YELLOW_LED_2
, LOW);
45
}
46
47
void
loop
() {
48
49
if
(digitalRead(
BUTTON_1
) == LOW){
50
Serial.println(
"Botão 1 pressionado"
);
51
digitalWrite(
RED_LED_1
, HIGH);
52
delay(10);
53
reset
();
54
}
55
if
(digitalRead(
BUTTON_2
) == LOW){
56
Serial.println(
"Botão 2 pressionado"
);
57
digitalWrite(
RED_LED_2
, HIGH);
58
delay(10);
59
reset
();
60
}
61
if
(digitalRead(
BUTTON_3
) == LOW){
62
Serial.println(
"Botão 3 pressionado"
);
63
digitalWrite(
YELLOW_LED_1
, HIGH);
64
delay(10);
65
reset
();
66
}
67
if
(digitalRead(
BUTTON_4
) == LOW){
68
Serial.println(
"Botão 4 pressionado"
);
69
digitalWrite(
YELLOW_LED_2
, HIGH);
70
delay(10);
71
reset
();
72
}
73
if
(digitalRead(
BUTTON_5
) == LOW){
74
Serial.println(
"Botão 5 pressionado"
);
75
digitalWrite(
GREEN_LED_1
, HIGH);
76
delay(10);
77
reset
();
78
}
79
if
(digitalRead(
BUTTON_6
) == LOW){
80
Serial.println(
"Botão 6 pressionado"
);
81
digitalWrite(
GREEN_LED_2
, HIGH);
82
delay(10);
83
reset
();
84
}
85
86
int
potencio = analogRead(
POTENCIO
);
87
Serial.print(
"Potenciometro: "
);
88
Serial.println(potencio);
89
90
// Turn last green led on if potencio is greater than 512
91
if
(potencio > 512) {
92
digitalWrite(
GREEN_LED_3
, HIGH);
93
}
else
{
94
digitalWrite(
GREEN_LED_3
, LOW);
95
}
96
}
setup
void setup()
Definition
main.cpp:10
loop
void loop()
AMI main loop: Button gets picked and lights up the corresponding LED LAST BUTTON CHECKED WINS.
Definition
main.cpp:23
BUTTON_6
#define BUTTON_6
Definition
main.cpp:15
RED_LED_2
#define RED_LED_2
Definition
main.cpp:7
GREEN_LED_1
#define GREEN_LED_1
Definition
main.cpp:3
YELLOW_LED_1
#define YELLOW_LED_1
Definition
main.cpp:8
BUTTON_5
#define BUTTON_5
Definition
main.cpp:14
BUTTON_2
#define BUTTON_2
Definition
main.cpp:11
RED_LED_1
#define RED_LED_1
Definition
main.cpp:6
YELLOW_LED_2
#define YELLOW_LED_2
Definition
main.cpp:9
BUTTON_4
#define BUTTON_4
Definition
main.cpp:13
GREEN_LED_2
#define GREEN_LED_2
Definition
main.cpp:4
reset
void reset()
Definition
main.cpp:36
BUTTON_3
#define BUTTON_3
Definition
main.cpp:12
POTENCIO
#define POTENCIO
Definition
main.cpp:16
BUTTON_1
#define BUTTON_1
Definition
main.cpp:10
GREEN_LED_3
#define GREEN_LED_3
Definition
main.cpp:5
bread-board-test
src
main.cpp
Generated by
1.9.8