Shop OBEX P1 Docs P2 Docs Learn Events
Newbee project — Parallax Forums

Newbee project

alfa88alfa88 Posts: 5
edited 2008-08-18 09:37 in BASIC Stamp
I just finished the Boe-Bot and decided to tear off the Basic Stamp board to drive a 6X6 led matrix. I am real beginner at programming so I hope someone will hold my hands so to speak. What I have done is use P0 through P11 as outputs. P0 through P5 are the X axis and P6 through P11 are the Y axis. The program I wrote simply addresses each led with the high/low commands. I then replicated the same code 10 times and changed the pause each time to speed up the scan. I am hoping there is a better way to do this because I used up the RAM in a hurry with my simpleton program.

Comments

  • SRLMSRLM Posts: 5,045
    edited 2008-08-13 05:09
    If you have a 6x6 LED matrix, isn't that 36 LEDS? Unless if you are having multiple LEDS per IO pin, how are you setting this up?
  • metron9metron9 Posts: 1,100
    edited 2008-08-13 06:21
    Dont replicate the code, reuse it by making a code block in a subroutine that you set a variable to the amount of time for the pause command. Then in your main loop you can do a for next loop to do the 10 scans at different speeds by calling the subroutine.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Think Inside the box first and if that doesn't work..
    Re-arrange what's inside the box then...
    Think outside the BOX!
  • alfa88alfa88 Posts: 5
    edited 2008-08-13 07:23
    Yes, slrm, that's 36 leds. As for metron9, I am programming virgin. I sort of get what your saying but how do you manipulate a subroutine that has the pause command in it. Here is an example of what I did to get row1 of 6 to blink.

    '1st scan

    HIGH 0
    LOW 6
    HIGH 7
    HIGH 8
    HIGH 9
    HIGH 10
    HIGH 11
    PAUSE 125
    LOW 0
    HIGH 1
    PAUSE 125
    LOW 1
    HIGH 2
    PAUSE 125
    LOW 2
    HIGH 3
    PAUSE 125
    LOW 3
    HIGH 4
    PAUSE 125
    LOW 4
    HIGH 5
    PAUSE 125
    LOW 5
  • Steph LindsaySteph Lindsay Posts: 767
    edited 2008-08-13 17:50
    Hello Alfa88,

    I'm glad that the Boe-Bot has inspired you to start buiding your own projects!· For an example of efficiently turning on and off groups of I/O pins in patterns with a single command, take a look at Chapter 6 of "What's a Microcontroller?" - it's about controlling a 7-segment LED, but it's an easy introduction to using OUTH, DIRH, etc.

    You can download the book (and many others) free from this page:

    http://www.parallax.com/tabid/535/Default.aspx

    Have fun!
    -Stephanie Lindsay
    Editor, Parallax Inc.
  • metron9metron9 Posts: 1,100
    edited 2008-08-14 00:31
    Here you have 16 lines of code using HIGH and LOW commands
    Reduced to 5 lines in a for next loop

    The 6th line is a debug output to show the state of the pins (can be removed)

    There is one logic difference in that pin 6 is set HIGH on exit of the code, one additional line to turn bit 5 off after the loop and reducing the loop count by 1 would be more exact. If bit 6 was not used then it would not matter.

    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    ' {$PORT COM1}
    i VAR Byte
    
    'LOW 0
    'HIGH 1
    'PAUSE 125
    'LOW 1
    'HIGH 2
    'PAUSE 125
    'LOW 2
    'HIGH 3
    'PAUSE 125
    'LOW 3
    'HIGH 4
    'PAUSE 125
    'LOW 4
    'HIGH 5
    'PAUSE 125
    'LOW 5
     
    'code above reduced to 5 lines of code + the debug output that can be removed 
    OUTL=1
    FOR i=1 TO 6
     PAUSE 125
     OUTL=OUTL*2        'shift the Bit over 1 position
    DEBUG BIN8 OUTL, CR 'this line outputs the value of pins0..7 on the screen.
    NEXT
     
     
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Think Inside the box first and if that doesn't work..
    Re-arrange what's inside the box then...
    Think outside the BOX!
  • alfa88alfa88 Posts: 5
    edited 2008-08-14 08:37
    Metron 9,

    Thank's for your help. I'll play with it. Just as a graphical aid I made a pictorial of what I'm doing.



    ---- Anodes----

    J0 J1 J2 J3 J4 J5
    J6 O O O O O O
    J7 O O O O O O
    J8 O O O O O O
    J9 O O O O O O
    J10 O O O O O O
    J11 O O O O O O

    Post Edited (alfa88) : 8/15/2008 5:37:38 AM GMT
  • alfa88alfa88 Posts: 5
    edited 2008-08-18 09:37
    Thanks to Steph's hint I have slashed a whole lot of code but now I have another problem.... I have a hunch J0 through J11 are not necessarily P0 through P11 on the BoeBot board. Hopefully this will be easy to sort out.


    The code:

    ' improved 6x6 led scanner program

    ' {$STAMP BS2}
    ' {$PBASIC 2.5}

    x CON %100000011111
    x1 CON %010000011111
    x2 CON %001000011111
    x3 CON %000100011111
    x4 CON %000010011111
    x5 CON %000001011111
    x6 CON %100000101111
    x7 CON %010000101111
    x8 CON %001000101111
    x9 CON %000100101111
    x10 CON %000010101111
    x11 CON %000001101111
    x12 CON %100000110111
    x13 CON %010000110111
    x14 CON %001000110111
    x15 CON %000100110111
    x16 CON %000010110111
    x17 CON %000001110111
    x18 CON %100000111011
    x19 CON %010000111011
    x20 CON %001000111011
    x21 CON %000100111011
    x22 CON %000010111011
    x23 CON %000001111011
    x24 CON %100000111101
    x25 CON %010000111101
    x26 CON %001000111101
    x27 CON %000100111101
    x28 CON %000010111101
    x29 CON %000001111101
    x30 CON %100000111110
    x31 CON %010000111110
    x32 CON %001000111110
    x33 CON %000100111110
    x34 CON %000010111110
    x35 CON %000001111110

    OUTH = %000000000000
    DIRH = %111111111111


    index VAR Byte

    DO

    FOR index = 0 TO 36

    LOOKUP index, [noparse][[/noparse] x, x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15,
    x16, x17, x18, x19, x20, x21, x22, x23, x24, x25, x26, x27, x28, x29, x30, x31, x32, x33, x34, x35 ], OUTH



    PAUSE 100

    NEXT

    LOOP
Sign In or Register to comment.