#include "ArduinoTrace.h"
int ledPin[] = {7,8,9,10};
int ledPin1[] = {3,4};
const int buttonPin=2;
const int buttonPin1=0;
bool buttonPresent=HIGH,buttonLast=HIGH;
bool button1Present=HIGH,button1Last=HIGH;
int counter;
int counter1;
void setup()
{
Serial.begin(9600);
for (int i =0;i<4;i++)
{
pinMode(ledPin[i], OUTPUT);
pinMode(buttonPin, INPUT_PULLUP);
}
displayBinary(counter);
for (int i =0;i<4;i++)
{
pinMode(ledPin1[i], OUTPUT);
pinMode(buttonPin1, INPUT_PULLUP);
}
displayBinary1(counter1);
}
void loop()
{
Task1();
Task2();
}
bool Task1()
{
static unsigned long previousMillis=0;
if((millis()-previousMillis)>100)
{
buttonLast=buttonPresent;
buttonPresent=digitalRead(buttonPin);
DUMP(buttonPresent);
if(buttonPresent==LOW && buttonLast==HIGH)
{
if(counter<15)
{
counter++;
}
else
{
counter=0;
}
displayBinary(counter);
}
previousMillis=millis();
}
}
bool Task2()
{
static unsigned long previousMillis=0;
if((millis()-previousMillis)>100)
{
button1Last=button1Present;
button1Present=digitalRead(buttonPin1);
DUMP(button1Present);
if(button1Present==LOW && button1Last==HIGH)
{
if(counter1<3)
{
counter1++;
}
else
{
counter1=0;
}
displayBinary1(counter1);
}
previousMillis=millis();
}
}
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);
}
}
}
void displayBinary1(byte numToShow1)
{
for (int i =0;i<4;i++)
{
if (bitRead(numToShow1, i)==1)
{
digitalWrite(ledPin1[i], HIGH);
}
else
{
digitalWrite(ledPin1[i], LOW);
}
}
}