Verizon Fios Tech Support

  • Subscribe to our RSS feed.
  • Twitter
  • StumbleUpon
  • Reddit
  • Facebook
  • Digg

Monday, 5 November 2012

Arduino and 7-segment LED counter driven by two tactile switches

Posted on 14:16 by Unknown
I have posted on YouTube a couple of videos about a project I made with the Arduino prototype board. The circuit uses an Arduino mini and has a simple gear counter based on a 7-segment LED and controlled by two switches. It can be mounted on your bike and used for example to visualize which gear you are in at any time.

If you are interested in the schematics I can send you the PCB Artist version by email. The Arduino code is instead available below.

/*
Blink

Turns on an LED on for one second, then off for one second, repeatedly.

The circuit:
* LED connected from digital pin 13 to ground.

* Note: On most Arduino boards, there is already an LED on the board
connected to pin 13, so you don't need any extra components for this example.


Created 1 June 2005
By David Cuartielles

http://arduino.cc/en/Tutorial/Blink

based on an orginal by H. Barragan for the Wiring i/o board

*/

#define BUTTON_DOWN 10
#define BUTTON_UP 12

int ledPinA = 6; // LED connected to digital pin 3
int ledPinB = 9; // LED connected to digital pin 4
int ledPinC = 4; // LED connected to digital pin 5
int ledPinD = 3; // LED connected to digital pin 6
int ledPinE = 2; // LED connected to digital pin 7
int ledPinF = 7; // LED connected to digital pin 8
int ledPinG = 8; // LED connected to digital pin 9
int ledPinDP = 5; // LED connected to digital pin 10

int val_down = 0;
int old_val_down = 0;
int val_up = 0;
int old_val_up = 0;
int state = 0;
int gear = 1;

// The setup() method runs once, when the sketch starts

void setup() {
pinMode(BUTTON_DOWN, INPUT);
pinMode(BUTTON_UP, INPUT);

// initialize the digital pin as an output:
pinMode(ledPinA, OUTPUT);
pinMode(ledPinB, OUTPUT);
pinMode(ledPinC, OUTPUT);
pinMode(ledPinD, OUTPUT);
pinMode(ledPinE, OUTPUT);
pinMode(ledPinF, OUTPUT);
pinMode(ledPinG, OUTPUT);
pinMode(ledPinDP, OUTPUT);

// initialize serial communication:
Serial.begin(9600);
}

void led0()
{
digitalWrite(ledPinA, LOW);
digitalWrite(ledPinB, LOW);
digitalWrite(ledPinC, LOW);
digitalWrite(ledPinD, LOW);
digitalWrite(ledPinE, LOW);
digitalWrite(ledPinF, LOW);
digitalWrite(ledPinG, HIGH);
digitalWrite(ledPinDP, HIGH);
}

void led1()
{
digitalWrite(ledPinA, HIGH);
digitalWrite(ledPinB, LOW);
digitalWrite(ledPinC, LOW);
digitalWrite(ledPinD, HIGH);
digitalWrite(ledPinE, HIGH);
digitalWrite(ledPinF, HIGH);
digitalWrite(ledPinG, HIGH);
digitalWrite(ledPinDP, HIGH);
}

void led2()
{
digitalWrite(ledPinA, LOW);
digitalWrite(ledPinB, LOW);
digitalWrite(ledPinC, HIGH);
digitalWrite(ledPinD, LOW);
digitalWrite(ledPinE, LOW);
digitalWrite(ledPinF, HIGH);
digitalWrite(ledPinG, LOW);
digitalWrite(ledPinDP, HIGH);
}

void led3()
{
digitalWrite(ledPinA, LOW);
digitalWrite(ledPinB, LOW);
digitalWrite(ledPinC, LOW);
digitalWrite(ledPinD, LOW);
digitalWrite(ledPinE, HIGH);
digitalWrite(ledPinF, HIGH);
digitalWrite(ledPinG, LOW);
digitalWrite(ledPinDP, HIGH);
}

void led4()
{
digitalWrite(ledPinA, HIGH);
digitalWrite(ledPinB, LOW);
digitalWrite(ledPinC, LOW);
digitalWrite(ledPinD, HIGH);
digitalWrite(ledPinE, HIGH);
digitalWrite(ledPinF, LOW);
digitalWrite(ledPinG, LOW);
digitalWrite(ledPinDP, HIGH);
}

