#include <Arduino.h>
const int numLeds = 10;
const int button[] = {2 ,3 ,4 ,5 ,6 ,7 ,8 ,9 ,10,11}; //Pins for buttons
const int led[] = {30,31,32,33,34,36,38,39,40,41}; //Pins for light emiting diodes
const int ledExtra[] {-1,-1,-1,-1,35,37,-1,44,45,-1}; //Extra pin for same output
const int shutdownAll = 14; //Pin to shutdown all outputs;
long buttonLastDown[] = {0,0,0,0,0,0,0,0,0,0};//Latest time the button was pressed down
bool ledStat[] = {0,0,0,0,0,0,0,0,0,0};//The current stat of the leds. Change all 0 to 1 for default to turn on.
void updateLeds(){
for(int i = 0; i < numLeds; i++){
digitalWrite(led[i],ledStat[i]);
digitalWrite(ledExtra[i],ledStat[i]);
}
}
void setup(){
for(int i = 0; i < numLeds; i++){//All led pins will be outputs
pinMode(led[i],OUTPUT);
pinMode(ledExtra[i],OUTPUT);
}
updateLeds();
for(int i = 0; i < numLeds; i++){//All button pins will be pulled up.
pinMode(button[i],INPUT_PULLUP);
}
pinMode(shutdownAll, INPUT_PULLUP);//PULLUP for all off button.
/*OLD CODE*/
pinMode(22, INPUT_PULLUP);
pinMode(42, OUTPUT);
pinMode(23, INPUT_PULLUP);
pinMode(43, OUTPUT);
}
void loop(){
/*Reading all the buttons*/
for(int i = 0; i < numLeds; i++){
if(!digitalRead(button[i])){//Button down NO-button. Remove invert(!) for NC-button.
if(millis()- buttonLastDown[i] > 500){//It is over 0.5 sec since the button was pressed.
ledStat[i] = !ledStat[i];
updateLeds();
}
buttonLastDown[i] = millis();//Blocking debounce
}
}
/*Shutdown all*/
if(!digitalRead(shutdownAll)){//Button down NO-button. Remove invert(!) for NC-button.
for(int i = 0; i < numLeds; i++){
ledStat[i] = 0;//Set to 1 in order to turn on all leds instead
}
updateLeds();
}
/*OLD CODE - SIMPLI*/
digitalWrite(42, digitalRead(22));
digitalWrite(43, digitalRead(23));
}