Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 13

Problem#1

//this is for common ANODE config


int button1 = A1;//sets variable for our analog pins
int button2 = A2;
int button3 = A3;
int button4 = A4;

int timer = 500;//500ms delay


int timer2 = 200;//200ms delay

//'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

//pins 2-8 for the right SSD


//pins 0,1,9-13 for the left SSD
for (int pin = 0; pin < 14; pin++){
//digital pins for OUTPUT
pinMode(pin, OUTPUT);
}

//analog pins for INPUT


pinMode(button1, INPUT_PULLUP);//A1
pinMode(button2, INPUT_PULLUP);//A2
pinMode(button3, INPUT_PULLUP);//A3
pinMode(button4, INPUT_PULLUP);//A4

void ones(int n){


//this is the function to diplay digit 0-9 for the RIGHT SSD
//int 'n' is used to determine which digit to display
//value of 'n' corresponds to the digit to be displayed
//pins utilized: 0-1 & 9-13

if(n == 0){//display digit 0


digitalWrite(0, LOW);
for(int a = 10; a < 13; a++){
digitalWrite(a, LOW);
}//LOW the adjacent digits 1 and 9
digitalWrite(13, HIGH);
}
if(n == 1){//display digit 1
digitalWrite(9, LOW);
//LOW the adjacent digits 0 and 2
digitalWrite(0, HIGH);
for(int a = 10; a < 14; a++){
digitalWrite(a, HIGH);
}
}
if(n == 2){//display digit 2
digitalWrite(0, LOW);
for(int a = 10; a < 14; a++){
digitalWrite(a, LOW);
}
//LOW the adjacent digits 1 and 3
digitalWrite(9, HIGH);
digitalWrite(12, HIGH);
}
if(n == 3){//display digit 3
digitalWrite(9, LOW);
digitalWrite(0, LOW);
digitalWrite(10, LOW);
//LOW the adjacent digits 2 and 4
digitalWrite(11, HIGH);
digitalWrite(12, HIGH);
}
if(n == 4){//display digit 4
digitalWrite(12, LOW);
digitalWrite(1, LOW);
//LOW the adjacent digits 3 and 5
digitalWrite(0, HIGH);
digitalWrite(10, HIGH);
digitalWrite(11, HIGH);
}
if(n == 5){//display digit 5
digitalWrite(0, LOW);
digitalWrite(10, LOW);
//LOW the adjacent digits 4 and 6
digitalWrite(1, HIGH);
digitalWrite(11, HIGH);
}
if(n == 6){//display digit 6
for(int a = 10; a < 14; a++){
digitalWrite(a, LOW);
}
//LOW the adjacent digits 5 and 7
digitalWrite(1, HIGH);
}
if(n == 7){//display digit 7
digitalWrite(1, LOW);
//LOW the adjacent digits 6 and 8
for(int a = 10; a < 14; a++){
digitalWrite(a, HIGH);
}
}
if(n == 8){//display digit 8
//LOW every segment to display digit 8
digitalWrite(0, LOW);
digitalWrite(1, LOW);
for(int a = 9; a < 14; a++){
digitalWrite(a, LOW);
}
}
if(n == 9){//display digit 9
digitalWrite(13, LOW);
//LOW the adjacent digit 0
digitalWrite(10, HIGH);
digitalWrite(11, HIGH);
}

void tens(int m){


//function to diplay digit 0-9 for the RIGHT SSD
//int 'm' is used to determine which digit to display
//value of 'm' corresponds to the digit to be displayed
//pins utilized: 2-8

if(m == 0){//display digit 0


digitalWrite(2, LOW);
for(int a = 5; a < 8; a++){
digitalWrite(a, LOW);
}
//LOW the adjacent digits 1 and 9
digitalWrite(8, HIGH);
}
if(m == 1){//display digit 1
digitalWrite(4, LOW);
//LOW the adjacent digits 0 and 2
digitalWrite(2, HIGH);
for(int a = 5; a < 9; a++){
digitalWrite(a, HIGH);
}
}
if(m == 2){//display digit 2
digitalWrite(2, LOW);
for(int a = 5; a < 9; a++){
digitalWrite(a, LOW);
}
//LOW the adjacent digits 1 and 3
digitalWrite(4, HIGH);
digitalWrite(7, HIGH);
}
if(m == 3){//display digit 3
digitalWrite(4, LOW);
digitalWrite(2, LOW);
digitalWrite(5, LOW);
//LOW the adjacent digits 2 and 4
digitalWrite(6, HIGH);
digitalWrite(7, HIGH);
}
if(m == 4){//display digit 4
digitalWrite(7, LOW);
digitalWrite(3, LOW);
//LOW the adjacent digits 3 and 5
digitalWrite(2, HIGH);
digitalWrite(5, HIGH);
digitalWrite(6, HIGH);
}
if(m == 5){//display digit 5
digitalWrite(2, LOW);
digitalWrite(5, LOW);
//LOW the adjacent digits 4 and 6
digitalWrite(3, HIGH);
digitalWrite(6, HIGH);
}
if(m == 6){//display digit 6
for(int a = 5; a < 9; a++){
digitalWrite(a, LOW);
}
//LOW the adjacent digits 5 and 7
digitalWrite(3, HIGH);
}
if(m == 7){//display digit 7
digitalWrite(3, LOW);
//LOW the adjacent digits 6 and 8
for(int a = 5; a < 9; a++){
digitalWrite(a, HIGH);
}
}
if(m == 8){//display digit 8
//LOW every segment to display digit eight
for(int a = 2; a < 9; a++){
digitalWrite(a, LOW);
}
}
if(m == 9){//display digit 9
digitalWrite(8, LOW);
//LOW the adjacent digit 0
digitalWrite(5, HIGH);
digitalWrite(6, HIGH);
}

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

for(x = 0; x < 10; x++){


//code to display digit 0-9 for the LEFT SSD
//incrementing count for 'x' 0-9
ones(x);//'ones' is for LEFT SSD
tens(y);//'tens' is for RIGHT SSD
delay(timer);//200ms delay

if(x==9 && y!=9){


//conditions for 'tens' to increment each time 'ones' reaches 9
x=-1;//resets 'x' to -1 each time it reaches 9
ones(0);//resets 'ones' SSD to zero
y++;//increment 'tens' by 1
tens(y);//display new value of 'tens'
}
else if(x==9 && y==9){
//code to display 99 at the end
x=10;//sets 'x' to 10 to end the function
ones(9);
tens(9);
}

void loop (){//main bulk of the code for problem#1


//set variables for our button readings
bool buttonstate1 = digitalRead(button1);
bool buttonstate2 = digitalRead(button2);
bool buttonstate3 = digitalRead(button3);
bool buttonstate4 = digitalRead(button4);

if(buttonstate1 == LOW){//for button 1


//program to display digits 10,20,30,40 ... 90

for(y = 0; y < 10; y++){


//counts 1-9 for 'y'
tens(y);//function to display 0-9 on the 'tens', dictated by 'y'
delay(timer);//500ms delay
}
delay(timer);//500ms delay
y=0;//resets 'y' to zero after the counting
}

if(buttonstate2 == LOW){//for button2


//program to display digits 00 to 99

scenario2();//calls for function scenario2()


delay(timer);//500ms delay
ON();//turns ON all segments
x=0;//resets 'x' and 'y' to 0
y=0;
}

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);
}

else if(x==0 && y==0){


//this is to set the default display to '00'
//calls for function zero() to display to '00'
//each button command rnds with reseting 'x' & 'y' to 0 in order to display the
default '00'
zero();
}

-----------------------------------------------------------------------------------
------------

Problem#2

//this is for common ANODE config


int button1 = A1;//sets variable for our analog pins
int button2 = A2;
int button3 = A3;
int button4 = A4;

int timer = 500;//500ms delay


int timer2 = 200;//200ms delay

//'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

//pins 2-8 for the right SSD


//pins 0,1,9-13 for the left SSD
for (int pin = 0; pin < 14; pin++){
//digital pins for OUTPUT
pinMode(pin, OUTPUT);
}

//analog pins for INPUT


pinMode(button1, INPUT_PULLUP);//A1
pinMode(button2, INPUT_PULLUP);//A2
pinMode(button3, INPUT_PULLUP);//A3
pinMode(button4, INPUT_PULLUP);//A4

void ones(int n){


//this is the function to diplay digit 0-9 for the RIGHT SSD
//int 'n' is used to determine which digit to display
//value of 'n' corresponds to the digit to be displayed
//pins utilized: 0-1 & 9-13

if(n == 0){//display digit 0


digitalWrite(0, LOW);
for(int a = 10; a < 13; a++){
digitalWrite(a, LOW);
}//LOW the adjacent digits 1 and 9
digitalWrite(13, HIGH);
}
if(n == 1){//display digit 1
digitalWrite(9, LOW);
//LOW the adjacent digits 0 and 2
digitalWrite(0, HIGH);
for(int a = 10; a < 14; a++){
digitalWrite(a, HIGH);
}
}
if(n == 2){//display digit 2
digitalWrite(0, LOW);
for(int a = 10; a < 14; a++){
digitalWrite(a, LOW);
}
//LOW the adjacent digits 1 and 3
digitalWrite(9, HIGH);
digitalWrite(12, HIGH);
}
if(n == 3){//display digit 3
digitalWrite(9, LOW);
digitalWrite(0, LOW);
digitalWrite(10, LOW);
//LOW the adjacent digits 2 and 4
digitalWrite(11, HIGH);
digitalWrite(12, HIGH);
}
if(n == 4){//display digit 4
digitalWrite(12, LOW);
digitalWrite(1, LOW);
//LOW the adjacent digits 3 and 5
digitalWrite(0, HIGH);
digitalWrite(10, HIGH);
digitalWrite(11, HIGH);
}
if(n == 5){//display digit 5
digitalWrite(0, LOW);
digitalWrite(10, LOW);
//LOW the adjacent digits 4 and 6
digitalWrite(1, HIGH);
digitalWrite(11, HIGH);
}
if(n == 6){//display digit 6
for(int a = 10; a < 14; a++){
digitalWrite(a, LOW);
}
//LOW the adjacent digits 5 and 7
digitalWrite(1, HIGH);
}
if(n == 7){//display digit 7
digitalWrite(1, LOW);
//LOW the adjacent digits 6 and 8
for(int a = 10; a < 14; a++){
digitalWrite(a, HIGH);
}
}
if(n == 8){//display digit 8
//LOW every segment to display digit 8
digitalWrite(0, LOW);
digitalWrite(1, LOW);
for(int a = 9; a < 14; a++){
digitalWrite(a, LOW);
}
}
if(n == 9){//display digit 9
digitalWrite(13, LOW);
//LOW the adjacent digit 0
digitalWrite(10, HIGH);
digitalWrite(11, HIGH);
}

void tens(int m){


//function to diplay digit 0-9 for the RIGHT SSD
//int 'm' is used to determine which digit to display
//value of 'm' corresponds to the digit to be displayed
//pins utilized: 2-8

if(m == 0){//display digit 0


digitalWrite(2, LOW);
for(int a = 5; a < 8; a++){
digitalWrite(a, LOW);
}
//LOW the adjacent digits 1 and 9
digitalWrite(8, HIGH);
}
if(m == 1){//display digit 1
digitalWrite(4, LOW);
//LOW the adjacent digits 0 and 2
digitalWrite(2, HIGH);
for(int a = 5; a < 9; a++){
digitalWrite(a, HIGH);
}
}
if(m == 2){//display digit 2
digitalWrite(2, LOW);
for(int a = 5; a < 9; a++){
digitalWrite(a, LOW);
}
//LOW the adjacent digits 1 and 3
digitalWrite(4, HIGH);
digitalWrite(7, HIGH);
}
if(m == 3){//display digit 3
digitalWrite(4, LOW);
digitalWrite(2, LOW);
digitalWrite(5, LOW);
//LOW the adjacent digits 2 and 4
digitalWrite(6, HIGH);
digitalWrite(7, HIGH);
}
if(m == 4){//display digit 4
digitalWrite(7, LOW);
digitalWrite(3, LOW);
//LOW the adjacent digits 3 and 5
digitalWrite(2, HIGH);
digitalWrite(5, HIGH);
digitalWrite(6, HIGH);
}
if(m == 5){//display digit 5
digitalWrite(2, LOW);
digitalWrite(5, LOW);
//LOW the adjacent digits 4 and 6
digitalWrite(3, HIGH);
digitalWrite(6, HIGH);
}
if(m == 6){//display digit 6
for(int a = 5; a < 9; a++){
digitalWrite(a, LOW);
}
//LOW the adjacent digits 5 and 7
digitalWrite(3, HIGH);
}
if(m == 7){//display digit 7
digitalWrite(3, LOW);
//LOW the adjacent digits 6 and 8
for(int a = 5; a < 9; a++){
digitalWrite(a, HIGH);
}
}
if(m == 8){//display digit 8
//LOW every segment to display digit eight
for(int a = 2; a < 9; a++){
digitalWrite(a, LOW);
}
}
if(m == 9){//display digit 9
digitalWrite(8, LOW);
//LOW the adjacent digit 0
digitalWrite(5, HIGH);
digitalWrite(6, HIGH);
}

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

for(x = 0; x < 10; x++){


//code to display digit 0-9 for the LEFT SSD
//incrementing count for 'x' 0-9
ones(x);//'ones' is for LEFT SSD
tens(y);//'tens' is for RIGHT SSD
delay(timer);//500ms delay

if(x==9 && y!=9){


//conditions for 'tens' to increment each time 'ones' reaches 9
x=-1;//resets 'x' to -1 each time it reaches 9
ones(0);//resets 'ones' SSD to zero
y++;//increment 'tens' by 1
tens(y);//display new value of 'tens'
}
else if(x==9 && y==9){
//code to display 99 at the end
x=10;//sets 'x' to 10 to end the function
ones(9);
tens(9);
}

}
}

void scenario3(int y3){


//function to display 0-to9 on 'ones' & 9-to-0 on 'tens' simultaneously

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(buttonstate1 == LOW){//0-to-9 on ones


for(x = 0; x < 10; x++){
//counts from 0-9 for 'x'
ones(x);//display digit 'ones' equal to value of 'x'
delay(timer);//500ms delay
}
delay(timer);//500ms delay
x=0;//resets 'x' value to 0
}

if(buttonstate2 == LOW){//for button2


//program to display digits 00 to 99

scenario2();//calls for function scenario2()


x=0;//resets 'x' and 'y' to 0
y=0;
}

if(buttonstate3 == LOW){//9-to-0 & 0-to-9


for(int d = 0; d < 10; d++){
//counts 0-9 for 'd'
scenario3(d);//calls for function scenario3()
delay(timer);//delay 500ms
x=0;//resets value of 'x' & 'y' to 0
y=0;
}
}

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();

x=0;//resets value of 'x' & 'y' to 0


y=0;
}

else if(x==0 && y==0){


//this is to set the default display to '00'
//calls for function zero() to display to '00'
//each button command rnds with reseting 'x' & 'y' to 0 in order to display the
default '00'
zero();
}

You might also like