1. Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.
    Dismiss Notice

(SOLVED)Code beat me again, 7 segment this time

Discussion in 'Arduino' started by fezder, Oct 16, 2015.

  1. fezder

    fezder Well-Known Member

    Joined:
    Dec 11, 2011
    Messages:
    1,665
    Likes:
    100
    Location:
    Mikkeli, Finland
    So, i managed to do this many years ago, BUT, now that i started doing again (nope, didn't take copy of that previously working code....)
    this for some reason won't work at least the way it should
    Basic 2-digit timer, but the trouble currently is that other digit won't go on, even though i'm quite sure i told it to do so. However, when i drive them as separatery, i mean as 1 digit, they work as intened. What bothers me is that they won't work as multiplexing/synchronously, if you get my meaning. those codes all over the internet didn't help either, didn't find that thing that causes this, there is blanking supposedly between digits. But, hopefully you guys could shep some light....port manipulation might be overkill, but i recently started doing codes with it, shoudln't be issue....
    and, i use 4543 bcd-7 segment driver, if that makes any difference
    Code (C):

    int const t =100;
    int count;


    void setup()
    {
      //Serial.begin(9600);       //debugging
      DDRD = DDRD | B11111100;    //Data direction register D, 0=input, 1=output: pins 4-7 output
      DDRB = B00000011;           // 8, 9 outputs
    }

    void loop()
    {
    PORTD = B00000000;                 //display 0
    PORTB = B00000001;                 //turn on digit 1
    picknumber(count / 1 % 10);      
    delayMicroseconds(10);          
    PORTD = B00000000;                  //display 0
    PORTB = B00000010;                  //turn on digit 2
    picknumber(count / 10 % 10);
    delayMicroseconds(10);
      delay(t);                         //increment delay 0.1s, resolution is 0.1s
    count++;                           //increment
    //Serial.println(count);            //debugging
    }



    void picknumber( int count)
    {
      switch (count)
      {
      //case 0: zero(); break;
      case 1:PORTD=B00010000; break;            //1
      case 2:PORTD=B01000000; break;            //2
      case 3:PORTD=B01010000; break;            //3
      case 4:PORTD=B10000000; break;            //4
      case 5:PORTD=B10010000; break;            //5
      case 6:PORTD=B11000000; break;            //6
      case 7:PORTD=B11010000; break;            //7
      case 8:PORTD=B00100000; break;            //8
      case 9:PORTD=B00110000; break;            //9
      default: B00000000; break;                //0
      }
    }

     
     
    Last edited: Feb 15, 2016
  2. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,304
    Likes:
    914
    Location:
    Rochdale UK
    ONLINE
    You only have one visual delay time.... delaymicroseconds(10) isn't long enough... You need a bit more as the final one is longer!!! I would keep the LED's on for at least 20mS each
     
    • Thanks Thanks x 1
  3. fezder

    fezder Well-Known Member

    Joined:
    Dec 11, 2011
    Messages:
    1,665
    Likes:
    100
    Location:
    Mikkeli, Finland
    Oops, that was the cause, i confused micros and millis....doh! sorry and thanks!
     
  4. dave

    Dave New Member

    Joined:
    Jan 12, 1997
    Messages:
    -
    Likes:
    0


     
  5. fezder

    fezder Well-Known Member

    Joined:
    Dec 11, 2011
    Messages:
    1,665
    Likes:
    100
    Location:
    Mikkeli, Finland

    wohoo, all 4 digits work, and it's better than previous version! thanks a lot!
     
  6. fezder

    fezder Well-Known Member

    Joined:
    Dec 11, 2011
    Messages:
    1,665
    Likes:
    100
    Location:
    Mikkeli, Finland
    here we go
     
  7. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,304
    Likes:
    914
    Location:
    Rochdale UK
    ONLINE
    Cool!! No Flicker!! Well done....
     
    • Like Like x 1
  8. fezder

    fezder Well-Known Member

    Joined:
    Dec 11, 2011
    Messages:
    1,665
    Likes:
    100
    Location:
    Mikkeli, Finland
    my previous version is at blog section, if you want to compare....now i took code and schematics to safe place hehe
     

Share This Page