Up/Down Counter Display using 4 7-seg displays

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 2 and 3.

Moderators: Benj, Mods

Post Reply
Sub_z
Posts: 3
Joined: Mon Dec 03, 2007 9:35 pm
Location: England
Contact:

Up/Down Counter Display using 4 7-seg displays

Post by Sub_z »

hello!
I have been using Flowcode at college and for a project trying to make an up down Counter which displays the count on a 4 7-seg display. i have got the counter working by using switches to make te counter count up every time the input switch count up is pressed which adds 1 to the total count and a switch when pressed takes one away from the total to count down.

to see if the counter was working i used LEDs as a display on the output. now i want to use the 4 7-seg displays to display the total count. i have worked through the floucourse tutorials and have got the sinlge 7 segment display working. the problem with the single 7-seg display is that only displays the count upto 9. when i worked through the 4 7-seg display on flowcourse i got it working on its own with putting the values i wanted on each digit in its macro.

i just wanted some help on how to program the display so i dont have to put the number in each display manually but for it do load the count automatically form the total count. i have tried using variables value1, value2, value3, value4 for each macro but i only get digit 0 the display on the right counting upto 9 after which it goes to zero but the next display doesnt display the 1 to display a 10 the next display stays at 0 and digit 0 starts counting again from 0-9 and the cycle keeps going. how do i program it so it displays the count if the counter has gone over 9

if anyone counld please help me i would appreciate it because i have to do a presentation to the class of the counter in action/working and hand in a report to the tutor.

SUB

User avatar
Steve
Matrix Staff
Posts: 3426
Joined: Tue Jan 03, 2006 3:59 pm
Has thanked: 114 times
Been thanked: 422 times
Contact:

Post by Steve »

Hello,

The following is an extract from the "quad 7 segment" page on Flowcourse:
Let's display 1234 on the quad 7-segment display . Enter 3,1,0 into the parameters box and click on OK. This will display the number 1 in the leftmost 7-segment display (remember they are numbered right to left). Next add 3 more macros with 2,2,0 1,3,0 and 0,4,0 in respectively.

Now run the program.
???????????????????
What happened? We sent the correct digit to all four 7-segments, but only the last one is lit.
This sounds like your problem. The solution is later on that page.

I hope this helps.

Sub_z
Posts: 3
Joined: Mon Dec 03, 2007 9:35 pm
Location: England
Contact:

Post by Sub_z »

thanks for the reply steve!

i have carefully gone through the "quad 7 segment" section of Flowcourse to see if i missed something or doing something wrong. After the following part of the extrac i cant get my head around how to incorperate that in my counter program.
One more trick to teach you, before we finish this part of the course. We could just show '1234' or some other predetermined number. But then we wouldn't be able to change the display without rewriting the program. So instead let's use a bunch of variables, Digit1, Digit2, Digit3 and Digit4. Now if we want to change the values we can change the variables in the main program, and the next time the interrupt is triggered then the new values will appear on the 7-segment display.
if it helps i can put my program on here to see if anyone can sopt where i have going wrong but basically this is what i have done so far to incorperate the display into the counter:
*I have put an iterupt into my program and put all the quad 7-seg display component macros into a separate routine
*I have used variables for the values but im not sure if i should do variables for the digit insted

*And the caluculation icon for the values I have no idea where to start and this is where the main problem is because i cant figure out what to write in the icon so the display changes every time the count goes up or down(the counter calculation is working its the display thats not). the only thing i have put in the calculations so far which is working for digit0 is Value1 = TotalCount, after that i cant figure out the calculations for the other digits. i have tried writing Value2 = TotalCount >9 because its after 9 that i cant program it to display TEN but this way when the count reaches 20 the 1 on digit1 stays a 1.

if you could help me with this i would seriously appreciate it
Thanks

Sub

User avatar
Steve
Matrix Staff
Posts: 3426
Joined: Tue Jan 03, 2006 3:59 pm
Has thanked: 114 times
Been thanked: 422 times
Contact:

Post by Steve »

Let's say you have 4 variables, d1, d2, d3, d4 for each digit.

First, you will need to set them to their initial values (probably all zero).

Use this whenever the count needs to be incremented:

Code: Select all

d1 = d1 + 1.

if d1 >= 10
  d1 = 0
  d2 = d2 + 1

  if d2 >= 10
    d2 = 0
    d3 = d3 + 1

    if d3 >= 10
      d3 = 0
      d4 = d4 + 1

      if d4 >= 10
        d4 = 0
      end if

    end if

  end if

end if
When displaying the digits, use something similar to this:

Code: Select all

ShowDigit 1,d1,0
Delay 10ms
ShowDigit 2,d2,0
Delay 10ms
ShowDigit 3,d3,0
Delay 10ms
ShowDigit 4,d4,0
Delay 10ms
The delays are used to keep the LEDs lit long enough for your eyes to see them.

Your display routine should ideally go in the main program, and there should not be any other large delays within this main loop.

I hope this helps.

Sub_z
Posts: 3
Joined: Mon Dec 03, 2007 9:35 pm
Location: England
Contact:

Post by Sub_z »

Seriously i cant thank you enough steve!

i have got the counter display working perfectly counting up.

after your last reply i realised where i was going wrong. i had the program set up like the first code you have described, but i had it as follows

Code: Select all

D1 = TotalCount. 

if D1 > 9 
  D1 = 0 
  D2 = D2 + 1 

  if D2 > 9 
    D2 = 0 
    D3 = D3 + 1 

    if D3 > 9 
      D1 = 9
      D2 = 9
      D3 = 9
the count is only every going to be > 9 oncle if D1 = Total Count thats why the second display wasnt changing. but now i have made the changes and the counter is counting up perfectly. there is still a problem of dsiplaying it counting down but if i cant figure it out i will let you know after i have tested it on flowcode at college which wont be until a couple of days as i dont have college until monday.

but thanks alot steve.
appreciate your help

SUB

Polanco
Posts: 21
Joined: Wed Dec 05, 2007 12:14 am
Location: Uruguay
Contact:

Post by Polanco »

Wouldn't it be nice to add some kind of latching button to the 4 digit module?
The adding of delays helps, but only a little bit.

Post Reply