How to draw graphics on an 8x8 LED matrix

Post here to discuss programming with swordfish basic

Moderators: Chuckt, Garth, bitfogav

User avatar
bitfogav
Moderator
Moderator
Posts: 915
Joined: Sun Mar 28, 2010 9:03 pm
Location: United Kingdom
Contact:

How to draw graphics on an 8x8 LED matrix

Post by bitfogav » Mon Aug 02, 2010 3:24 am

Hi all, As I am learning Basic just wanted a Topic to share some code examples and to help anyone else learn the Basic Language.

Heres a subroutine which checks that counter value is between 100 to 200 and then it will carry out a FOR loop which will draw data on a 8x8 led matrix, after the FOR loop is finished looping it will then jump to NEXT and increase the counter and EXIT, if the routine is called and counter equals 201 then the ELSEIF line is carried out, which clears our counter.

Note that any comments after two forward slashes // are ignored by the complier.

I hope this helps someone :)

Code: Select all

Sub draw_disp2()                                        // display two routine
        IF counter >= 100 AND counter <=200 THEN        // check counter is 100 to 200 and then carry -
        FOR x = 0 To 7                                  // out FOR loop (IF not then jump to ELSEIF)
            PORTD = cathodes (x)
            PORTB = disp2_data(x) 
            DelayMS(1) 
            PORTB = %00000000      // stops ghosting when moving to the next column 
        NEXT
            Inc (counter)          // increase our counter
            EXIT                   // then we exit routine
        ELSEIF counter = 201 then  // we come here if counter equals 201 and then we
            clear (counter)        // clear our counter
        ENDIF 
END SUB 
Check out Brads topic "How to draw a smiley face on an 8x8 LED matrix" as the FOR to NEXT loop is explained in detail there. Here's the link:

http://www.bradsprojects.com/phpBB2/viewtopic.php?t=210

User avatar
brad
Site Admin
Site Admin
Posts: 2578
Joined: Fri Mar 26, 2010 10:30 pm
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Post by brad » Mon Aug 02, 2010 6:09 am

Very cool indeed :)

I am curious though, why do you start the counter from 100? is there a separate subroutine that also modifies the contents of counter?

And as always, if anyone has any questions be sure to ask - so far there are two members here who are migrating to BASIC and it is only a matter of time before we recruit more members.

mwha ha ha ha!

oh by the way, I changed the title of the topic just to make it a tad easier when browsing the forum to see what's in each topic.

User avatar
bitfogav
Moderator
Moderator
Posts: 915
Joined: Sun Mar 28, 2010 9:03 pm
Location: United Kingdom
Contact:

Post by bitfogav » Mon Aug 02, 2010 6:12 am

HaHa yes there is another subroutine.. here it is :)

Code: Select all

Sub draw_disp1()                   // display one routine
        If counter <100 Then       // check counter is 0 to 100 and then carry out -
        For x = 0 To 7             // FOR loop
            PORTD = cathodes (x)
            PORTB = disp1_data(x) 
            DelayMS(1) 
            PORTB = %00000000      // stops ghosting when moving to the next column 
        Next
            Inc (counter)          // increase our counter
        EndIf 
End Sub
Ive just been playing around with bits of your code and trying to learn by changing things and reading the swordfish guide :)

User avatar
brad
Site Admin
Site Admin
Posts: 2578
Joined: Fri Mar 26, 2010 10:30 pm
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Post by brad » Mon Aug 02, 2010 10:37 pm

I am working quite a bit with arrays at the moment which you may be interested in.

Tonight I have been experimenting with getting five bad guys on the screen at once, all going in their own random directions while keeping track of where they are and also avoiding walls.

It's all made quite simple thanks to for next loops and arrays!

I'll have to post the code soon (possibly tomorrow...)

User avatar
bitfogav
Moderator
Moderator
Posts: 915
Joined: Sun Mar 28, 2010 9:03 pm
Location: United Kingdom
Contact:

Post by bitfogav » Tue Aug 03, 2010 3:16 am

I'll be interested in any code Brad, to see how you tackled things and made things work..

Heres the arrays ive used for the code above

Code: Select all

Const disp1_data(8) As Byte = (%01010101,%10101010,%01010101,%10101010,%01010101,%10101010,%01010101,%10101010)
Const disp2_data(8) As Byte = (%10101010,%01010101,%10101010,%01010101,%10101010,%01010101,%10101010,%01010101)                                            
Const cathodes(8) As Byte = (%11111110,%11111101,%11111011,%11110111,%11101111,%11011111,%10111111,%01111111) 
all im really doing in the version of my code for the 8x8 matrix is making the led matrix display a chequered flag, and then switch to the other leds to draw another chequered flag, you will prob see that from my array data, disp1_data and disp2_data:)

User avatar
brad
Site Admin
Site Admin
Posts: 2578
Joined: Fri Mar 26, 2010 10:30 pm
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Post by brad » Tue Aug 03, 2010 6:20 am

Ah yes, I can see that (if I rearrange your code a little bit)

Code: Select all

