Hey guys, I have a simple counter project, it works but when the circuit is closed the display goes blank and when the circuit reopens, it counts fine but flashes almost like a strobe.
I've included my code and a pic of the display, any suggestions are welcomed,
Thxs y'all
#include "LedControl.h"
#define plate 2 // set the pin on which plate or switch is to be conneced
#define reset 3 //set pin to reset counter
LedControl lc=LedControl(12,11,10,1);
unsigned long delaytime=250;
int count;
void setup() {
lc.shutdown(0,false);
lc.setIntensity(0,8);
lc.clearDisplay(0);
pinMode(plate,INPUT_PULLUP);
pinMode(reset,INPUT_PULLUP);
}
void loop()
{
if( digitalRead(plate)==0)
{
count++;
while(digitalRead(plate)==0);
}
if(digitalRead(reset)==0)
{
count=0;
while(digitalRead(reset)==0);
}
if(count>9999)
{
count=0;
}
disp(count);
}
void disp(int a)
{
int one, ten, hundred, thousand;
one=a%10;
ten=(a/10)%10;
hundred=(a/100)%10;
thousand=(a/1000)%10;
lc.setDigit(0,3,thousand,false);
lc.setDigit(0,2,hundred,false);
lc.setDigit(0,1,ten,false);
lc.setDigit(0,0,one,false);
lc.clearDisplay(0);
delay(delaytime);
}
