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