Shop OBEX P1 Docs P2 Docs Learn Events
led matrix problem — Parallax Forums

led matrix problem

Dr. VetterDr. Vetter Posts: 34
edited 2008-07-04 17:32 in BASIC Stamp
HI,

I·am making a little hand held game using a 5x5 led matrix.
·instead of programing each pin when to turn on i want to assign two pins to a label EX:

F1· F2· F3· F4· F5

F6· F7· F8· F9· F10

if i want F5 to turn on i just have to write

HIGH F5

i figured out how to do it with one pin but what about muiltiple pins

i have tryed
F5 pin 0 , 9
F5 pin 0 and 9
F5 pin 0 ; 9

what would the code be i cant seem to find it in my book

any help would be much apreciated

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2008-07-02 22:20
    It doesn't work that way. You have to change the output register (OUTS) for the bits you want and the details depend on which pins are hooked up to which LEDs. For the sake of discussion, say F1 is pin 0, F2 is pin 1 and so on up to F10 being pin 9. The bits in OUTS are such that pin 0 is the least significant bit with pin 15 being the most significant bit. To turn on F5, F8, and F10, leave F1, F3, and F7 unchanged, and turn off the others, you'd do
    OUTS = (OUTS & %111110001000101) | %0000001010010000
    


    Notice that you do a "bit and" with zero bits where you want to turn off the LED and "bit or" with one bits where you want to turn on the LED.

    Post Edited (Mike Green) : 7/2/2008 10:32:29 PM GMT
  • Dr. VetterDr. Vetter Posts: 34
    edited 2008-07-02 22:33
    thanks for the quick reply

    this sounds like its going to be a long night if this is the case.

    see in my matrix i have power going to the collector of my transister1 base to stamp and emiter to the diodes which there is 5 in parellel to a 220 ohm resister then going to a collector of another transister2 base to stamp and emiter to ground

    i have it set up this way so i can control 25 leds with only 10 pins with each transister controlling a row or colum so two pins have to be high in order for a specific led to light
    not sure if that changes what you have just told me but is there not a way i can map out the spicific leds
  • FranklinFranklin Posts: 4,747
    edited 2008-07-03 00:33
    How about a drawing of your circuit, it might it easier to follow the logic.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
  • Dr. VetterDr. Vetter Posts: 34
    edited 2008-07-03 01:17
    right now im playing with the registers but its nice cause it uses less code but its so confusing when your reading it to see if its right and then debuging it cause it was really wrong

    well anyways heres my schematic of the martix i have labeled where the stamp pins go also·probly not important but its·not on the schematic but there is two active high switches button a and button b going to P10 and P11.
  • Mike GreenMike Green Posts: 23,101
    edited 2008-07-03 01:32
    There's still the same issue. You have to make pairs of I/O pins active at the same time. You can do that exactly as I illustrated. You do run into problems if you want to turn on/off more than one LED at a time since you can get "sneak" paths through the matrix.

    You can use multiple statements on a line like: "HIGH F1 : LOW F7"

    There's a whole variety of ways to do this. What's "best" or works better will depend on what task you're trying to perform. You need to describe that.
  • Dr. VetterDr. Vetter Posts: 34
    edited 2008-07-03 03:18
    ok, well I did run in to the sneak your talking about but i did get around it.

    for instance when you loose the game it displays an L for loose but in the begining it would only display a block so I seperated the L in to two parts the right bar and the bottom seperated by a pause 1 and now it seem work wonderfully

    but basicly the game is just like an old atari game involving a racecar driving down the track passing cars but in my game your car is an led and its just an led that is coming at you and you can move with the A and B buttons only into three different spaces (right, left, and middle) if you get hit or crash then its game over. I have prepared three maps (easy,medium,hard) the map will scroll in a downward fashion at a certain rate for each level. The two right and left leds will be running on a 2on1off pattern starting on the 4th row. I am using a Bs2 and programing in 2.5 this is my first project after going through some basics on a kit i bought. hope i covered everything.
  • Mike GreenMike Green Posts: 23,101
    edited 2008-07-03 03:40
    With the matrix arrangement and because you need to light up complex patterns with more than one LED showing at a time, you need to multiplex the display bits. What this means is that you need to light a whole row at a time and go quickly through all 5 rows, do a little computation, and go through the 5 rows again repeatedly. Say you have a 5 byte array called "leds". You might have something like:
    leds  VAR  byte(5)
    i       VAR  nibble
    
    scan: for i = 0 to 4
               outs = (%1111100000 - (%100000 << i)) | leds(i)
             next i
    


    This should scan the rows turning on one PNP row driver at a time and turning on a pattern of NPN drivers based on the values in "leds".
    After going through the "scan:" routine once, you can update the bits in "leds" for the next cycle of what to show.
    This may be too slow with just a BS2. There are ways to speed this up using an external LED driver or you can use a faster processor.
  • Dr. VetterDr. Vetter Posts: 34
    edited 2008-07-04 14:17
    I·understand the concept of this but the code does not make sence to me

    what·I see here is

    scan: for i = 0 to 4
    (scan 5 times)

    outs = (%1111100000 - (%100000 << i)) | leds(i)
    (turn on only the vertical transisters) (and then i get lost)

    and by external do you mean like a ULN2003?
  • Mike GreenMike Green Posts: 23,101
    edited 2008-07-04 15:08
    The "outs =" statement sets all the I/O pins. It enables one row driver and the entire row (from a byte in the array "leds") at the same time. The reason the first part of the statement seems complex is that the row bits are off if they're a one and they're on if they're a zero. This expression converts "i" to a bitmask in the proper position. If "i" is 3, the bitmask is %1011100000. This gets or'd with the row contents which should be only 5 bits.

    By "external driver", I was thinking about a graphics LED driver from Maxim that can handle an 8x8 LED matrix and does all the multiplexing and LED driving with the transistors included on the chip, but, after looking at the datasheet, I decided that it was "overkill".
  • Dr. VetterDr. Vetter Posts: 34
    edited 2008-07-04 16:11
    Im sorry for my incompitance
    but are you saying it works kinda like when you add in binary
    00001 +00100 = 00101
    also what are you talking about when 1 = off and 0 = on because
    when I send a binary 1 it turns on my led
  • Mike GreenMike Green Posts: 23,101
    edited 2008-07-04 16:30
    Read the description of the "|" operator in the Basic Stamp Manual. 00001 + 00100 = 00101 and 00001 | 00100 = 00101, but 01001 + 01100 = 10101 while 01001 | 01100 = 01101.

    To turn on a PNP transistor connected as you've shown, you have to connect the base to ground (logic zero). If you connect the base to logic one, the transistor will turn off. The NPN transistors work in an opposite manner. Send them a binary 1 and they will turn on.
  • Dr. VetterDr. Vetter Posts: 34
    edited 2008-07-04 17:23
    oops lol Im sorry I never mentioned that I ran out of pnp 2n3904 due to my pcb router project so i replaced them with npn UPTB550
    now I get it, my fault.

    ok so I read the description so this is no different than digital electronics
    I did not know that
    is it the same for
    and, nand, nor, xor, xnor, not
  • Mike GreenMike Green Posts: 23,101
    edited 2008-07-04 17:32
    In Parallax Basic, bit and is "&", bit or is "|", bit xor is "^", and bit not is "!".
Sign In or Register to comment.