Shop OBEX P1 Docs P2 Docs Learn Events
Simplifying code using arrays — Parallax Forums

Simplifying code using arrays

Technic-R-CTechnic-R-C Posts: 117
edited 2008-04-02 01:53 in BASIC Stamp
Hello,

I have a question in regards to the code i have pasted below.· I want to simplify it using an array instead of a bunch of numbers.· In other words I want to make one variable = to 8, 9, 10, 15, 14, 13.· I have read the index but I do not know how to approach this problem because the numbers i have chosen do not ascend in numerical order, rather they skip around a lot.· The code below is used to make the leds in a 8 digit led display move in a circle.· Can anyone simplify this with FOR loops and an array.

' {$STAMP BS2px} 
' {$PBASIC 2.5} 
DO 
'8, 9, 10, 15, 14, 13 
led VAR Word 

HIGH 8 
PAUSE 100 
HIGH 9 
PAUSE 100 
HIGH 10 
PAUSE 100 
HIGH 15 
PAUSE 100 
HIGH 14 
PAUSE 100 
HIGH 13 
PAUSE 100 
LOW 8 
PAUSE 100 
LOW 9 
PAUSE 100 
LOW 10 
PAUSE 100 
LOW 15 
PAUSE 100 
LOW 14 
PAUSE 100 
LOW 13 
PAUSE 100 
LOOP

Comments

  • JonathanJonathan Posts: 1,023
    edited 2008-04-02 01:35
    Here is one simple way:

    delay CON 100
    i     VAR Byte
    pinNum VAR Byte
    FOR i = 0 TO 5
      LOOKUP i,[noparse][[/noparse]8,9,10,15,14,13], pinMum
      HIGH pinNum
      PAUSE delay
    next
    FOR i = 0 TO 5
      LOOKUP i,[noparse][[/noparse]8,9,10,15,14,13], pinMum
      LOW pinNum
      PAUSE delay
    next
    
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    www.madlabs.info - Home of the Hydrogen Fuel Cell Robot
  • Technic-R-CTechnic-R-C Posts: 117
    edited 2008-04-02 01:53
    Thanks Jonathan for the very quick reply

    Works Great now

    Technic-R-C
    ·
Sign In or Register to comment.