Hi guys, im new to coding and i am currently doing a school project where i need to get a four digit common anode seven segment display screen to show a random number once the switch is pressed and for the number to only change once the switch is pressed. I currently have the display wired to the arduino uno board with the switch also wired to the same pin (pin 2) as one of the digit pins. The problem at the moment is that whenever the switch is pressed it will display the random number but it will immediately disappear, making it very hard to read. Any help would be much appreciated
Here is the code that i have at the moment
#include "SevSeg.h"
long randNumber;
SevSeg sevseg; //Initiate a seven segment controller object
How is the switch wired ? Between pin 2 and + or between pin 2 and Ground ?
You have 2 variables which are never changed:
go_by_switch
last_input_value
What did you mean here ?
once the switch is pressed and for the number to only change once the switch is pressed.
You need to distinguish between "is pressed" and "becomes pressed". The loo() function could iterate a few thosand times while a switch IS pressed, though on only of those iterations will the switch change from not pressed to pressed (BECOME pressed).
6v6gt:
How is the switch wired ? Between pin 2 and + or between pin 2 and Ground ?
You have 2 variables which are never changed:
go_by_switch
last_input_value
What did you mean here ?
The display pins are all wired to pins 2-13,
i used different example codes to create what i have, so im not really sure why they are there but the program wasnt running without them
randNumber = random(9999);{
sevseg.setNumber(randNumber, 3);
sevseg.refreshDisplay(); // Must run repeatedly
delay(1000);}
You display the random number, then you clear the display.
Try moving-sevseg.refreshDisplay();
to above randNumber=random(9999);{
ie switch detected, clear display, generate random number then display.
G
I have tried changing these around but it had no effect