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
7int inputPins[NUM_PINS] = {2, 1, 0, 3, 4, 5, 8};
8int outputPins[NUM_PINS] = {15, 10, 12, 11, 13, 14, 9}; //funcional
9
10void 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
23void 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}
void setup()
Definition main.cpp:10
#define NUM_PINS
Definition main.cpp:3
int outputPins[NUM_PINS]
Definition main.cpp:8
#define PRESSED_STATE
Definition main.cpp:4
int inputPins[NUM_PINS]
Definition main.cpp:7
void loop()
AMI main loop: Button gets picked and lights up the corresponding LED LAST BUTTON CHECKED WINS.
Definition main.cpp:23