void led5()
{
digitalWrite(ledPinA, LOW);
digitalWrite(ledPinB, HIGH);
digitalWrite(ledPinC, LOW);
digitalWrite(ledPinD, LOW);
digitalWrite(ledPinE, HIGH);
digitalWrite(ledPinF, LOW);
digitalWrite(ledPinG, LOW);
digitalWrite(ledPinDP, HIGH);
}

void led6()
{
digitalWrite(ledPinA, LOW);
digitalWrite(ledPinB, HIGH);
digitalWrite(ledPinC, LOW);
digitalWrite(ledPinD, LOW);
digitalWrite(ledPinE, LOW);
digitalWrite(ledPinF, LOW);
digitalWrite(ledPinG, LOW);
digitalWrite(ledPinDP, HIGH);
}

void led7()
{
digitalWrite(ledPinA, LOW);
digitalWrite(ledPinB, LOW);
digitalWrite(ledPinC, LOW);
digitalWrite(ledPinD, HIGH);
digitalWrite(ledPinE, HIGH);
digitalWrite(ledPinF, HIGH);
digitalWrite(ledPinG, HIGH);
digitalWrite(ledPinDP, HIGH);
}

void led8()
{
digitalWrite(ledPinA, LOW);
digitalWrite(ledPinB, LOW);
digitalWrite(ledPinC, LOW);
digitalWrite(ledPinD, LOW);
digitalWrite(ledPinE, LOW);
digitalWrite(ledPinF, LOW);
digitalWrite(ledPinG, LOW);
digitalWrite(ledPinDP, HIGH);
}

void led9()
{
digitalWrite(ledPinA, LOW);
digitalWrite(ledPinB, LOW);
digitalWrite(ledPinC, LOW);
digitalWrite(ledPinD, LOW);
digitalWrite(ledPinE, HIGH);
digitalWrite(ledPinF, LOW);
digitalWrite(ledPinG, LOW);
digitalWrite(ledPinDP, HIGH);
}

void ledDP()
{
digitalWrite(ledPinA, HIGH);
digitalWrite(ledPinB, HIGH);
digitalWrite(ledPinC, HIGH);
digitalWrite(ledPinD, HIGH);
digitalWrite(ledPinE, HIGH);
digitalWrite(ledPinF, HIGH);
digitalWrite(ledPinG, HIGH);
digitalWrite(ledPinDP, LOW);
}

void setLed(int number)
{
switch (number) {
case 0:
ledDP();
break;
case 1:
led1();
break;
case 2:
led2();
break;
case 3:
led3();
break;
case 4:
led4();
break;
case 5:
led5();
break;
case 6:
led6();
break;
case 7:
led7();
break;
case 8:
led8();
break;
case 9:
led9();
break;
}
}

// the loop() method runs over and over again,
// as long as the Arduino has power

void oldloop()
{
ledDP();
delay(1000); // wait for a second
led0();
delay(1000); // wait for a second
led1();
delay(1000); // wait for a second
led2();
delay(1000); // wait for a second
led3();
delay(1000); // wait for a second
led4();
delay(1000); // wait for a second
led5();
delay(1000); // wait for a second
led6();
delay(1000); // wait for a second
led7();
delay(1000); // wait for a second
led8();
delay(1000); // wait for a second
led9();
delay(1000); // wait for a second
}

void loop()
{
val_up = digitalRead(BUTTON_UP);
if ((val_up == HIGH) && (old_val_up == LOW)) {
gear += 1;
Serial.print("gear number: ");
Serial.println(gear, DEC);
delay(100);
}
old_val_up = val_up;

val_down = digitalRead(BUTTON_DOWN);
if ((val_down == HIGH) && (old_val_down == LOW)) {
gear -= 1;
Serial.print("gear number: ");
Serial.println(gear, DEC);
delay(100);
}
old_val_down = val_down;

if (gear >= 6) {
gear = 6;
}
if (gear <= 1) {
gear = 1;
}

setLed(gear);
}

Email ThisBlogThis!Share to XShare to FacebookShare to Pinterest
Posted in Arduino | No comments
Newer Post Older Post Home

0 comments:

Post a Comment

Subscribe to: Post Comments (Atom)

