/*
4 bit up down counter that represent every count as binary number on LEDs and display its decimal representation on LCD shield.
created by Maha Raafat
*/
#include <OneSheeld.h>
int count = 0;
void setup()
{
OneSheeld.begin();
pinMode(3,OUTPUT); // declare LED pins as output pins
pinMode(4,OUTPUT);
pinMode(5,OUTPUT);
pinMode(6,OUTPUT);
}
void loop()
{
if (GamePad.isOrangePressed()){
delay (10); // for debouncing
if (GamePad.isOrangePressed()){
count ++ ;
delay(200);
if((count % 2) > 0) {
digitalWrite(3, HIGH);
}
else {
digitalWrite(3, LOW);
}
if((count % 4) > 1) {
digitalWrite(4, HIGH);
}
else {
digitalWrite(4, LOW);
}
if((count % 8) > 3) {
digitalWrite(5, HIGH);
}
else {
digitalWrite(5, LOW);
}
if((count % 16) > 7) {
digitalWrite(6, HIGH);
}
else {
digitalWrite(6, LOW);
}
LCD.begin();
LCD.print (count);
OneSheeld.delay(100);
}
}
if (GamePad.isRedPressed()){
delay (10);
if (GamePad.isRedPressed()){
count -- ;
delay(200);
if((count % 2) > 0) {
digitalWrite(3, HIGH);
}
else {
digitalWrite(3, LOW);
}
if((count % 4) > 1) {
digitalWrite(4, HIGH);
}
else {
digitalWrite(4, LOW);
}
if((count % 8) > 3) {
digitalWrite(5, HIGH);
}
else {
digitalWrite(5, LOW);
}
if((count % 16) > 7) {
digitalWrite(6, HIGH);
}
else {
digitalWrite(6, LOW);
}
LCD.begin();
LCD.print (count);
OneSheeld.delay(100);
}
}
}
Comments