Pages: [1]   Go Down
Author Topic: Dual 7 segment counters with triggers for adding & subtracting from 00 to 99  (Read 971 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello,

I am working a project and I am trying to piece together a counter using my Uno. I have it wired 2-8 on segments A-G as so...

  -A-
|     |
F     B
|     |
  -G-
|     |
E     C
|     |
  -D-

A = pin2
B = pin3
C = pin4
D = pin5
E = pin6
F = pin7
G = pin8

Anyways, I have butchered the hell out of some code but closest thing I found was a snippet of code that would count down automatically and one that used a trigger but the display did not work no matter how I tried to trace the program. So I am here posting for some help. If you can lead me to a few snippets that work I would be grateful. If you can figure this idea out and help me with the code I'll send beer.smiley God knows I need one.
Thanks for reading this and I hope someone out there enjoys a few cold ones smiley

Domasi
Logged

Offline Offline
Faraday Member
**
Karma: 68
Posts: 2800
The last thing you did is where you should start looking.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I Googled "7 segment Arduino tutorial" and got this example.
It probably is close to what you want.

https://www.youtube.com/watch?v=WfdeGb0LUUY
http://www.hacktronics.com/Tutorials/arduino-and-7-segment-led.html
« Last Edit: February 13, 2013, 11:31:24 pm by LarryD » Logged

The way you have it in your schematic isn't the same as how you have it wired up! That goes for me too.

Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

That is close but it counts on it's own. I am looking for something that is triggered to increment or decrease by 1 for every signal sent to it.

:/
Logged

Sydney, Australia
Offline Offline
Edison Member
*
Karma: 33
Posts: 1284
Big things come in large packages
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

At the site in my signature block below there is code for a timer display that allows you to preset the value and then it counts down. You  may be able to use some of the code for our own purposes.
Logged

Arduino libraries http://arduinocode.codeplex.com
Parola hardware & library http://parola.codeplex.com

Canberra Australia
Offline Offline
God Member
*****
Karma: 11
Posts: 518
Hardcore Arduino
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Domasi,

this code will increment a 7Seg display from a blank display, to zero, then digits one through nine and back to blank display on the twelveth button press. Button connected to Arduino pin 12.

Connect Arduino pins as follows –

Pin  9          Segment       Decimal Point
      8                            A
      7                            B
      6                            C
      5                            D
      4                            E
      3                            F
      2                            G 

Code:
 
  // Code by Pedro147 Arduino Forum - Thanks to Grumpy Mike  http://www.thebox.myzen.co.uk/Tutorial/Arrays.html
 
  int pins [] = { 2, 3, 4, 5, 6, 7, 8, 9 };     // pin 9 allocated to DP but not used (first element of binary array in char elevenCode)
  int digit[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
  int switchPin = 12;                           // pushbutton attached to pin 12
  int buttonState = LOW;                        // initialise buttonState as LOW
  int counter = 0;                              // initialise counter as zero
  int timer1 = 100;                             // delay timer interval
  int timer = 1000;
 
   char elevenCode[] = {B00000000, B01111110, B00110000, B01101101, B01111001, B00110011, B01011011, B01011111, B01110000, B01111111, B01111011 };
  // Array element   #  No Display     0          1          2          3          4          5          6          7          8         9

   void setup()
  {
    for(int i = 0; i < 8; i++)                  // set digital pins as OUTPUTS
      pinMode(pins[i], OUTPUT);
      pinMode(switchPin, INPUT);                // sets pin 12 as pushbutton INPUT
  }
 
 
  void loop()
  {
    int newstate = digitalRead(switchPin);
    if (buttonState != newstate)                // has the state changed from 
                                                // HIGH to LOW or vice versa
 
    {                                         
   
      buttonState = newstate;
      if (newstate == LOW)                      // IF the button was pressed
        ++counter;                              // increment the counter by one
        delay(20);                              // delay to debounce
 
    }
 
   
    if(counter > 10)
      counter = 0;
     
     
    displayEleven(counter);
  }
 
 
  void displayEleven(int num)
  {
    int mask = 1;
    for(int i = 0; i < 8; i++)
    {
      if((mask & elevenCode[num]) == 0)
        digitalWrite(pins[i], LOW);
      else digitalWrite(pins[i], HIGH);
      mask = mask << 1;
    }
  }
 
 
                     




Logged


Pages: [1]   Go Up
Jump to: