#include "ArduinoTrace.h"
int ledPin[] = {7,8,9,10};
int ledPin1[] = {12, 13};
const int buttonPin=2;
const int buttonPin1=4;
bool buttonPresent=HIGH,buttonLast=HIGH;
bool buttonPresent1=HIGH,buttonLast1=HIGH;
int counter;
int counter1;
void setup()
{
Serial.begin(9600);
for (int i =0;i<4;i++)
{
pinMode(ledPin[i], OUTPUT);
}
pinMode(ledPin1[0], OUTPUT);
pinMode(ledPin1[1], OUTPUT);
pinMode(buttonPin, INPUT_PULLUP);
pinMode(buttonPin1, INPUT_PULLUP);
}
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, false);
}
previousMillis=millis();
}
}
bool Task2()
{
static unsigned long previousMillis1=0;
if((millis()-previousMillis1)>100)
{
buttonLast1=buttonPresent1;
buttonPresent1=digitalRead(buttonPin1);
//DUMP(buttonPresent1);
if(buttonPresent1==LOW && buttonLast1==HIGH)
{
if(counter1<3)
{
counter1++;
}
else
{
counter1=0;
}
displayBinary(counter1, true);
}
previousMillis1=millis();
}
}
void displayBinary(byte numToShow, bool left)
{
DUMP(numToShow)
int ledCount;
int usedLeds[] = {7,8,9,10};
if (left)
{
ledCount = 2;
usedLeds[0] = 12;
usedLeds[1] = 13;
}
else
{
ledCount = 4;
}
for (int i =0;i<ledCount;i++)
{
if (bitRead(numToShow, i)==1)
{
digitalWrite(usedLeds[i], HIGH);
}
else
{
digitalWrite(usedLeds[i], LOW);
}
}
}