Controling The 7 Segment LED Display

technokid

Member
Hello,

My dad has a model train set (N scale) and he wants to find out the scaled train speed.
N scale has a size ratio of 1:144 and I found an equation to calculate the speed using 2 sets of infra red LEDs.
I have found the task easy until I tried to display the scaled speed of the train on a 3 digit, 7 segment, LED display.
What I want to know is: Is there any sort of PICAXE command to help with this task.
I would need a command that separates the 3 digits of the trains scaled speed (Separates the numeric string into 3 variables).
Each of the 3 variables will have the numbers 0 through to 9.
If I have that command, I can work around the software to easily display the 3 digits separately.
Hope someone can help.

Thanking anyone that can help,
Technokid.
 

technokid

Member
Sorry. I am using a 20M2 to control the displays.
I don't really like the extra commands that the X1 and X2 Versions have as I have always used M2 chips.
I am using the pins of the chip to turn the digits on and off separately.
The way that I am hoping to use it, flicker shouldn't matter.
I am not looking for the worlds fastest and non-flickering code.
I just want a command to separate the numeric string.

Thanks to anyone that can help,
Technokid.

P.S Is there also a command to round numbers to the whole digit (No decimals) ?
 
Last edited:

Hemi345

Senior Member
I've used the following in some of my projects to separate the digits. Here's a simple working example of how it works - speed counts up from 0:

Code:
[color=Blue]symbol [/color][color=Purple]speed [/color][color=DarkCyan]= [/color][color=Purple]b0[/color]
[color=Blue]symbol [/color][color=Purple]hund [/color][color=DarkCyan]= [/color][color=Purple]b1[/color]
[color=Blue]symbol [/color][color=Purple]tens [/color][color=DarkCyan]= [/color][color=Purple]b2[/color]
[color=Blue]symbol [/color][color=Purple]ones [/color][color=DarkCyan]= [/color][color=Purple]b3[/color]
[color=Blue]symbol [/color][color=Purple]temp1 [/color][color=DarkCyan]= [/color][color=Purple]b4[/color]
[color=Blue]symbol [/color][color=Purple]temp2 [/color][color=DarkCyan]= [/color][color=Purple]b5
speed [/color][color=DarkCyan]= [/color][color=Navy]0[/color]
[color=Black]main:
    [/color][color=Blue]inc [/color][color=Purple]speed
    hund [/color][color=DarkCyan]= [/color][color=Navy]0
    [/color][color=Purple]tens [/color][color=DarkCyan]= [/color][color=Navy]0
    [/color][color=Purple]ones [/color][color=DarkCyan]= [/color][color=Navy]0
    [/color][color=Purple]temp1 [/color][color=DarkCyan]= [/color][color=Navy]0
    [/color][color=Purple]temp2 [/color][color=DarkCyan]= [/color][color=Purple]speed
    [/color][color=Blue]if [/color][color=Purple]speed [/color][color=DarkCyan]>= [/color][color=Navy]100 [/color][color=Blue]then
      [/color][color=Purple]hund [/color][color=DarkCyan]= [/color][color=Purple]temp2 [/color][color=DarkCyan]/ [/color][color=Navy]100 [/color][color=Green]'hundreds digit defined here.
      [/color][color=Purple]temp1 [/color][color=DarkCyan]= [/color][color=Purple]hund [/color][color=DarkCyan]* [/color][color=Navy]100
      [/color][color=Purple]temp2 [/color][color=DarkCyan]= [/color][color=Purple]temp2 [/color][color=DarkCyan]- [/color][color=Purple]temp1
    [/color][color=Blue]endif
    if [/color][color=Purple]speed [/color][color=DarkCyan]>= [/color][color=Navy]10 [/color][color=Blue]then
      [/color][color=Purple]tens [/color][color=DarkCyan]= [/color][color=Purple]temp2 [/color][color=DarkCyan]/ [/color][color=Navy]10  [/color][color=Green]'tens digit defined here.
      [/color][color=Purple]temp1 [/color][color=DarkCyan]= [/color][color=Purple]tens [/color][color=DarkCyan]* [/color][color=Navy]10
      [/color][color=Purple]temp2 [/color][color=DarkCyan]= [/color][color=Purple]temp2 [/color][color=DarkCyan]- [/color][color=Purple]temp1
      ones [/color][color=DarkCyan]= [/color][color=Purple]temp2      [/color][color=Green]'ones digit defined here
    [/color][color=Blue]else
      [/color][color=Purple]ones [/color][color=DarkCyan]= [/color][color=Purple]temp2      [/color][color=Green]'ones digit defined here.
    [/color][color=Blue]endif
    sertxd ([/color][color=Red]"Speed:"[/color][color=Black],#[/color][color=Purple]speed[/color][color=Black],[/color][color=Red]" -- Hund:"[/color][color=Black],#[/color][color=Purple]hund[/color][color=Black],[/color][color=Red]" Tens:"[/color][color=Black],#[/color][color=Purple]tens[/color][color=Black],[/color][color=Red]" Ones:"[/color][color=Black],#[/color][color=Purple]ones[/color][color=Black],[/color][color=Navy]13[/color][color=Black],[/color][color=Navy]10[/color][color=Blue])
    pause [/color][color=Navy]250
    [/color][color=Blue]goto [/color][color=Black]main[/color]
 
Last edited:
Top