Hackster is hosting Hackster Holidays, Ep. 6: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Monday!Stream Hackster Holidays, Ep. 6 on Monday!
Maha Raafat
Published © GPL3+

4 bit up/ down counter using 1sheeld

4 bit up down counter that represent every count as binary number on LEDs and display its decimal representation on LCD shield.

IntermediateFull instructions provided7,829
4 bit up/ down counter using 1sheeld

Things used in this project

Schematics

Counter_schema

Counter_Schema.fzz

Code

Counter.ino

C/C++
/* 
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);
   
 
 } 
 }
 }

Credits

Maha Raafat

Maha Raafat

2 projects • 48 followers

Comments