Const disp1_data(8) As Byte = 
(%01010101
,%10101010
,%01010101
,%10101010
,%01010101
,%10101010
,%01010101
,%10101010)
Const disp2_data(8) As Byte = 
(%10101010
,%01010101
,%10101010
,%01010101
,%10101010
,%01010101
,%10101010
,%01010101)   
I have actually managed to get loads of bad guys within my game area on the pacman game. They all check their own speed, check for any walls in any direction and they move and turn in random directions which means they move all the way around the game area by themselves. It's looking like a game now!

User avatar
bitfogav
Moderator
Moderator
Posts: 915
Joined: Sun Mar 28, 2010 9:03 pm
Location: United Kingdom
Contact:

Post by bitfogav » Tue Aug 03, 2010 6:43 am

brad wrote:Ah yes, I can see that (if I rearrange your code a little bit)

Code: Select all

Const disp1_data(8) As Byte = 
(%01010101
,%10101010
,%01010101
,%10101010
,%01010101
,%10101010
,%01010101
,%10101010)
Const disp2_data(8) As Byte = 
(%10101010
,%01010101
,%10101010
,%01010101
,%10101010
,%01010101
,%10101010
,%01010101)   
I have actually managed to get loads of bad guys within my game area on the pacman game. They all check their own speed, check for any walls in any direction and they move and turn in random directions which means they move all the way around the game area by themselves. It's looking like a game now!
Brad your pacman game sounds really interesting, how did you program your bad guys to check all there own speed etc wow! cant wait to see it all working..

User avatar
brad
Site Admin
Site Admin
Posts: 2578
Joined: Fri Mar 26, 2010 10:30 pm
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Post by brad » Sun Aug 08, 2010 7:42 am

hi buddy, sorry for the late reply.

I have posted the pacman code as it is so far in the projects section.

make sure you ask questions if you have any!

User avatar
bitfogav
Moderator
Moderator
Posts: 915
Joined: Sun Mar 28, 2010 9:03 pm
Location: United Kingdom
Contact:

Post by bitfogav » Sun Aug 08, 2010 7:45 am

Hey buddy, no worries. I will have a look, I have been so busy lately that I haven't got round to anything this week or this weekend :(

User avatar
brad
Site Admin
Site Admin
Posts: 2578
Joined: Fri Mar 26, 2010 10:30 pm
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Post by brad » Sun Aug 08, 2010 10:01 pm

bitfogav wrote:Hey buddy, no worries. I will have a look, I have been so busy lately that I haven't got round to anything this week or this weekend :(
Sounds like me!

User avatar
bitfogav
Moderator
Moderator
Posts: 915
Joined: Sun Mar 28, 2010 9:03 pm
Location: United Kingdom
Contact:

Post by bitfogav » Mon Aug 16, 2010 10:21 am

Heres something that I have been doing today with a 8x8 matrix using swordfish.

the video isn't that good quality but heres the link to youtube
http://www.youtube.com/watch?v=rO2sjkj_GPk

heres part of the souce code

Code: Select all

