top of page
Search

Code Using 7 Segment Display

  • Writer: Christopher Pereyra
    Christopher Pereyra
  • May 27, 2021
  • 2 min read

I created a count down timer that starts with the push of a button.




Code


#include "simpletools.h" // Include simple tools


int n[]= {0b11100111, 0b10000100, 0b11010011,

0b11010110, 0b10110100, 0b01110110,

0b01110111, 0b11000100, 0b11110111,

0b11110110};

char const dir=2; // direction button

char const sel=1; // select button

int tp=0;

int op=0;


int main()

{


// Part 1: Selecting a time............................................................................................

set_directions(15,8, 0b11111111);//(high pin, low pin, 0bxxxxxxxx) make pin sinks or sources

pause(100);


while(tp<=6) // direction button values for tenths place are restricted from 0 to 6

{

set_outputs(15,8,n[tp]); // display inital number 0 on 7 segement display

pause(100);

if(input(dir)) // When direction button is pressed the values increase by 1

{

tp=tp+1;

if(tp>6)

{

tp=0;

} // restrict the value in tenths place from going higher than 6

set_outputs(15,8,n[tp]); // display number on 7 segment after each press

pause(100);

} //input(direction)

term_cmd(HOME);

term_cmd(CLS);

//print("Do you want to set a timer? \n\nTop button = cycles thru numbers \nBottom button = selects a number");

print("\nSelect number in tenths place:\n %d_",tp);

pause(100);

//------------------------------------------------------------------------------------------

if(input(sel)) // tenths place is locked in, will now select ones place

{

// print the info for tenths place so far


while(op<=9) // we will give the ones place a range of 0 to 9

{

set_outputs(15,8,n[op]); // display initial number

pause(100);

if(input(dir)) // direction button is pressed to change ones place values

{

op=op+1;

if(op>9)

{

op=0;

}

set_outputs(15,8,n[op]); // display number

pause(100);

} //input(direction)

if(input(sel))

{

char countdowntime=(tp*10)+ op;

term_cmd(HOME);

term_cmd(CLS);

print("Select number in ones place:\n _%d",op);

pause(100);

if(input(sel))

{

int n[]= {0b11100111, 0b10000100, 0b11010011,

0b11010110, 0b10110100, 0b01110110,

0b01110111, 0b11000100, 0b11110111,

0b11110110, };

int run=0;


set_directions(15,8, 0b11111111);//(high pin, low pin, 0bxxxxxxxx) make pin sinks or sources

pause(20);


for(int a=tp; a>=0; a=a-1)

{

for(int b=op; b>=0; b=b-1)

{

set_outputs(15,8, n[a]);

pause(500);

set_outputs(15,8, n[b]);

pause(250);

toggle(11);

pause(250);

term_cmd(HOME);

term_cmd(CLS);

print(" Countdown initiated \n time remaining %d%d",a,b);

pause(100);

}

tp=tp-1;

for(int a=tp; a>=0; a=a-1)

{

for(int b=9; b>=0; b=b-1)

{

set_outputs(15,8, n[a]);

pause(500);

set_outputs(15,8, n[b]);

pause(250);

toggle(11);

pause(250);

term_cmd(HOME);

term_cmd(CLS);

print(" Countdown initiated \n time remaining %d%d",a,b);

pause(100);

}

}// for (b)

}// for(a)

}// while(1)

}// int

}//while(op)

}// if input(sel)

}//while(tp)

}//int


 
 
 

Kommentit


Post: Blog2_Post

©2019 by Christopher Pereyra. Proudly created with Wix.com

bottom of page