// 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
// Variáveis para armazenar o estado dos botões
int buttonUpState = 0;
int buttonDownState = 0;
int lastButtonUpState = 0;
int lastButtonDownState = 0;
int currentProgram = 0; // Variável para armazenar o programa atual
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[12][8] = {
//a b c d e f g .
{ 0, 0, 0, 0, 0, 0, 1, 1}, // 0
{ 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
{ 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()
{
// Verifica se o botão para subir os programas foi pressionado
if (digitalRead(UP_BUTTON) == LOW) {
// Verifica se ainda há programas para subir
if (currentProgram < 10) {
// Incrementa o programa atual
currentProgram++;
} else {
// Volta para o primeiro programa
currentProgram = 0;
}
// Envia um comando MIDI para subir o programa
//midi.sendProgramChange(1, currentProgram);
displayDigit(currentProgram);
delay(200);
}
// Verifica se o botão para descer os programas foi pressionado
if (digitalRead(DOWN_BUTTON) == LOW) {
// Verifica se ainda há programas para descer
if (currentProgram > 0) {
// Decrementa o programa atual
currentProgram--;
} else {
// Vai para o último programa
currentProgram = 10;
}
// Envia um comando MIDI para descer o programa
//midi.sendProgramChange(1, currentProgram);
displayDigit(currentProgram);
delay(200);
}
}