Professional Documents
Culture Documents
Final Lab Exp 7 Codes
Final Lab Exp 7 Codes
//'counter' variables
int x = 0;//counter for void function "ones"
int y = 0;//counter for void function "tens"
void setup(){//initialization
//configuring pins as OUTPUTS and INPUTS
void ON(){
//function to turn ON all the LED segments for both SSD
//they are set to LOW since it is an INPUT_PULLUP config
for(int pin = 0; pin < 14; pin++){
digitalWrite(pin, LOW);
}
}
void zero(){
//function to display "00" on both SSD
ones(0);
tens(0);
}
void OFF(){
//function to turn OFF all the LED segments for both SSD
//they are set to HIGH since it is an INPUT_PULLUP config
for(int pin = 0; pin < 14; pin++){
digitalWrite(pin, HIGH);
}
}
void scenario2(){
//function to display digits 00 to 99
if(buttonstate3 == LOW){
//incrementing function
x+=1;//incrementing count for 'x'
ones(x);//display digit corresponding to value of 'x'
tens(y);//display digit corresponding to value of 'y'
delay(timer2);//200ms delay
}
else if(x>9){
//this is to limit counter 'ones' to the max value of 9
//increments the value of 'tens' each time 'ones' > 9
y++;//increment value for 'tens'
x=0;//resets 'ones' to 0
ones(x);
tens(y);
}
else if(y>9){
//limits the counters to only display '99'
//provides the maximum limit for counting
y=9;//resets 'ones' & 'tens' to 9
x=9;
ones(9);//display '99' on 'ones' & 'tens'
tens(9);
}
if(buttonstate4 == LOW){
//decrementing function
x-=1;//decrementing count for 'x'
ones(x);//display digit corresponding to value of 'x'
tens(y);//display digit corresponding to value of 'y'
delay(timer2);//200ms delay
}
else if(x<0 && y != 0){
//limits the counter 'ones' to a minimum value of 0
//decrements 'tens' each time 'ones' < 0
y--;//decrement value for 'tens'
x=9;//reset 'ones' to 9
ones(x);
tens(y);
}
else if(y<0 || x<0){
//this is to prevent the counter from going in to the negative values
//provides the minimum limit for counting
x=0;//resets 'ones' & 'tens' to 0
y=0;
ones(0);//display '00' on 'ones' & 'tens'
tens(0);
}
-----------------------------------------------------------------------------------
------------
Problem#2
//'counter' variables
int x = 0;//counter for void function "ones"
int y = 0;//counter for void function "tens"
void setup(){//initialization
//configuring pins as OUTPUTS and INPUTS
void ON(){
//function to turn ON all the LED segments for both SSD
//they are set to LOW since it is an INPUT_PULLUP config
for(int pin = 0; pin < 14; pin++){
digitalWrite(pin, LOW);
}
}
void zero(){
//function to display "00" on both SSD
ones(0);
tens(0);
}
void OFF(){
//function to turn OFF all the LED segments for both SSD
//they are set to HIGH since it is an INPUT_PULLUP config
for(int pin = 0; pin < 14; pin++){
digitalWrite(pin, HIGH);
}
}
void scenario2(){
//function to display digits 00 to 99
}
}
if(y3 == 0){
//display digits 0 & 9
ones(0);
tens(9);
}
if(y3==1){
//display digits 1 & 8
ones(1);
tens(8);
}
if(y3==2){
//display digits 2 & 7
ones(2);
tens(7);
}
if(y3==3){
//display digits 3 & 6
ones(3);
tens(6);
}
if(y3==4){
//display digits 4 & 5
ones(4);
tens(5);
}
if(y3==5){
//display digits 5 & 4
ones(5);
tens(4);
}
if(y3==6){
//display digits 6 & 3
ones(6);
tens(3);
}
if(y3==7){
//display digits 7 & 2
ones(7);
tens(2);
}
if(y3==8){
//display digits 8 & 1
ones(8);
tens(1);
}
if(y3==9){
//display digits 9 & 0
ones(9);
tens(0);
}
}
void loop (){//main bulk of the code for problem#2
//set variables for our button readings
bool buttonstate1 = digitalRead(button1);
bool buttonstate2 = digitalRead(button2);
bool buttonstate3 = digitalRead(button3);
bool buttonstate4 = digitalRead(button4);
if(buttonstate4 == LOW){
//blinking 00's
//1st blink
OFF();//turns OFF all the segments on both SSD
delay(timer);//500ms to stay OFF
ON();
/*after a short delay, turn ON all segments to revert the OFF function
then simultaneously displaying the digits '00'; the whole cycle
of ON & OFF will repeat for 10 times*/
//2nd blink
zero();
delay(timer);//500ms to stay on '00'
OFF();
delay(timer);
ON();
//3rd blink
zero();
delay(timer);
OFF();
delay(timer);
ON();
//4th blink
zero();
delay(timer);
OFF();
delay(timer);
ON();
//5th blink
zero();
delay(timer);
OFF();
delay(timer);
ON();
//6th blink
zero();
delay(timer);
OFF();
delay(timer);
ON();
//7th blink
zero();
delay(timer);
OFF();
delay(timer);
ON();
//8th blink
zero();
delay(timer);
OFF();
delay(timer);
ON();
//9th blink
zero();
delay(timer);
OFF();
delay(timer);
ON();
//10th blink
zero();
delay(timer);
OFF();
delay(timer);
ON();