/////////////////////////////////////////
// name: task to understand switch cases
// arther: James Beven.
// version 1.0
// description: program will flash lamps
////////////////////////////////////////
// definitions
///////////////////////////////////////
int USER_BTN_01 = 2; // upper snake case //constent
int LAMP_1 = 3;;
int LAMP_2 = 4;
int SeqNo = 0;
int SeqNoNext = 10;
int flashcount;
int btn_status;
void setup()
{//////////////////////////////////////
// I.O assignment
/////////////////////////////////////
// Inputs.
pinMode(USER_BTN_01, INPUT);
// Outputs.
pinMode(LAMP_1, OUTPUT);
pinMode(LAMP_2, OUTPUT);
/////////////////////////////////////
// Serial setup
////////////////////////////////////
Serial.begin(9600);
}
void loop()
{
////////////////////////////////////////////////////
// Gets Input Statuses
/////////////////////////////////////////////////////
btn_status = digitalRead(USER_BTN_01);
////////////////////////////////////////////////////
//Update Sequence Number
////////////////////////////////////////////////////
if (SeqNo != SeqNoNext)
{
SeqNo = SeqNoNext;
}
switch(SeqNo)
{
///////////////////////////////////////////////////
//case 10 - wait user butten.
//////////////////////////////////////////////////
case 10:
Serial.println(" waiting user butten");
if (btn_status == 1)
{
SeqNoNext = 20;
}
break;
//////////////////////////////////////////////////
//case 20 - flash lamp
/////////////////////////////////////////////////
case 20:
Serial.println("Lamp Flashing ");
flashcount ++;
if (flashcount % 2 == 0) // MODULUS Argument: to help find odd and even numbers
{
digitalWrite(LAMP_1, HIGH);
}
else
{
digitalWrite(LAMP_1, LOW);
}
if (flashcount >= 10)
{
SeqNoNext = 30;
}
break;
//////////////////////////////////////////////////
// case 30 - turn lamp 1 off
//////////////////////////////////////////////////
case 30:
Serial.println("turn off lamp");
digitalWrite(LAMP_1, LOW);
digitalWrite(LAMP_2, HIGH);
SeqNoNext = 40;
break;
/////////////////////////////////////////////////
// case 40 - wait user butten
////////////////////////////////////////////////
case 40:
Serial.println("wait user butten");
if (btn_status == 0)
{
SeqNoNext = 50;
}
break;
///////////////////////////////////////////////
//case 50 - turn lamp 2 off
//////////////////////////////////////////////
case 50:
Serial.println("turning lamp 2 off");
digitalWrite(LAMP_2,LOW);
SeqNoNext = 10;
break;
}
delay(1000);
}