0% found this document useful (0 votes)
79 views5 pages

Const Int Numeral

This document contains the code for a digital timer that counts up to 999 milliseconds. It defines variables for the run state, key presses, maximum value, number of digits, and current number being displayed. Segment and digit pins are initialized as outputs. The main loop increments the number every 1000ms if running, and multiplexes the display across three digits to show the hundreds, tens, and ones places. Buttons can pause/resume counting or reset to 0.

Uploaded by

Lm
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
79 views5 pages

Const Int Numeral

This document contains the code for a digital timer that counts up to 999 milliseconds. It defines variables for the run state, key presses, maximum value, number of digits, and current number being displayed. Segment and digit pins are initialized as outputs. The main loop increments the number every 1000ms if running, and multiplexes the display across three digits to show the hundreds, tens, and ones places. Buttons can pause/resume counting or reset to 0.

Uploaded by

Lm
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

const int numeral[10] = {

B00000101, //0

B10011111, //1

B00100110, //2

B00001110, //3

B10011100, //4

B01001100, //5

B11000100, //6

B00011111, //7

B00000100, //8

B00011100, //9

};

int runFlag = 0; //determines whether the device would run or pause

int switchKey = 0; //determines which key is active

const int maxValue = 999; //the timer would no longer run when this number is reached

const int numDigits = 3; //number of digits displayed by the timer

int number = 0; //number currently displayed by the timer

int incTime = 1000; //number of milliseconds between increments

unsigned long lastUpdate = 0;

boolean inputSwitch = LOW;

const int segPins[8] = { 7, 9, 8, 6, 5, 4, 3, 2};

const int digitPins[numDigits] = { 13, 12, 11};

//pin definitions

int displayOnes = 13;


int displayTens = 12;

int displayHundreds = 11;

int toggleSwitch = 10;

void setup() {

for(int i=0; i < 8; i++){

pinMode(segPins[i], OUTPUT); //set segment pins as output

for(int i=0; i < numDigits; i++){

pinMode(digitPins[i], OUTPUT); //set digit pins 13 to 11 as output

pinMode(toggleSwitch, INPUT);

Serial.begin(9600);

void reset(){ //reset function

runFlag = 0;

number = 0;

void loop(){

unsigned long timeElapsed = millis();

//The code will count down ever second that has passed

//regardless of the state of the runFlag

if (timeElapsed - lastUpdate > incTime){

//The number variable will not increment if the runFlag is zero


if(runFlag != 0){

number++;

lastUpdate = timeElapsed;

//When number reaches beyond maxValue, counting will stop

//but will still display the value of the number

if(number >= maxValue){

int runFlag = 0;

int hund = number / 100;

int tens = ( (number / 10) % 10);

int ones = number % 10;

//Multiplexing Code

for(int i = 0; i < 2; i++){

//Ones Digit

if(i == 0)

switchKey = 1; //for the Play/Pause switch

boolean inputSwitch = digitalRead(toggleSwitch);

//When the Pause/Play switch is pressed

if(switchKey == 1 && inputSwitch){


int runFlag = 1;

//display code for ones digit

//[incomplete]

delay(1);

//Tens Digit

else if(i == 1)

switchKey = 0;

//display code for tens digit

//[incomplete]

delay(1);

//Hundreds Digit

switchKey = 2; //for the Reset switch

boolean inputSwitch = digitalRead(toggleSwitch);

//When the Reset switch is pressed

if(switchKey == 2 && inputSwitch ){

reset();

}
//display code for hundreds digit

delay(1);

You might also like