Controlling display without a timer library

I have a program that is doing everything I need it to be doing, but it is using a timer library and I am not supposed to be using it. Can anyone help me use break, delay, or interrupt type functions to display numbers for the serial port and have them stay up? Pictures of my schematic are below.

#include "Timer.h" //include timer library
Timer t; // craete a timer object
long number = 0; //declear the variables
int first_digit = 0;
int second_digit = 0;
int third_digit = 0;
int fourth_digit = 0;
int timer_event = 0;
int CA_1 = 12;
int CA_2 = 11;
int CA_3 = 10;
int CA_4 = 9;
int clk = 6;
int latch = 5;
int data = 4;
int count = 0;
int digits[4] ;
int CAS[4] = {12, 11, 10, 9};
byte numbers[10] {B11111100, B01100000, B11011010, B11110010, B01100110, B10110110, B10111110, B11100000, B11111110, B11110110};
//byte combinations for each number 0-9
void setup() {
 Serial.begin(9600); //serial start and pin config
 pinMode(CA_1, OUTPUT);
 pinMode(CA_2, OUTPUT);
 pinMode(CA_3, OUTPUT);
 pinMode(CA_4, OUTPUT);
 pinMode(clk, OUTPUT);
 pinMode(latch, OUTPUT);
 pinMode(data, OUTPUT);
 digitalWrite(CA_1, HIGH);
 digitalWrite(CA_2, HIGH);
 digitalWrite(CA_3, HIGH);
 digitalWrite(CA_4, HIGH);
 Serial.println("please Enter a number from 0 to 9999");
}

void loop() {
 t.update(); //timer update
 if (Serial.available()) { // read from serial
   t.stop(timer_event); //stop timer if anythign to read
   cathode_high(); // blank the screen
   String s = Serial.readString(); //read the serail value
   number = (long)s.toInt(); //convert it to int
   if (number > 9999) { //check the number is 0-9999
     Serial.println("Please Enter Number Between 0 - 9999");
   } else {
     break_number(number);
     timer_event = t.every(1, display_number); // start timer again
   }
 }
}

void break_number(long num) { // seperate the input number into 4 single digits

 first_digit = num / 1000;
 digits[0] = first_digit;

 int first_left = num - (first_digit * 1000);
 second_digit = first_left / 100;
 digits[1] = second_digit;
 int second_left = first_left - (second_digit * 100);
 third_digit = second_left / 10;
 digits[2] = third_digit;
 fourth_digit = second_left - (third_digit * 10);
 digits[3] = fourth_digit;
}

void display_number() { //scanning

 cathode_high(); //black screen
 digitalWrite(latch, LOW); //put the shift register to read
 shiftOut(data, clk, LSBFIRST, numbers[digits[count]]); //send the data
 digitalWrite(CAS[count], LOW); //turn on the relevent digit
 digitalWrite(latch, HIGH); //put the shift register to write mode
 count++; //count up the digit
 if (count == 4) { // keep the count between 0-3
   count = 0;
 }
}

void cathode_high() { //turn off all 4 digits
 digitalWrite(CA_1, HIGH);
 digitalWrite(CA_2, HIGH);
 digitalWrite(CA_3, HIGH);
 digitalWrite(CA_4, HIGH);
}

You can manage timing using millis() as illustrated in Several Things at a Time.

You may also like to look at Using millis() for timing. A beginners guide

...R

Yeah, but I can't just blow out the timer library commands and just replace them with millis() commands, because then my segment display doesn't read the integers correctly. Everything in my code is based off these timer library commands, and I cant get back to where I need to be where the library isnt effecting everything not being present.

saulgoodman:
Yeah, but I can't just blow out the timer library commands and just replace them with millis() commands,

You are correct. You will need to do some work.

That is probably why your Teacher does not want you to use the Timer library.

...R

Hi,
Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Thanks.. Tom.... :slight_smile:

TomGeorge,

I have done what you requested. Thanks in advance for any help on this.

saulgoodman:
TomGeorge,

I have done what you requested. Thanks in advance for any help on this.

Pictures of my schematic are below.

Its a picture, not a labeled schematic, you have produced a layout diagram not a schematic.
Tom... :slight_smile:

saulgoodman:
I have done what you requested. Thanks in advance for any help on this.

Please don't add things to older Posts. Just put the new material in your next Reply so that someone reading the Thread from top to bottom sees a logical progression.

...R