Shop OBEX P1 Docs P2 Docs Learn Events
Running leds — Parallax Forums

Running leds

Jack.RubenJack.Ruben Posts: 8
edited 2008-04-21 16:19 in Propeller 1
Hallo,
wat is wrong on my program to create a running leds program?

Thanks,
··········· Jack

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2008-04-19 16:04
    It is difficult to tell what you want your program to do. Please explain. If it is a simple running LEDs process where the lights go from one side to another, then back again, your program is not written to do that. The indenting isn't consistent either. Start with a clear description. You probably need an outer loop (REPEAT) and two inner loops, one for going in one direction, the other for going in the other direction.
  • Jack.RubenJack.Ruben Posts: 8
    edited 2008-04-19 16:29
    Sorry mike for my bad explaination.

    I mean the leds wil first shift to the right and then go backwards(shift left) en so on.

    (a Nightrider light)

    Thanks Mike,

    ··················· Jack
  • Mike GreenMike Green Posts: 23,101
    edited 2008-04-19 17:04
    I've added some comments to your code. File attachments don't seem to work with the Safari browser.
    '' File: ShiftRightP9toP4_3.spin 
    '' ShiftRight and ShiftLeft
    '' Demonstrates the right shift and left shift.
    
    PUB ShiftLedsLeft
    
        dira[noparse][[/noparse]4..9]~~
    
        repeat
           
           if outa[noparse][[/noparse]9..4] == 0            ' *** This statement is OK
              outa[noparse][[/noparse]9..4] := %100000
          waitcnt(clkfreq/1 + cnt)   '  Wait = 1 seconde ' *** line this up
              outa[noparse][[/noparse]9..4] >>= 1           ' *** Why is this lined up this way?
           if outa[noparse][[/noparse]9..4] == %000001      ' *** All of the following only occur when outa is %000001
              waitcnt(clkfreq/1 + cnt)        ' *** and that's probably not what you want
              outa[noparse][[/noparse]9..4] := %000010
              waitcnt(clkfreq/1 + cnt)
              outa[noparse][[/noparse]9..4] <<= 1
    
  • Jack.RubenJack.Ruben Posts: 8
    edited 2008-04-19 19:35
    Have anyone a other suggestion so that my program wil work?
    ···· Jack.
  • Mike GreenMike Green Posts: 23,101
    edited 2008-04-19 19:59
    Did you read my previous reply about the two nested loops?
    I could write the program for you, but you wouldn't learn much from that.
  • propelleruser999propelleruser999 Posts: 39
    edited 2008-04-19 22:39
    Jack

    Since i'm also a newbee to the propeller, i took it as a challenge to solve Jacks problem. here is my version of the solution.

    At least it works. However,i think there is much to improve. May be Mike or someone else can have a look at the code and tell me and Jack, what can be improved.
    That's the way , we can learn to understand the propeller
  • hippyhippy Posts: 1,981
    edited 2008-04-20 01:07
    One thing which might be of use ( but might not be ) is that the range in OUTA[noparse]/noparse etc can be reversed ...

    OUTA[noparse][[/noparse]3..0] := %0101 ' Turns on LED's 0 and 2
    OUTA[noparse][[/noparse]0..3] := %0101 ' Turns on LED's 1 and 3

    Rather than have two loops, one could simply switch the startPin and EndPin numbers.
  • Jack.RubenJack.Ruben Posts: 8
    edited 2008-04-20 07:07
    Hello Mike

    I can not find any clou that helps my further. Thanks anyway.

    propelleruser999 and hippy thanks for the help.

    ··············· Jack.
  • deiloohaydeiloohay Posts: 11
    edited 2008-04-20 13:35
    when i first got the proprpm board, it comes with a demo program that was fairly easy to modify to run different patterns. try to load this up and modify as a start...

    http://elmicro.com/files/manuals/blink10.spin
  • Jack.RubenJack.Ruben Posts: 8
    edited 2008-04-20 14:54
    Yes it is a great demo program!
    Thanks you ferry mutch Deiloohay.

    ············· Jack.
  • Mike GreenMike Green Posts: 23,101
    edited 2008-04-20 15:20
    Here's my version, propelleruser999:
    {{ RunningLEDs.spin }}
    
    CON
    
      _CLKMODE = XTAL1 + PLL16X
      _XINFREQ = 5_000_000
      
      PinStart   = 0                          ' First LED pin (active HIGH)
      PinEnd     = 7                          ' Last LED pin (active HIGH)
      Pins       = || (PinStart - PinEnd)     ' Doesn't matter if PinStart < PinEnd
      Delay      = 250                        ' Delay in milliseconds
    
    PUB MainProgram | i
      dira[noparse][[/noparse]PinStart..PinEnd]~~                ' Make outputs
      outa[noparse][[/noparse]PinStart..PinEnd]~                 ' Initially off
      repeat
        outa[noparse][[/noparse]PinStart..PinEnd] := 1           ' Start with LSB
        repeat Pins - 1                       ' Repeat for each other bit
          waitcnt((clkfreq/1000)*Delay + cnt)
          outa[noparse][[/noparse]PinStart..PinEnd] <<= 1        ' Move to next higher bit
        repeat Pins - 1
          waitcnt((clkfreq/1000)*Delay + cnt)
          outa[noparse][[/noparse]PinStart..PinEnd] >>= 1        ' Move to next lower bit
        waitcnt((clkfreq/1000)*Delay + cnt)   ' Delay for last bit to show
    
  • propelleruser999propelleruser999 Posts: 39
    edited 2008-04-21 13:04
    Mike,
    yes, you solved it much more elegantly. you only have to set PinStart and PinEnd and everything else needed to run the program is calulated automatically.

    Thats the way i wanted it too, but do to lack of enough experience with SPIN, i didnt came up with a good solution.
    I'm a C programmer and still have to get more aquainted to SPIN, which has a c-like(or at least similar) syntax, but there are differences.

    learned some new things,thanks.
  • Jack.RubenJack.Ruben Posts: 8
    edited 2008-04-21 15:19
    Hello Mike and all the others.

    This is my solution for this program.

    Thanks to all.
    ······ Jack.
  • jazzedjazzed Posts: 11,803
    edited 2008-04-21 15:37
    propelleruser999 said...
    I'm a C programmer and still have to get more aquainted to SPIN, which has a c-like(or at least similar) syntax, but there are differences.
    Like many of us [noparse]:)[/noparse]· I'm not a LISP programmer, but it looks like the "repeat while ..." construct comes from LISP.
    I thought that Nightrider special effect was cool ... gives a searching feeling. It has been on·some·movie-bots too.

    Jack, Not that it matters, but you only need to use dira[noparse][[/noparse]5..0]~~ once in your program.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    jazzed·... about·living in·http://en.wikipedia.org/wiki/Silicon_Valley

    Traffic is slow at times, but Parallax orders·always get here fast 8)
  • propelleruser999propelleruser999 Posts: 39
    edited 2008-04-21 16:19
    Hello jack.Ruben,

    that fits your special 6 Led problem for specific pins , that the LEDs are connected. running more LEDs will have you to change all of your code.

    the programs Mike and i have suggested , use variables in the VAR sections and
    some code changes in your program.
    with Mike's version:
    once you decide to put your LED's on other pins ,or want to increase or decrease the number of LED's, you simply have to change
    StartPin and EndPin in the VAR section and the program runs without changing your whole program again.

    Think of a much bigger program ???

    You want to change your SD-Card to another pingroup? Just change the start adress (you need no end adress for a SD-card adapter , its already known by your previous program, if programmed that way)

    I don't know , if thats the only program you will ever write for the prop; then stay with that.
Sign In or Register to comment.