I have made a simple code to test the matrix with the Arduino, but it is too slow (the LEDs are flickering). I have used digitalWrite functions, so that may be why. However, I have grown tired of trying to get this game working on the Arduino and have always wanted to get into using the more technical PICs anyway. Having just received a PICnDuino getting started will probably be much easier. Anyways Brad, can the PIC on the PICnDuino board run the matrix (I don't know if the 3.3V would be a problem.) And if it can, would you happen to have some code I could borrow?
Great project by the way! I made LEDs blink using BASIC for the first time today!
RPG game + LED pixel game system hardware
Moderators: Chuckt, Garth, bitfogav
- Saimaster13
- I practically live here!
- Posts: 176
- Joined: Mon Aug 13, 2012 4:23 am
- Location: Sarasota, Florida [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
- brad
- 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
Re: RPG game + LED pixel game system hardware
Now you're talking! PIC microcontrollers (in my opinion) are the most fun to work with. Swordfish Basic is the best language too (much better than amicus18) but the good news for you is that you can use the swordfish IDE with your picnduino.
Now the only thing with Swordfish is that the free version limits you to 256bytes of sram (which is heaps for games that you might make on an 8x8 matrix) however when dealing with a 16x32 RGB matrix or 32x32 matrix, 256 bytes just isn't enough because you need to create a buffer to hold all of your pixel data for all colors before sending to the screen. In this case, you will need to fork out around $125 for the full version:
https://core-electronics.com.au/store/i ... piler.html
Having said that, I have used many programming languages and IDE's - swordfish is wonderful to use.
As for sample code, I do have some for you, this code (for swordfish) will allow you to connect up your PICnDuino to the 16x32RGB matrix and it will then draw random colors and sizes of boxes on the screen:
You can download the source code and hex file here - you may not be able to compile the source code due to it requiring more than 256 bytes of sram - but you should be able to upload the code to the picnduino using the amicus18loader program. the sourceode tells you where to connect up the LED matrix connections.
There is no flicker with this code - it runs very nicely. From here you can throw whatever data you want into the red green and blue outputdata arrays and it will get drawn to the screen.
Now the only thing with Swordfish is that the free version limits you to 256bytes of sram (which is heaps for games that you might make on an 8x8 matrix) however when dealing with a 16x32 RGB matrix or 32x32 matrix, 256 bytes just isn't enough because you need to create a buffer to hold all of your pixel data for all colors before sending to the screen. In this case, you will need to fork out around $125 for the full version:
https://core-electronics.com.au/store/i ... piler.html
Having said that, I have used many programming languages and IDE's - swordfish is wonderful to use.
As for sample code, I do have some for you, this code (for swordfish) will allow you to connect up your PICnDuino to the 16x32RGB matrix and it will then draw random colors and sizes of boxes on the screen:
Code: Select all
Device = 18F25K20 'Automatically brings in device file 18F25K22.bas
Clock = 64 '64MHz (top speed)
Config FOSC = HSPLL 'tells PIC to use external high speed (crystal) oscillator, medium power
'Libraries
Include "utils.bas" // we are including an extra file here which allows us to use shortcuts
Include "RandGen.bas"
' Arrays
Dim OutputDataRed(16) As LongWord
Dim OutputDataGreen(16) As LongWord
Dim OutputDataBlue(16) As LongWord
' Variables
Dim x As Word
Dim y As Byte
Dim AnimationDelay As Byte
Dim TempData0 As LongWord
Dim TempData1 As LongWord
Dim TempData2 As LongWord
Dim TempData3 As LongWord
Dim TempData4 As LongWord
Dim TempData5 As LongWord
' Port Pins
Dim RedData0 As PORTB.0
Dim RedData1 As PORTB.1
Dim GreenData0 As PORTB.4
Dim GreenData1 As PORTB.5
Dim BlueData0 As PORTB.2
Dim BlueData1 As PORTB.3
Dim RowA As PORTC.1
Dim RowB As PORTC.2
Dim RowC As PORTC.3
Dim Latch As PORTB.6
Dim CLK As PORTB.7
Dim OutputEnable As PORTC.4
' Sub Routines
Sub DrawGraphics() ' All we need to do is store 32 long words in our output data registers, and this routine will take care of displaying them on the screen!
For y = 0 To 7
TempData0 = OutputDataRed(y)
TempData1 = OutputDataRed(y + 8)
TempData2 = OutputDataGreen(y)
TempData3 = OutputDataGreen(y + 8)
TempData4 = OutputDataBlue(y)
TempData5 = OutputDataBlue(y + 8)
For x = 0 To 31
RedData0 = TempData0.bits(31 - x)
RedData1 = TempData1.bits(31 - x)
GreenData0 = TempData2.bits(31 - x)
GreenData1 = TempData3.bits(31 - x)
BlueData0 = TempData4.bits(31 - x)
BlueData1 = TempData5.bits(31 - x)
CLK = 1
CLK = 0
Next
RowA = y.bits(0)
RowB = y.bits(1)
RowC = y.bits(2)
Latch = 1
Latch = 0
OutputEnable = 0
DelayUS(250)
OutputEnable = 1
Next
End Sub
Sub DrawFillBox(FromX As Byte, FromY As Byte, ToX As Byte, ToY As Byte, Color As Byte)
Dim Temp As Byte
If FromY > ToY Then
Temp = FromY
FromY = ToY
ToY = Temp
EndIf
If FromX > ToX Then
Temp = FromX
FromX = ToX
ToX = Temp
EndIf
If Color = 0 Then
Color = 1
EndIf
For x = 0 To (ToY - FromY)
For y = 0 To (ToX - FromX)
OutputDataRed(FromX + y).bits(FromY + x) = Color.bits(0)
OutputDataGreen(FromX + y).bits(FromY + x) = Color.bits(1)
OutputDataBlue(FromX + y).bits(FromY + x) = Color.bits(2)
Next
Next
End Sub
sub MakeBoxes()
If AnimationDelay <> 0 Then
Dec(AnimationDelay)
Else
AnimationDelay = 5
DrawFillBox((Rand()/16),(Rand()/8),(Rand()/16),(Rand()/8),(Rand()/32))
EndIf
end sub
Sub ClearScreen()
For x = 0 To 15
OutputDataRed(x) = 0
OutputDataGreen(x) = 0
OutputDataBlue(x) = 0
Next
End Sub
' Start Of Program
TRISB = %00000000
TRISA = %00111111
TRISC = %00100000
AnimationDelay = 10
' Main Loop
While True()
MakeBoxes
DrawGraphics
Wend
There is no flicker with this code - it runs very nicely. From here you can throw whatever data you want into the red green and blue outputdata arrays and it will get drawn to the screen.
Who is online
Users browsing this forum: No registered users and 8 guests