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 NUM_PINS 7
4
#define PRESSED_STATE LOW
5
6
// Use ATtiny pin identifiers
7
int
inputPins
[
NUM_PINS
] = {2, 1, 0, 3, 4, 5, 8};
8
int
outputPins
[
NUM_PINS
] = {15, 10, 12, 11, 13, 14, 9};
//funcional
9
10
void
setup
()
11
{
12
for
(
int
i = 0; i <
NUM_PINS
; i++) {
13
pinMode(
outputPins
[i], OUTPUT);
14
pinMode(
inputPins
[i], INPUT_PULLUP);
15
}
16
}
17
23
void
loop
() {
24
int
currentButtonPressed = -1;
25
26
for
(
int
i = 0; i <
NUM_PINS
; i++)
27
{
28
if
(digitalRead(
inputPins
[i])==
PRESSED_STATE
)
29
{
30
currentButtonPressed = i;
31
}
32
}
33
34
if
(currentButtonPressed != -1) {
35
for
(
int
i = 0; i <
NUM_PINS
; i++) {
36
digitalWrite(
outputPins
[i], LOW);
37
}
38
39
digitalWrite(
outputPins
[currentButtonPressed], HIGH);
40
}
41
}
setup
void setup()
Definition
main.cpp:10
NUM_PINS
#define NUM_PINS
Definition
main.cpp:3
outputPins
int outputPins[NUM_PINS]
Definition
main.cpp:8
PRESSED_STATE
#define PRESSED_STATE
Definition
main.cpp:4
inputPins
int inputPins[NUM_PINS]
Definition
main.cpp:7
loop
void loop()
AMI main loop: Button gets picked and lights up the corresponding LED LAST BUTTON CHECKED WINS.
Definition
main.cpp:23
ami
src
main.cpp
Generated by
1.9.8