// One digit 7 segment LED display demo.
// Displays digit 0 - 9 and decimal point
// Prepare array of 7-Arduino pins which we need to interfaced with
// 7segments
// Define os pinos dos footswitchs
#define UP_BUTTON 10
#define DOWN_BUTTON 11
int buttonUpState = 0;
int buttonDownState = 0;
int lastButtonUpState = 0;
int lastButtonDownState = 0;
int currentProgram = 0; // Variável para armazenar o programa atual
int initProgram = 0; // Variável para armazenar o programa inicial
int maxProgram = 23; // Variável para armazenar o máximo de programas
int segPins[] = {2, 3, 4, 5, 6, 7, 8, 9}; // { a b c d e f g . )
//Truth table for driving the 7segments LED
byte segCode[27][8] = {
//a b c d e f g .
{ 1, 0, 0, 1, 1, 1, 1, 1}, // 1
{ 0, 0, 1, 0, 0, 1, 0, 1}, // 2
{ 0, 0, 0, 0, 1, 1, 0, 1}, // 3
{ 1, 0, 0, 1, 1, 0, 0, 1}, // 4
{ 0, 1, 0, 0, 1, 0, 0, 1}, // 5
{ 0, 1, 0, 0, 0, 0, 0, 1}, // 6
{ 0, 0, 0, 1, 1, 1, 1, 1}, // 7
{ 0, 0, 0, 0, 0, 0, 0, 1}, // 8
{ 0, 0, 0, 0, 1, 0, 0, 1}, // 9
{ 0, 0, 0, 0, 0, 0, 1, 0}, // 0.
{ 1, 0, 0, 1, 1, 1, 1, 0}, // 1.
{ 0, 0, 1, 0, 0, 1, 0, 0}, // 2.
{ 0, 0, 0, 0, 1, 1, 0, 0}, // 3.
{ 1, 0, 0, 1, 1, 0, 0, 0}, // 4.
{ 0, 1, 0, 0, 1, 0, 0, 0}, // 5.
{ 0, 1, 0, 0, 0, 0, 0, 0}, // 6.
{ 0, 0, 0, 1, 1, 1, 1, 0}, // 7.
{ 0, 0, 0, 0, 0, 0, 0, 0}, // 8.
{ 0, 0, 0, 0, 1, 0, 0, 0}, // 9.
{ 0, 0, 0, 1, 0, 0, 0, 1}, // A
{ 1, 1, 0, 0, 0, 0, 0, 1}, // b
{ 0, 1, 1, 0, 0, 0, 1, 1}, // C
{ 1, 0, 0, 0, 0, 1, 0, 1}, // d
{ 0, 1, 1, 0, 0, 0, 0, 1}, // E
{ 0, 1, 1, 1, 0, 0, 0, 1}, // F
{ 1, 1, 1, 1, 1, 1, 1, 0}, // .
{ 1, 1, 1, 1, 1, 1, 1, 1}, // Off
};
void displayDigit(int digit)
{
for (int i = 0; i < 8; i++)
{
digitalWrite(segPins[i], segCode[digit][i]); //passing the value pin array
}
}
void setup()
{
// Inicializa os pinos dos botões como entradas
pinMode(UP_BUTTON, INPUT_PULLUP);
pinMode(DOWN_BUTTON, INPUT_PULLUP);
for (int i = 0; i < 8; i++)
{
pinMode(segPins[i], OUTPUT);// declare Arduino pin as an output
}
displayDigit(currentProgram);
}
void loop()
{
buttonUpState = digitalRead(UP_BUTTON);
buttonDownState = digitalRead(DOWN_BUTTON);
if (buttonUpState != lastButtonUpState) {
if (buttonUpState == HIGH) {
// Verifica se ainda há programas para descer
if (currentProgram < maxProgram)
{
// Decrementa o programa atual
currentProgram++;
}
else
{
// Vai para o último programa
currentProgram = initProgram;
}
}
lastButtonUpState = buttonUpState;
displayDigit(currentProgram);
delay(50);
}
if (buttonDownState != lastButtonDownState) {
if (buttonDownState == HIGH) {
// Verifica se ainda há programas para descer
if (currentProgram > initProgram)
{
// Decrementa o programa atual
currentProgram--;
}
else
{
// Vai para o último programa
currentProgram = maxProgram;
}
}
lastButtonDownState = buttonDownState;
displayDigit(currentProgram);
delay(50);
}
}