I am trying to make a reaction game like Formula 1. When each led lights up in its own time and then they all go dim. When they go dim I count the time and display it on the display. The problem I am facing is that the display shows 6.6.6 and A.A.A and sometimes has all the lights on. Is this a normal issue? If so how do I solve it? The code I am using is as follows:
#include <SevSeg.h>
void nextState(); // Forward declaration of function
SevSeg sevseg; // Instantiate a seven segment object
uint8_t state = 0;
uint8_t numDigits;
const uint32_t INTERVAL_MS = 500;
void setup() {
// put your setup code here, to run once:
pinMode(2, OUTPUT);
pinMode(6, INPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
numDigits = 4;
byte digitPins[] = {7, 8, 9, 10};
byte segmentPins[] = {12, 13, 14, 15, 16, 17, 18, 19};
bool resistorsOnSegments = false; // 'false' means resistors are on digit pins
byte hardwareConfig = COMMON_ANODE; // See README.md for options
bool updateWithDelays = false; // Default 'false' is Recommended
bool leadingZeros = false; // Use 'true' if you'd like to keep the leading zeros
bool disableDecPoint = false;
bool stop = false;
sevseg.begin(hardwareConfig, numDigits, digitPins, segmentPins, resistorsOnSegments, updateWithDelays, leadingZeros, disableDecPoint);
sevseg.setBrightness(90); // Set brightness if needed
Serial.begin(9600); // Initialize serial communication
}
void loop() {
int count = 1;
bool stop = false;
sevseg.blank();
// put your main code here, to run repeatedly:
while (stop == false){
count = count + 1;
digitalWrite(count, HIGH);
delay(1000);
while (count == 5){
int time = random(1000, 5000);
delay(time);
while (count > 1){
digitalWrite(count, LOW);
count = count - 1;
}
int counts = 0;
while(digitalRead(6) == LOW){
counts = counts + 1;
delay(1);
}
float total = 0.000;
total = (float)counts / 1000;
int displayValue = total * 1000;
Serial.println(total+0.075, 3 );
int ds = round(total);
sevseg.setNumber(ds); // Display the calculated value
stop = true;
delay(5000);
sevseg.refreshDisplay();
}
}
}
Your code uses delays that hinder the use of the SevSeg.h library.
See the text below and visit the library's author website.
" Warning: Any calls to delay() will interfere with the display. Any delays introduced by other functions will produce undesirable effects on the display. If you need help getting away from delay() statements, I recommend the simple Blink Without Delay arduino example sketch."
How do I find this? My display is 5641AS, it came with the start kit. I searched online and it said CATHODE but when I put it in the CATHODE the screen stopped working. The screen works in the tests that came with the sevseg file, just doesn't work with this one.
"Stopped working" - when? If you connect the 7seg display and all the LEDs start illuminating, that is "not working" and when no LEDs are illuminating, that is "working."
The LEDs should only light when the sketch commands them.
If your 7seg device has the word "CATHODE" on it, it is common cathode. To connect a common cathode 7seg, you connect the 7seg COM pin(s) to ground and the other 7seg pins to Arduino pins.
@milima
I suggest you run, (using your project's pins), the example
SevSeg_Counter.ino from the SevSeg.h library.
This way you will see if your Hardware is correct.
The hardware is ok as I tested it, just the software is not working as it should be.
On the 7seg I see nothing, in the arduino the LEDs work as they should. The only thing that is not working is the screen.
The software is working exactly as it is being instructed. Use the Serial Monitor to show the present output to help resolve the hardware and software issue.
I am speechless! You are a life saviour. You just saved me hours and hours of pain and headaches. After a few adjustments to the code, it worked perfectly. I can't thank you enough