Sub update_ram_data()

    Select display_step
    
        Case 0
            block_0_red(0) = %00101010
            block_0_red(1) = %10011111
            block_0_red(2) = %10111001
            block_0_red(3) = %01101101
            block_0_red(4) = %01011011
            block_0_red(5) = %10101011
            block_0_red(6) = %11011111
            block_0_red(7) = %10011010
            
            block_0_green(0) = %11010101
            block_0_green(1) = %11101101
            block_0_green(2) = %01100111
            block_0_green(3) = %10011011
            block_0_green(4) = %11100100
            block_0_green(5) = %11011101
            block_0_green(6) = %10110101
            block_0_green(7) = %01100101
    
        Case 1
            block_0_red(0) = %11011111
            block_0_red(1) = %11110101
            block_0_red(2) = %10111101
            block_0_red(3) = %10101100
            block_0_red(4) = %00010110
            block_0_red(5) = %01111110
            block_0_red(6) = %01110011
            block_0_red(7) = %01101101
            
            block_0_green(0) = %11100010
            block_0_green(1) = %01011110
            block_0_green(2) = %11111011
            block_0_green(3) = %01011011
            block_0_green(4) = %11101101
            block_0_green(5) = %11000011
            block_0_green(6) = %11001101
            block_0_green(7) = %10111011
               
        Case 2  
            block_0_red(0) = %01101010
            block_0_red(1) = %01100110
            block_0_red(2) = %10101111
            block_0_red(3) = %10110000
            block_0_red(4) = %00010111
            block_0_red(5) = %01011101
            block_0_red(6) = %11111000
            block_0_red(7) = %11011011
            
            block_0_green(0) = %11010111
            block_0_green(1) = %11011011
            block_0_green(2) = %01110010
            block_0_green(3) = %11101111
            block_0_green(4) = %11111100
            block_0_green(5) = %10110111
            block_0_green(6) = %11101111
            block_0_green(7) = %00110110
            
        Case 3
            block_0_red(0) = %11101100
            block_0_red(1) = %01000111
            block_0_red(2) = %10110100
            block_0_red(3) = %10111111
            block_0_red(4) = %11101010
            block_0_red(5) = %00001001
            block_0_red(6) = %01000001
            block_0_red(7) = %10011010
            
            block_0_green(0) = %01000011
            block_0_green(1) = %10110011
            block_0_green(2) = %00010110
            block_0_green(3) = %11010010
            block_0_green(4) = %00101100
            block_0_green(5) = %11010110
            block_0_green(6) = %11101101
            block_0_green(7) = %00101000

        Case 4
            block_0_red(0) = %10101110
            block_0_red(1) = %10111111
            block_0_red(2) = %10101011
            block_0_red(3) = %11011010
            block_0_red(4) = %01101101
            block_0_red(5) = %00000001
            block_0_red(6) = %00001010
            block_0_red(7) = %11001110
            
            block_0_green(0) = %01100011
            block_0_green(1) = %00000111
            block_0_green(2) = %01011011
            block_0_green(3) = %01010110
            block_0_green(4) = %01010001
            block_0_green(5) = %01010100
            block_0_green(6) = %11000110
            block_0_green(7) = %10010111

        Case 5
        
            block_0_red(0) = %11111111
            block_0_red(1) = %01100001
            block_0_red(2) = %01111001
            block_0_red(3) = %11000111
            block_0_red(4) = %01100001
            block_0_red(5) = %01001000
            block_0_red(6) = %11101110
            block_0_red(7) = %11011001
            
            block_0_green(0) = %11011110
            block_0_green(1) = %11001010
            block_0_green(2) = %11000110
            block_0_green(3) = %10010101
            block_0_green(4) = %01111100
            block_0_green(5) = %11010010
            block_0_green(6) = %11011101
            block_0_green(7) = %01100011

    EndSelect
    
    display_step = display_step + 1      // this is our count of frames
                                              // increment by 1.
    

    If display_step = 6 Then            // if we get to end, reset to 0. 
       display_step = 0
    EndIf
    
    red_cathodes = $00    // make sure that red cathodes are off 
    green_cathodes = $00  // and green cathodes
     

        For t = 0 To 250  // 250 = time delay
            For x = 0 To 7 
                green_cathodes = block_0_green(x)
                red_cathodes = block_0_red(x) 
                common_anodes = anodes0_7 (x) 
                DelayMS(1) 
                common_anodes = %00000000   // stops ghosting when moving to the next column     
            Next
            Inc(t)
        Next
End Sub

User avatar
brad
Site Admin
Site Admin
Posts: 2578
Joined: Fri Mar 26, 2010 10:30 pm
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Post by brad » Mon Aug 16, 2010 12:32 pm

Nice work :)

I think that you would be very interested in reading through Graham's explanation of how he managed to manipulate graphics for his tetris game.

Here's the link:

http://www.digital-diy.com/home/swordfi ... a-pic.html

In a nutshell, he has constant graphics data for all the blocks, and then he has variable data which holds all of the screen graphics.

A block will fall and will be or'ed with the screen data (so that it now displays on the screen) you can then rotate the block (using quite a simple routine) so as new blocks keep coming down, the screen data is constantly being updated and it only uses 16 bytes of ram (for an 8 x 16 display) not bad at all!

User avatar
bitfogav
Moderator
Moderator
Posts: 915
Joined: Sun Mar 28, 2010 9:03 pm
Location: United Kingdom
Contact:

Post by bitfogav » Mon Aug 16, 2010 8:05 pm

Yeah I have looked through Grahams tetris game, it is very good!.

He uses abit of code like this to turn the graphics around.

Code: Select all

Public Sub NewRotation(ByRef pSource() As Word, ByRef pTarget() As Word, ByVal pDirection As Byte     
Dim X2,Y2,Q,PX,PY As Integer       
Dim X1,Y1 As Byte     // define object origin    
PX = originx    PY = originY    // define object width   
 Q = 0     // clear the target array    
For X1 = 0 To 7        
pTarget(X1) = 0    Next
My code above is just experiments for my 24x24 display :)

User avatar
brad
Site Admin
Site Admin
Posts: 2578
Joined: Fri Mar 26, 2010 10:30 pm
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Post by brad » Mon Aug 16, 2010 9:43 pm

Any idea what you might want to display on the 24 x 24 screen?

User avatar
bitfogav
Moderator
Moderator
Posts: 915
Joined: Sun Mar 28, 2010 9:03 pm
Location: United Kingdom
Contact:

Post by bitfogav » Mon Aug 16, 2010 10:18 pm

brad wrote:Any idea what you might want to display on the 24 x 24 screen?
Well good question, it would be good to do objects that rotated like Graham's tetris, so might have to add a few things like that and then look into making a game for it, space invaders maybe? not sure yet :D

The Java Led-Grid-Tool that me and Woodz have been working on is really coming along now, check out the one 8x8 display version, we can make the output data output binary or hex in a swordfish format, it has some cool flip, rotate etc functions and even randomly fills the display like the picture below.

Image
Attachments
1 8x8 tool.jpg
1 8x8 tool.jpg (37.3 KiB) Viewed 23440 times

Post Reply
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Who is online

Users browsing this forum: No registered users and 3 guests