#include <Arduino_FreeRTOS.h>
#include <semphr.h> // add the FreeRTOS functions for Semaphores (or Flags).'
SemaphoreHandle_t xSerialSemaphore;
// define two Tasks for
void TaskTimer( void *pvParameters );
void TaskTimer2( void *pvParameters );
void TaskTimer3( void *pvParameters );
void TaskTimer4( void *pvParameters );
void TaskRelay( void *pvParameters );
void TaskFIFO( void *pvParameters );
//FirstSevenSegment push button counter
const int a1 =11; //For displaying segment "a"
const int b1 = 12; //For displaying segment "b"
const int c1 = 37; //For displaying segment "c"
const int d1 = 39; //For displaying segment "d"
const int e1 = 41; //For displaying segment "e"
const int f1 = 14; //For displaying segment "f"
const int g1 = 13; //For displaying segment "g"
//SecondSevenSegment push button counter
const int a2 = 7; //For displaying segment "a"
const int b2 = 8; //For displaying segment "b"
const int c2 = 32; //For displaying segment "c"
const int d2 = 33; //For displaying segment "d"
const int e2 = 34; //For displaying segment "e"
const int f2 = 10; //For displaying segment "f"
const int g2 = 9; //For displaying segment "g"
//ThirdtSevenSegment push button counter
const int a3 = 30; //For displaying segment "a"
const int b3 = 28; //For displaying segment "b"
const int c3 = 46; //For displaying segment "c"
const int d3 = 44; //For displaying segment "d"
const int e3 = 42; //For displaying segment "e"
const int f3 = 31; //For displaying segment "f"
const int g3 = 29; //For displaying segment "g"
//fourthSevenSegment push button counter
const int a4 = 26; //For displaying segment "a"
const int b4 = 24; //For displaying segment "b"
const int c4 = 52; //For displaying segment "c"
const int d4 = 50; //For displaying segment "d"
const int e4 = 48; //For displaying segment "e"
const int f4 = 25; //For displaying segment "f"
const int g4 = 27; //For displaying segment "g"
bool b1Press1 = false;
bool b1Press2 = false;
bool b2Press1 = false;
bool b2Press2 = false;
bool b3Press1 = false;
bool b3Press2 = false;
bool b4Press1 = false;
bool b4Press2 = false;
const int FirstbuttonPin = A1;
const int SeconbuttonPin = A3;
const int ThirdbuttonPin = A5;
const int FourthbuttonPin = A7;
const int timer1=18;
const int timer2=16;
const int timer3=20;
const int timer4=A9;
const int EA1=23;//40
const int EA2=40;//36
const int EA3=17;//23
const int EA4=36;//17
const int RESET = A8;
const int BLEU = A0;
// Variables will change:
int buttonPushCounter1 = 0; // counter for the number of button1 presses
int buttonPushCounter2 = 0; // counter for the number of button2 presses
int buttonPushCounter3 = 0; // counter for the number of button3 presses
int buttonPushCounter4 = 0; // counter for the number of button4 presses
int buttonPushCounter11 = 0; // counter for the number of button1 presses
int buttonPushCounter22 = 0; // counter for the number of button2 presses
int buttonPushCounter33 = 0; // counter for the number of button3 presses
int buttonPushCounter44 = 0; // counter for the number of button4 presses
int c=0;
int d=0;
int e=0;
int f=0;
int start1=0;
int start2=0;
int start3=0;
int start4=0;
int FirstbuttonState = 0; // Firstbutton current state
int LastFirstbuttonState = 0; // Firstbutton previous state
int SecondbuttonState = 0; // Secondbutton current state
int LastSecondbuttonState = 0; // Secondbutton previous state
int ThirdbuttonState = 0; // Secondbutton current state
int LastThirdbuttonState = 0; // Secondbutton previous state
int FourthbuttonState = 0; // Secondbutton current state
int LastFourthbuttonState = 0; // Secondbutton previous state
int counter1 = 0;
int counter2 = 0;
int counter3 = 0;
int counter4 = 0;
void setup() {
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
pinMode(timer1, INPUT);//
pinMode(timer2,INPUT); //
pinMode(timer3, INPUT); //
pinMode(timer4, INPUT); //
while (!Serial) {
; // wait for serial port to connect.
}
if ( xSerialSemaphore == NULL ) // Check to confirm that the Serial Semaphore has not already been created.
{
xSerialSemaphore = xSemaphoreCreateMutex(); // Create a mutex semaphore we will use to manage the Serial Port
if ( ( xSerialSemaphore ) != NULL )
xSemaphoreGive( ( xSerialSemaphore ) ); // Make the Serial Port available for use, by "Giving" the Semaphore.
}
xTaskCreate(
TaskTimer
, "TIMER" // A name just for humans
, 128 // This stack size can be checked & adjusted by reading the Stack Highwater
, NULL //Parameters for the task
, 1 // Priority, with 3 (configMAX_PRIORITIES - 1) being the highest, and 0 being the lowest.
, NULL ); //Task Handle
xTaskCreate(
TaskTimer2
, "TIMER" // A name just for humans
, 128 // This stack size can be checked & adjusted by reading the Stack Highwater
, NULL //Parameters for the task
, 1 // Priority, with 3 (configMAX_PRIORITIES - 1) being the highest, and 0 being the lowest.
, NULL ); //Task Handle
xTaskCreate(
TaskTimer3
, "TIMER" // A name just for humans
, 128 // This stack size can be checked & adjusted by reading the Stack Highwater
, NULL //Parameters for the task
, 1 // Priority, with 3 (configMAX_PRIORITIES - 1) being the highest, and 0 being the lowest.
, NULL ); //Task Handle
xTaskCreate(
TaskTimer4
, "TIMER" // A name just for humans
, 128 // This stack size can be checked & adjusted by reading the Stack Highwater
, NULL //Parameters for the task
, 1 // Priority, with 3 (configMAX_PRIORITIES - 1) being the highest, and 0 being the lowest.
, NULL ); //Task Handle
xTaskCreate(
TaskRelay
, "EM BLOCKING" // A name just for humans
, 128 // Stack size
, NULL //Parameters for the task
, 2 // Priority
, NULL ); //Task Handle
xTaskCreate(
TaskFIFO
, "NUMBERING " // A name just for humans
, 128 // Stack size
, NULL //Parameters for the task
, 2 // Priority
, NULL ); //Task Handle
off1();
off2();
off3();
off4();
}
void loop()
{
// Empty. Things are done in Tasks.
}
/*--------------------------------------------------*/
/*---------------------- Tasks ---------------------*/
/*--------------------------------------------------*/
void TaskTimer( void *pvParameters __attribute__((unused)) ) // This is a Task.
{
/*
DigitalReadSerial
Reads a digital input on pin 2, prints the result to the serial monitor
pinMode(timer1, INPUT_PULLUP);//
pinMode(timer2,INPUT_PULLUP); //
pinMode(timer3, INPUT_PULLUP); //
pinMode(timer4, INPUT_PULLUP); //
This example code is in the public domain.
*/
// digital pin 2 has a pushbutton attached to it. Give it a name:
// make the pushbutton's pin an input:
for (;;) // A Task shall never return or exit.
{
if(start1 == HIGH){
vTaskDelay( 1000 / portTICK_PERIOD_MS );
counter1++;
}
if ( xSemaphoreTake( xSerialSemaphore, ( TickType_t ) 5 ) == pdTRUE )
{
// We were able to obtain or "Take" the semaphore and can now access the shared resource.
// We want to have the Serial Port for us alone, as it takes some time to print,
// so we don't want it getting stolen during the middle of a conversion.
// print out the state of the button:
Serial.println("counter1");
Serial.println(counter1);
xSemaphoreGive( xSerialSemaphore ); // Now free or "Give" the Serial Port for others.
}
//if(counter > 30){///// counter as timer for 20 min
//digitalWrite(EA4, LOW);}
// }
// else counter = 0;
// See if we can obtain or "Take" the Serial Semaphore.
// If the semaphore is not available, wait 5 ticks of the Scheduler to see if it becomes free.
vTaskDelay(1); // one tick delay (15ms) in between reads for stability
}
}
/*--------------------------------------------------*/
/*---------------------- Tasks ---------------------*/
/*--------------------------------------------------*/
void TaskTimer2( void *pvParameters __attribute__((unused)) ) // This is a Task.
{
/*
DigitalReadSerial
Reads a digital input on pin 2, prints the result to the serial monitor
pinMode(timer1, INPUT_PULLUP);//
pinMode(timer2,INPUT_PULLUP); //
pinMode(timer3, INPUT_PULLUP); //
pinMode(timer4, INPUT_PULLUP); //
This example code is in the public domain.
*/
// digital pin 2 has a pushbutton attached to it. Give it a name:
// make the pushbutton's pin an input:
for (;;) // A Task shall never return or exit.
{
// read the input pin:
if(start2 == HIGH){
vTaskDelay( 1000 / portTICK_PERIOD_MS );
counter2++;
}
if ( xSemaphoreTake( xSerialSemaphore, ( TickType_t ) 5 ) == pdTRUE )
{
// We were able to obtain or "Take" the semaphore and can now access the shared resource.
// We want to have the Serial Port for us alone, as it takes some time to print,
// so we don't want it getting stolen during the middle of a conversion.
// print out the state of the button:
Serial.println("counter2");
Serial.println(counter2);
xSemaphoreGive( xSerialSemaphore ); // Now free or "Give" the Serial Port for others.
}
//if(counter > 30){///// counter as timer for 20 min
//digitalWrite(EA4, LOW);}
// }
// else counter = 0;
// See if we can obtain or "Take" the Serial Semaphore.
// If the semaphore is not available, wait 5 ticks of the Scheduler to see if it becomes free.
vTaskDelay(1); // one tick delay (15ms) in between reads for stability
}
}
/*--------------------------------------------------*/
/*---------------------- Tasks ---------------------*/
/*--------------------------------------------------*/
void TaskTimer3( void *pvParameters __attribute__((unused)) ) // This is a Task.
{
/*
DigitalReadSerial
Reads a digital input on pin 2, prints the result to the serial monitor
pinMode(timer1, INPUT_PULLUP);//
pinMode(timer2,INPUT_PULLUP); //
pinMode(timer3, INPUT_PULLUP); //
pinMode(timer4, INPUT_PULLUP); //
This example code is in the public domain.
*/
// digital pin 2 has a pushbutton attached to it. Give it a name:
// make the pushbutton's pin an input:
for (;;) // A Task shall never return or exit.
{
if(start3 == HIGH){
vTaskDelay( 1000 / portTICK_PERIOD_MS );
counter3++;
}
if ( xSemaphoreTake( xSerialSemaphore, ( TickType_t ) 5 ) == pdTRUE )
{
// We were able to obtain or "Take" the semaphore and can now access the shared resource.
// We want to have the Serial Port for us alone, as it takes some time to print,
// so we don't want it getting stolen during the middle of a conversion.
// print out the state of the button:
Serial.println("counter3");
Serial.println(counter3);
xSemaphoreGive( xSerialSemaphore ); // Now free or "Give" the Serial Port for others.
}
//if(counter > 30){///// counter as timer for 20 min
//digitalWrite(EA4, LOW);}
// }
// else counter = 0;
// See if we can obtain or "Take" the Serial Semaphore.
// If the semaphore is not available, wait 5 ticks of the Scheduler to see if it becomes free.
vTaskDelay(1); // one tick delay (15ms) in between reads for stability
}
}
/*--------------------------------------------------*/
/*---------------------- Tasks ---------------------*/
/*--------------------------------------------------*/
void TaskTimer4( void *pvParameters __attribute__((unused)) ) // This is a Task.
{
/*
DigitalReadSerial
Reads a digital input on pin 2, prints the result to the serial monitor
pinMode(timer1, INPUT_PULLUP);//
pinMode(timer2,INPUT_PULLUP); //
pinMode(timer3, INPUT_PULLUP); //
pinMode(timer4, INPUT_PULLUP); //
This example code is in the public domain.
*/
// digital pin 2 has a pushbutton attached to it. Give it a name:
// pinMode(EA1, OUTPUT);//
// pinMode(EA2, OUTPUT);//
// pinMode(EA3, OUTPUT);//
// pinMode(EA4, OUTPUT);//
/////////////////////////
//READ FROM TIMER 1--4////
// pinMode(timer4, INPUT_PULLUP); //
// make the pushbutton's pin an input:
for (;;) // A Task shall never return or exit.
{
// read the input pin:
//int State4 = digitalRead(timer1);
//if(State4 == HIGH){
if(start4 == LOW){
vTaskDelay( 1000 / portTICK_PERIOD_MS );
counter4++;
}
if ( xSemaphoreTake( xSerialSemaphore, ( TickType_t ) 5 ) == pdTRUE )
{
// We were able to obtain or "Take" the semaphore and can now access the shared resource.
// We want to have the Serial Port for us alone, as it takes some time to print,
// so we don't want it getting stolen during the middle of a conversion.
// print out the state of the button:
Serial.println("counter4");
Serial.println(counter4);
xSemaphoreGive( xSerialSemaphore ); // Now free or "Give" the Serial Port for others.
}
//if(counter > 30){///// counter as timer for 20 min
//digitalWrite(EA4, LOW);}
// }
// else counter = 0;
// See if we can obtain or "Take" the Serial Semaphore.
// If the semaphore is not available, wait 5 ticks of the Scheduler to see if it becomes free.
vTaskDelay(1); // one tick delay (15ms) in between reads for stability
}
}
/*--------------------------------------------------*/
/*---------------------- Tasks ---------------------*/
/*--------------------------------------------------*/
void TaskRelay( void *pvParameters __attribute__((unused)) ) // This is a Task.
{
pinMode(EA1, OUTPUT);//
pinMode(EA2, OUTPUT);//
pinMode(EA3, OUTPUT);//
pinMode(EA4, OUTPUT);//
pinMode(BLEU, OUTPUT);//
/////////////////////////
//READ FROM TIMER 1--4////
pinMode(timer1, INPUT);//
pinMode(timer2,INPUT); //
pinMode(timer3, INPUT); //
pinMode(timer4, INPUT); //
pinMode(RESET, INPUT_PULLUP); //
for (;;)
{
// read the input :
start1=digitalRead(timer1);//
start2=digitalRead(timer2);////////////////////////// read timer position on/off
start3=digitalRead(timer3);//
start4=digitalRead(timer4);//
if((start1 == HIGH)&&(counter1<30)){
digitalWrite(EA1, HIGH);
counter1=0;
}
else if ((start1 == LOW)&&(buttonPushCounter2==1)&&(counter1<30)){
digitalWrite(EA1, LOW);
}
else if((start1 == LOW)&&(counter1>30)) {
digitalWrite(EA1, HIGH);
if(RESET==HIGH){
counter1=0;
}
}
if(start2 == HIGH){
digitalWrite(EA2, HIGH);
}
else if ((start2 == LOW)&&(buttonPushCounter1==1)){
digitalWrite(EA2, LOW);
}
if(start3 == HIGH){
digitalWrite(EA3, HIGH);
}
else if((start3 == LOW)&&(buttonPushCounter3==1)){
digitalWrite(EA3, LOW);
}
if(start4 == HIGH){
digitalWrite(EA4, HIGH);
}
else if((start4 == LOW)&&(buttonPushCounter4==1)){
digitalWrite(EA4, LOW);
}
// See if we can obtain or "Take" the Serial Semaphore.
// If the semaphore is not available, wait 5 ticks of the Scheduler to see if it becomes free.
if ( xSemaphoreTake( xSerialSemaphore, ( TickType_t ) 5 ) == pdTRUE )
{
// We were able to obtain or "Take" the semaphore and can now access the shared resource.
// We want to have the Serial Port for us alone, as it takes some time to print,
// so we don't want it getting stolen during the middle of a conversion.
// print out the value you read:
// Serial.println(start1);
// Serial.println(start2);
// Serial.println(start3);
// Serial.println(start4);
xSemaphoreGive( xSerialSemaphore ); // Now free or "Give" the Serial Port for others.
}
vTaskDelay(1); // one tick delay (15ms) in between reads for stability
}
}
/*--------------------------------------------------*/
/*---------------------- Tasks ---------------------*/
/*--------------------------------------------------*/
void TaskFIFO( void *pvParameters __attribute__((unused)) ) // This is a Task.
{
pinMode(a1, OUTPUT); //A1
pinMode(b1, OUTPUT); //B1
pinMode(c1, OUTPUT); //C1
pinMode(d1, OUTPUT); //D1
pinMode(e1, OUTPUT); //E1
pinMode(f1, OUTPUT); //F1
pinMode(g1, OUTPUT); //G1
pinMode(a2, OUTPUT); //A2
pinMode(b2, OUTPUT); //B2
pinMode(c2, OUTPUT); //C2
pinMode(d2, OUTPUT); //D2
pinMode(e2, OUTPUT); //E2
pinMode(f2, OUTPUT); //F2
pinMode(g2, OUTPUT); //G2
pinMode(a3, OUTPUT); //A3
pinMode(b3, OUTPUT); //B3
pinMode(c3, OUTPUT); //C3
pinMode(d3, OUTPUT); //D3
pinMode(e3, OUTPUT); //E3
pinMode(f3, OUTPUT); //F3
pinMode(g3, OUTPUT); //G3
pinMode(a4, OUTPUT); //A4
pinMode(b4, OUTPUT); //B4
pinMode(c4, OUTPUT); //C4
pinMode(d4, OUTPUT); //D4
pinMode(e4, OUTPUT); //E4
pinMode(f4, OUTPUT); //F4
pinMode(g4, OUTPUT); //G4
pinMode( FirstbuttonPin , INPUT_PULLUP);
pinMode( SeconbuttonPin , INPUT_PULLUP);
pinMode( ThirdbuttonPin , INPUT_PULLUP);
pinMode( FourthbuttonPin , INPUT_PULLUP);
for (;;)
{
// read the input on analog pin 0:
FirstbuttonState = digitalRead(FirstbuttonPin);
SecondbuttonState = digitalRead(SeconbuttonPin);
ThirdbuttonState = digitalRead(ThirdbuttonPin);
FourthbuttonState = digitalRead(FourthbuttonPin);
checkFirstButtonPress();
checkSecondButtonPress();
checkThirdButtonPress();
checkFourthButtonPress();
if( b1Press1 )
{
b1Press1 = false;
swic1(buttonPushCounter1);
swic2(buttonPushCounter2);
swic3(buttonPushCounter3);
swic4(buttonPushCounter4);
}
if( b2Press1 ){
swic1(buttonPushCounter1);
swic2(buttonPushCounter2);
swic3(buttonPushCounter3);
swic4(buttonPushCounter4);
}
if( b3Press1 ){
swic1(buttonPushCounter1);
swic2(buttonPushCounter2);
swic3(buttonPushCounter3);
swic4(buttonPushCounter4);
}
if( b4Press1 ){
swic1(buttonPushCounter1);
swic2(buttonPushCounter2);
swic3(buttonPushCounter3);
swic4(buttonPushCounter4);
}
// See if we can obtain or "Take" the Serial Semaphore.
// If the semaphore is not available, wait 5 ticks of the Scheduler to see if it becomes free.
if ( xSemaphoreTake( xSerialSemaphore, ( TickType_t ) 5 ) == pdTRUE )
{
// We were able to obtain or "Take" the semaphore and can now access the shared resource.
// We want to have the Serial Port for us alone, as it takes some time to print,
// so we don't want it getting stolen during the middle of a conversion.
// print out the value you read:
/*
Serial.println("-------------");
Serial.println("buttonPushCounter1");
Serial.println(buttonPushCounter1);
Serial.println("buttonPushCounter2");
Serial.println(buttonPushCounter2);
Serial.println("buttonPushCounter3");
Serial.println(buttonPushCounter3);
Serial.println("buttonPushCounter4");
Serial.println(buttonPushCounter4);
Serial.println("-------------"); */
xSemaphoreGive( xSerialSemaphore ); // Now free or "Give" the Serial Port for others.
}
vTaskDelay(1); // one tick delay (15ms) in between reads for stability
}
}
void FIFO(){
if((start1 == HIGH)&&(buttonPushCounter1==1)&&(buttonPushCounter2=!1)&&(buttonPushCounter3=!1)&&(buttonPushCounter4=!1) ){
digitalWrite(EA1, HIGH);
Serial.println("EA1 UNLOCKED");
delay(200);
}
if((start2 == HIGH)&&(buttonPushCounter2==1)&&(buttonPushCounter1=!1)&&(buttonPushCounter3=!1)&&(buttonPushCounter4=!1) ){
digitalWrite(EA2, HIGH);
Serial.println("EA2 UNLOCKED");
delay(200);
}
if((start3 == HIGH)&&(buttonPushCounter3==1)&&(buttonPushCounter2=!1)&&(buttonPushCounter1=!1)&&(buttonPushCounter4=!1) ){
digitalWrite(EA3, HIGH);
Serial.println("EA3 UNLOCKED");
delay(200);
}
if((start4 == HIGH)&&(buttonPushCounter4==1)&&(buttonPushCounter2=!1)&&(buttonPushCounter3=!1)&&(buttonPushCounter1=!1) ){
digitalWrite(EA4, HIGH);
Serial.println("EA4 UNLOCKED");
delay(200);
}
}
void checkFirstButtonPress()
{
// compare the buttonState to its previous state
if (FirstbuttonState != LastFirstbuttonState) {
// if the state has changed, increment the counter
if (FirstbuttonState == LOW) {
// if the current state is HIGH then the button went from off to on:
b1Press1 = true;
Serial.println("FirstButton");
c=buttonPushCounter1;
buttonPushCounter1= max(buttonPushCounter1,buttonPushCounter2);
buttonPushCounter1= max(buttonPushCounter1,buttonPushCounter3);
buttonPushCounter1= max(buttonPushCounter1,buttonPushCounter4);
buttonPushCounter1++;
if (c !=0) {
if(c ==1){
buttonPushCounter1--;
buttonPushCounter2--;
buttonPushCounter3--;
buttonPushCounter4--;
}
if(c ==2){
if( buttonPushCounter1 >= 2) buttonPushCounter1--;
if( buttonPushCounter2 >= 2) buttonPushCounter2--;
if( buttonPushCounter3 >= 2) buttonPushCounter3--;
if( buttonPushCounter4 >= 2) buttonPushCounter4--;
}
if(c ==3){
if( buttonPushCounter1 >= 3) buttonPushCounter1--;
if( buttonPushCounter2 >= 3) buttonPushCounter2--;
if( buttonPushCounter3 >= 3) buttonPushCounter3--;
if( buttonPushCounter4 >= 3) buttonPushCounter4--;
}
if(c ==4){
if( buttonPushCounter1 >= 4) buttonPushCounter1--;
if( buttonPushCounter2 >= 4) buttonPushCounter2--;
if( buttonPushCounter3 >= 4) buttonPushCounter3--;
if( buttonPushCounter4 >= 4) buttonPushCounter4--;
}
}
if( buttonPushCounter1 <= 0) buttonPushCounter1 =0 ;
if( buttonPushCounter2 <= 0) buttonPushCounter2 =0 ;
if( buttonPushCounter3 <= 0) buttonPushCounter3 =0 ;
if( buttonPushCounter4 <= 0) buttonPushCounter4 =0 ;
if( buttonPushCounter1 >= 4) buttonPushCounter1 =4 ;
Serial.println("on");
} else {
// if the current state is LOW then the button went from on to off:
Serial.println("of");
}
// Delay a little bit to avoid bouncing
delay(50);
}
// save the current state as the last state, for next time through the loop
LastFirstbuttonState = FirstbuttonState;
}
void checkSecondButtonPress()
{
// compare the buttonState to its previous state
if (SecondbuttonState != LastSecondbuttonState) {
// if the state has changed, increment the counter
if (SecondbuttonState == LOW) {
// if the current state is HIGH then the button went from off to on:
b2Press1 = true;
Serial.println("SecondButton");
d=buttonPushCounter2;
buttonPushCounter2= max(buttonPushCounter2,buttonPushCounter1);
buttonPushCounter2= max(buttonPushCounter2,buttonPushCounter3);
buttonPushCounter2= max(buttonPushCounter2,buttonPushCounter4);
buttonPushCounter2++;
if (d !=0) {
if(d ==1){
buttonPushCounter1--;
buttonPushCounter2--;
buttonPushCounter3--;
buttonPushCounter4--;
}
if(d ==2){
if( buttonPushCounter1 >= 2) buttonPushCounter1--;
if( buttonPushCounter2 >= 2) buttonPushCounter2--;
if( buttonPushCounter3 >= 2) buttonPushCounter3--;
if( buttonPushCounter4 >= 2) buttonPushCounter4--;
}
if(d ==3){
if( buttonPushCounter1 >= 3) buttonPushCounter1--;
if( buttonPushCounter2 >= 3) buttonPushCounter2--;
if( buttonPushCounter3 >= 3) buttonPushCounter3--;
if( buttonPushCounter4 >= 3) buttonPushCounter4--;
}
if(d ==4){
if( buttonPushCounter1 >= 4) buttonPushCounter1--;
if( buttonPushCounter2 >= 4) buttonPushCounter2--;
if( buttonPushCounter3 >= 4) buttonPushCounter3--;
if( buttonPushCounter4 >= 4) buttonPushCounter4--;
}
}
if( buttonPushCounter1 <= 0) buttonPushCounter1 =0 ;
if( buttonPushCounter2 <= 0) buttonPushCounter2 =0 ;
if( buttonPushCounter3 <= 0) buttonPushCounter3 =0 ;
if( buttonPushCounter4 <= 0) buttonPushCounter4 =0 ;
if( buttonPushCounter2 >= 4) buttonPushCounter2 =4 ;
Serial.println("onn");
} else {
// if the current state is LOW then the button went from on to off:
Serial.println("off");
}
// Delay a little bit to avoid bouncing
delay(50);
}
// save the current state as the last state, for next time through the loop
LastSecondbuttonState = SecondbuttonState;
}
void checkThirdButtonPress()
{
// compare the buttonState to its previous state
if (ThirdbuttonState != LastThirdbuttonState) {
// if the state has changed, increment the counter
if (ThirdbuttonState == LOW) {
// if the current state is HIGH then the button went from off to on:
b3Press1 = true;
Serial.println("ThiredButton");
e=buttonPushCounter3;
buttonPushCounter3=max(buttonPushCounter3,buttonPushCounter1);
buttonPushCounter3=max(buttonPushCounter3,buttonPushCounter2);
buttonPushCounter3=max(buttonPushCounter3,buttonPushCounter4);
buttonPushCounter3++;
if (e !=0) {
if(e ==1){
buttonPushCounter1--;
buttonPushCounter2--;
buttonPushCounter3--;
buttonPushCounter4--;
}
if(e ==2){
if( buttonPushCounter1 >= 2) buttonPushCounter1--;
if( buttonPushCounter2 >= 2) buttonPushCounter2--;
if( buttonPushCounter3 >= 2) buttonPushCounter3--;
if( buttonPushCounter4 >= 2) buttonPushCounter4--;
}
if(e ==3){
if( buttonPushCounter1 >= 3) buttonPushCounter1--;
if( buttonPushCounter2 >= 3) buttonPushCounter2--;
if( buttonPushCounter3 >= 3) buttonPushCounter3--;
if( buttonPushCounter4 >= 3) buttonPushCounter4--;
}
if(e ==4){
if( buttonPushCounter1 >= 4) buttonPushCounter1--;
if( buttonPushCounter2 >= 4) buttonPushCounter2--;
if( buttonPushCounter3 >= 4) buttonPushCounter3--;
if( buttonPushCounter4 >= 4) buttonPushCounter4--;
}
}
if( buttonPushCounter1 <= 0) buttonPushCounter1 =0 ;
if( buttonPushCounter2 <= 0) buttonPushCounter2 =0 ;
if( buttonPushCounter3 <= 0) buttonPushCounter3 =0 ;
if( buttonPushCounter4 <= 0) buttonPushCounter4 =0 ;
if( buttonPushCounter3 >= 4) buttonPushCounter3 =4 ;
Serial.println("onnn");
} else {
// if the current state is LOW then the button went from on to off:
Serial.println("offf");
}
// Delay a little bit to avoid bouncing
delay(50);
}
// save the current state as the last state, for next time through the loop
LastThirdbuttonState = ThirdbuttonState;
}
void checkFourthButtonPress()
{
// compare the buttonState to its previous state
if (FourthbuttonState != LastFourthbuttonState) {
// if the state has changed, increment the counter
if (FourthbuttonState == LOW) {
// if the current state is HIGH then the button went from off to on:
b4Press1 = true;
Serial.println("FourthButton");
f=buttonPushCounter4;
buttonPushCounter4=max(buttonPushCounter4,buttonPushCounter1);
buttonPushCounter4=max(buttonPushCounter4,buttonPushCounter2);
buttonPushCounter4=max(buttonPushCounter4,buttonPushCounter3);
buttonPushCounter4++;
if (f !=0) {
if(f==1){
buttonPushCounter1--;
buttonPushCounter2--;
buttonPushCounter3--;
buttonPushCounter4--;
}
if(f==2){
if( buttonPushCounter1 >= 2) buttonPushCounter1--;
if( buttonPushCounter2 >= 2) buttonPushCounter2--;
if( buttonPushCounter3 >= 2) buttonPushCounter3--;
if( buttonPushCounter4 >= 2) buttonPushCounter4--;
}
if(f==3){
if( buttonPushCounter1 >= 3) buttonPushCounter1--;
if( buttonPushCounter2 >= 3) buttonPushCounter2--;
if( buttonPushCounter3 >= 3) buttonPushCounter3--;
if( buttonPushCounter4 >= 3) buttonPushCounter4--;
}
if(f==4){
if( buttonPushCounter1 >= 4) buttonPushCounter1--;
if( buttonPushCounter2 >= 4) buttonPushCounter2--;
if( buttonPushCounter3 >= 4) buttonPushCounter3--;
if( buttonPushCounter4 >= 4) buttonPushCounter4--;
}
}
if( buttonPushCounter1 <= 0) buttonPushCounter1 =0 ;
if( buttonPushCounter2 <= 0) buttonPushCounter2 =0 ;
if( buttonPushCounter3 <= 0) buttonPushCounter3 =0 ;
if( buttonPushCounter4 <= 0) buttonPushCounter4 =0 ;
if( buttonPushCounter4 >= 4) buttonPushCounter4 =4 ;
Serial.println("onnnn");
} else {
// if the current state is LOW then the button went from on to off:
Serial.println("offff");
}
// Delay a little bit to avoid bouncing
delay(50);
}
// save the current state as the last state, for next time through the loop
LastFourthbuttonState = FourthbuttonState;
}
void one1() {
digitalWrite(c1, HIGH);
digitalWrite(d1, LOW);
digitalWrite(e1, LOW);
digitalWrite(b1, HIGH);
digitalWrite(a1, LOW);
digitalWrite(g1, LOW);
digitalWrite(f1, LOW);
}
void one2() {
digitalWrite(c2, HIGH);
digitalWrite(d2, LOW);
digitalWrite(e2, LOW);
digitalWrite(b2, HIGH);
digitalWrite(a2, LOW);
digitalWrite(g2, LOW);
digitalWrite(f2, LOW);
}
void one3() {
digitalWrite(c3, HIGH);
digitalWrite(d3, LOW);
digitalWrite(e3, LOW);
digitalWrite(b3, HIGH);
digitalWrite(a3, LOW);
digitalWrite(g3, LOW);
digitalWrite(f3, LOW);
}
void one4() {
digitalWrite(c4, HIGH);
digitalWrite(d4, LOW);
digitalWrite(e4, LOW);
digitalWrite(b4, HIGH);
digitalWrite(a4, LOW);
digitalWrite(g4, LOW);
digitalWrite(f4, LOW);
}
void tow1() {
digitalWrite(c1, LOW);
digitalWrite(d1, HIGH);
digitalWrite(e1, HIGH);
digitalWrite(b1, HIGH);
digitalWrite(a1, HIGH);
digitalWrite(g1, HIGH);
digitalWrite(f1, LOW);
}
void tow2() {
digitalWrite(c2, LOW);
digitalWrite(d2, HIGH);
digitalWrite(e2, HIGH);
digitalWrite(b2, HIGH);
digitalWrite(a2, HIGH);
digitalWrite(g2, HIGH);
digitalWrite(f2, LOW);
}
void tow3() {
digitalWrite(c3, LOW);
digitalWrite(d3, HIGH);
digitalWrite(e3, HIGH);
digitalWrite(b3, HIGH);
digitalWrite(a3, HIGH);
digitalWrite(g3, HIGH);
digitalWrite(f3, LOW);
}
void tow4() {
digitalWrite(c4, LOW);
digitalWrite(d4, HIGH);
digitalWrite(e4, HIGH);
digitalWrite(b4, HIGH);
digitalWrite(a4, HIGH);
digitalWrite(g4, HIGH);
digitalWrite(f4, LOW);
}
void three1() {
digitalWrite(c1, HIGH);
digitalWrite(d1, HIGH);
digitalWrite(e1, LOW);
digitalWrite(b1, HIGH);
digitalWrite(a1,HIGH);
digitalWrite(g1, HIGH);
digitalWrite(f1, LOW);
}
void three2() {
digitalWrite(c2, HIGH);
digitalWrite(d2, HIGH);
digitalWrite(e2, LOW);
digitalWrite(b2, HIGH);
digitalWrite(a2,HIGH);
digitalWrite(g2, HIGH);
digitalWrite(f2, LOW);
}
void three3() {
digitalWrite(c3, HIGH);
digitalWrite(d3, HIGH);
digitalWrite(e3, LOW);
digitalWrite(b3, HIGH);
digitalWrite(a3,HIGH);
digitalWrite(g3, HIGH);
digitalWrite(f3, LOW);
}
void three4() {
digitalWrite(c4, HIGH);
digitalWrite(d4, HIGH);
digitalWrite(e4, LOW);
digitalWrite(b4, HIGH);
digitalWrite(a4,HIGH);
digitalWrite(g4, HIGH);
digitalWrite(f4, LOW);
}
void four1() {
digitalWrite(c1, HIGH);
digitalWrite(d1, LOW);
digitalWrite(e1, LOW);
digitalWrite(b1, HIGH);
digitalWrite(a1, LOW);
digitalWrite(g1, HIGH);
digitalWrite(f1, HIGH);
}
void four2() {
digitalWrite(c2, HIGH);
digitalWrite(d2, LOW);
digitalWrite(e2, LOW);
digitalWrite(b2, HIGH);
digitalWrite(a2, LOW);
digitalWrite(g2, HIGH);
digitalWrite(f2, HIGH);
}
void four3() {
digitalWrite(c3, HIGH);
digitalWrite(d3, LOW);
digitalWrite(e3, LOW);
digitalWrite(b3, HIGH);
digitalWrite(a3, LOW);
digitalWrite(g3, HIGH);
digitalWrite(f3, HIGH);
}
void four4() {
digitalWrite(c4, HIGH);
digitalWrite(d4, LOW);
digitalWrite(e4, LOW);
digitalWrite(b4, HIGH);
digitalWrite(a4, LOW);
digitalWrite(g4, HIGH);
digitalWrite(f4, HIGH);
}
void off1() {
digitalWrite(c1, LOW);
digitalWrite(d1, LOW);
digitalWrite(e1, LOW);
digitalWrite(b1, LOW);
digitalWrite(a1, LOW);
digitalWrite(g1, HIGH);
digitalWrite(f1, LOW);
}
void off2(){
digitalWrite(c2, LOW);
digitalWrite(d2, LOW);
digitalWrite(e2, LOW);
digitalWrite(b2, LOW);
digitalWrite(a2, LOW);
digitalWrite(g2, HIGH);
digitalWrite(f2, LOW);
}
void off3() {
digitalWrite(c3, LOW);
digitalWrite(d3, LOW);
digitalWrite(e3, LOW);
digitalWrite(b3, LOW);
digitalWrite(a3, LOW);
digitalWrite(g3, HIGH);
digitalWrite(f3, LOW);
}
void off4(){
digitalWrite(c4, LOW);
digitalWrite(d4, LOW);
digitalWrite(e4, LOW);
digitalWrite(b4, LOW);
digitalWrite(a4, LOW);
digitalWrite(g4, HIGH);
digitalWrite(f4, LOW);
}
void turnOff() {
digitalWrite(a1,LOW);
digitalWrite(b1,LOW);
digitalWrite(c1,LOW);
digitalWrite(d1,LOW);
digitalWrite(e1,LOW);
digitalWrite(f1,LOW);
digitalWrite(g1,LOW);
}
void swic1(int a) {
switch(a)
{
case 0:
off1();
break;
case 1:
one1();
break;
case 2:
tow1();
break;
case 3:
three1();
break;
case 4:
four1();
break;
}
}
void swic2(int a){
switch(a)
{
case 0:
off2();
break;
case 1:
one2();
break;
case 2:
tow2();
break;
case 3:
three2();
break;
case 4:
four2();
break;
}
}
void swic3(int a){
switch(a)
{
case 0:
off3();
break;
case 1:
one3();
break;
case 2:
tow3();
break;
case 3:
three3();
break;
case 4:
four3();
break;
}
}
void swic4(int a){
switch(a)
{
case 0:
off4();
break;
case 1:
one4();
break;
case 2:
tow4();
break;
case 3:
three4();
break;
case 4:
four4();
break;
}
}