Popular Posts

  • How to compile busybox with Android NDK for both ARM and x86 architectures
    I was looking for a way to run busybox on a Motorola RAZRi with an x86 Intel Atom processor but I couldn't find any Android app from th...
  • Security and Trust when Everything has a Computer In It
    Security and Trust when Everything has a Computer In It Recently, Panic Software announced that they had opened up an HDMI display adapter ...
  • Sony Cyber-shot DSC-HX200V 18.2 MP 30 x High Zoom GPS Digital Camera - BLACK
    Sony Cyber-shot DSC-HX200V 18.2 MP 30 x High Zoom GPS Digital Camera - BLACK Blogger Opportunity Giveaway from June 17 to  July 12 Come and ...
  • Free Blogger Opp – Timjan Design Malachite 5/1
    Here comes another Visionary Bri blogger opportunity. Sign up now for the Timjan Bloomers Giveaway. Our sponsor, Timjan Design , has offered...
  • Hackers that solve problems...
    The nation and the world at large are struggling to come to grips with the fact that we are now more than ever vulnerable in our daily lives...
  • How to build Python-4-Android for the ARM Neon
    Currently the Py4A project does not compile for the ARM Neon architecture. If you try to run ndk-build on the project by setting the APP_A...
  • How to Cross-Compile libiconv for Android
    If your legacy C/C++ code includes <iconv.h> to convert the encoding of characters from one coded character set to another, and you ne...
  • How to compile libogg for Android
    To compile libogg for Android, you just need to create an appropriate jni/Android.mk makefile with the minimum set of files and options need...
  • Problems with new version of rpmbuild
    The Problem With the new version of rpmbuild installed on CentOS 6.x, if you try to use an old RPM spec file, you will get an error like the...
  • Sony Cyber-shot DSC-HX200V Giveaway
    Hosted by: NYSavingSpecials and Your Fashion Resource ,  Co-hosted by Melissa Say What? ,  Barbara's Beat ,  LibbysLibrary ,  Confessio...

Categories

  • amazon
  • amazon.com
  • Android
  • Apple
  • Arduino
  • ARM
  • baby
  • baby reviews
  • back to school
  • beef jerky
  • bicycle. wagon
  • bike
  • Blanket Buddies
  • blogging
  • Blogging with The Tate's
  • books
  • busybox
  • camera
  • camera giveaway
  • candle giveaway
  • candles
  • CaseApp
  • CentOS
  • coffee
  • david haskell
  • dermorganic
  • DHCP
  • digital camera
  • events
  • Florida
  • Fortran
  • free blogger giveaway
  • free blogger sign-ups
  • full of flavor
  • giveaways
  • GNU
  • GPON
  • hair care
  • happy husband
  • Hot tea
  • Husband and Wife perspective
  • iMac
  • ipad
  • iphone
  • iphone case
  • iphone case review
  • Javascript
  • Keurig Coffee Review
  • Keurig Review
  • Kindle
  • ksh
  • LifeProof iPhone Case Review
  • Linux
  • MacOSX
  • Malachite Bloomers
  • man and women perspective
  • meat
  • Mips
  • Network
  • Pretzel Crisps
  • Pretzels
  • product reviews
  • products
  • Python
  • Router
  • scentsy
  • scentsy candles
  • school
  • scooter
  • security system
  • skin care
  • snacks
  • sony
  • sony cyber-shot
  • Stuff Animal
  • suface pro
  • Summer
  • summer fun
  • surface pro giveaway
  • techno thriller
  • Timjan Design
  • too much information
  • UNIX
  • vegan
  • vegan products
  • verizon
  • verizon fios
  • VitaminsBaby
  • waterproof case
  • Windows
  • x86
  • yummy

Blog Archive

  • ►  2013 (41)
    • ►  November (2)
    • ►  October (2)
    • ►  September (3)
    • ►  August (3)
    • ►  July (2)
    • ►  June (2)
    • ►  May (6)
    • ►  April (8)
    • ►  March (2)
    • ►  February (5)
    • ►  January (6)
  • ▼  2012 (17)
    • ►  December (3)
    • ▼  November (4)
      • Automatic Entity Recognition Identifying Antennas ...
      • LifeProof iPhone Case Review
      • Python For Android (Py4A)
      • Arduino and 7-segment LED counter driven by two ta...
    • ►  October (8)
    • ►  July (1)
    • ►  June (1)
Powered by Blogger.

About Me

Unknown
View my complete profile