For a project I need to create a binary counter that uses one button to count a desired number and then another button to display that number in binary through 4 leds.
So far I am able to compile without errors but my program does nothing. I wrote a serial output to test if the counter was working and nothing is displayed. Any help would be awesome.
int ledPin[] = {7,8,9,10};
const int countbuttonPin = 2;
const int startbuttonPin = 3;
int count = 0;
int countbuttonState = 0;
int lastbuttonState = 0;
int startlastbuttonState = 0;
int startbuttonState = 0;
void setup()
{
pinMode(countbuttonPin, INPUT);
pinMode(startbuttonPin, INPUT);
Serial.begin(9600);
for (int i =0;i<4;i++)
{
pinMode(ledPin[i], OUTPUT);
}
}
void loop(){
countbuttonState = digitalRead(countbuttonPin);
if (countbuttonState != lastbuttonState){
if (countbuttonState == HIGH) {
count++;
Serial.println(count);
if (count > 15) {
count = 0;
}
}
}
}
void startLoop(){
startbuttonState = digitalRead(startbuttonPin);
if (startbuttonState != startlastbuttonState){
if (startbuttonState == HIGH)
{
displayBinary(count);
}
}
}
void displayBinary(byte numToShow)
{
for (int i =0;i<4;i++)
{
if (bitRead(numToShow, i)==1)
{
digitalWrite(ledPin[i], HIGH);
}
else
{
digitalWrite(ledPin[i], LOW);
}
}
}