DigiPixel
The DigiPixel is a game shield which allows the user to connect an Arduino or DigiSpark, It is also an open source Arduino shield with a 64 pixel RGB LED display and six buttons.
It was also a project built by Brad Slattery, and one of his KickStarter projects. DigiPixel KickStarter.
This is my version of the DigiPixel Library and the ported games/progs to Firewing. All files can be downloaded at the bottom of the page.
Pin Layout
Diagram of the pins used by the Firewing DigiPixel Library to control the DigiPixel shift registers and buttons.
Example Images
Firewing DigiPixel Library
Module DigiPixel ' DigiPixel Colors... Public Const Black as byte = 0 Public Const Red as byte = 1 Public Const Green as byte = 2 Public Const Yellow as byte = 3 Public Const Blue as byte = 4 Public Const Magenta as byte = 5 Public Const Cyan as byte = 6 Public Const White as byte = 7 Public Const Blackbarrier as byte = 8 Public Const Redbarrier as byte = 9 Public Const Greenbarrier as byte = 10 Public Const Yellowbarrier as byte = 11 Public Const Bluebarrier as byte = 12 Public Const Magentabarrier as byte = 13 Public Const Cyanbarrier as byte = 14 Public Const Whitebarrier as byte = 15 ' Variable Arrays... Dim columnData(8) as byte = {&B10000000, &B01000000, &B00100000, &B00010000, &B00001000, &B00000100, &B00000010, &B00000001} public Dim bufferRed(8) as byte = {0,0,0,0,0,0,0,0} public Dim bufferGreen(8) as byte = {0,0,0,0,0,0,0,0} public Dim bufferBlue(8) as byte = {0,0,0,0,0,0,0,0} public Dim bufferBarriers(8) as byte = {0,0,0,0,0,0,0,0} ' Port/Pin Selection... Dim latchShiftNotLoadPin as D5 Dim clockPin as D2 Dim ledDataPin as D6 Dim outputEnablePin as D4 Dim buttonDataPin as D3 ' Button Controls... public Dim buttonStatus as byte = 0 public Dim buttonAPressed as boolean = false public Dim buttonBPressed as boolean = false public Dim buttonUpPressed as boolean = false public Dim buttonDownPressed as boolean = false public Dim buttonLeftPressed as boolean = false public Dim buttonRightPressed as boolean = false '**************************************************************************** '* Name : DrawScreen() * '* Purpose : Send stored data to RGB display. * '* Note : Needs to be called on a regular basis throughout your code. * '* : (for example, place it straight into your main loop). * '**************************************************************************** Public Sub DrawScreen() for index As Byte = 0 To 7 low(latchShiftNotLoadPin) shiftOut(columnData(index)) shiftOut(not bufferBlue(index)) shiftOut(not bufferRed(index)) shiftOut(not bufferGreen(index)) high(latchShiftNotLoadPin) low(outputEnablePin) delayms(1) high(outputEnablePin) next end sub '**************************************************************************** '* Name : SetPixel() * '* Purpose : Makes one single pixel a certain color. * '**************************************************************************** Public Sub SetPixel(pixelX as byte, pixelY as byte, color as byte) bufferRed(pixelX).bits(pixelY) = color.bits(0) bufferGreen(pixelX).bits(pixelY) = color.bits(1) bufferBlue(pixelX).bits(pixelY) = color.bits(2) bufferBarriers(pixelX).bits(pixelY) = color.bits(3) end sub '**************************************************************************** '* Name : AirWrite() * '* Purpose : Capture images and messages in the air with your camera. * '**************************************************************************** Public Sub AirWrite(flashDelay as integer) low(latchShiftNotLoadPin) shiftOut(columnData(0)) shiftOut(not bufferBlue(0)) shiftOut(not bufferRed(0)) shiftOut(not bufferGreen(0)) high(latchShiftNotLoadPin) low(outputEnablePin) delayus(flashDelay) high(outputEnablePin) end sub '**************************************************************************** '* Name : ClearScreen() * '* Purpose : Clears Screen (Clears data in buffers). * '**************************************************************************** Public Sub ClearScreen() for index As Byte = 0 To 7 bufferRed(index) = 0 bufferGreen(index) = 0 bufferBlue(index) = 0 bufferBarriers(index) = 0 next end sub '**************************************************************************** '* Name : DrawBox() * '* Purpose : Draw a filled box on the screen. * '**************************************************************************** Public Sub DrawBox(fromX As Byte, fromY As Byte, toX As Byte, toY As Byte, color As Byte) Dim tempByte as byte if (toX < fromX) then tempByte = fromX fromX = toX toX = tempByte end if if (toY < fromY) then tempByte = fromY fromY = toY toY = tempByte end if for index1 as byte = 0 to (toX - fromX) for index2 as byte = 0 to (toY - fromY) setPixel(fromX + index1, fromY + index2, color) next next end sub '**************************************************************************** '* Name : DrawVerticalLine() * '* Purpose : Draw a Vertical line on the screen. * '**************************************************************************** Public Sub DrawVerticalLine(xLocation as byte, fromY as byte, toY as byte, color as byte) Dim tempByte as byte if (toY < fromY) then tempByte = fromY fromY = toY toY = tempByte end if for index1 as byte = 0 to (toY - fromY) setPixel(xLocation, fromY + index1, color) next end sub '**************************************************************************** '* Name : DrawHorizontalLine() * '* Purpose : Draw a Horizontal line on the screen. * '**************************************************************************** Public Sub DrawHorizontalLine(yLocation as byte, fromX as byte, toX as byte, color as byte) Dim tempByte as byte if (toX < fromX) then tempByte = fromX fromX = toX toX = tempByte end if for index1 as byte = 0 to (toX - fromX) setPixel(fromX + index1, yLocation, color) next end sub '**************************************************************************** '* Name : FillScreen() * '* Purpose : Fill the entire screen with one single color. * '**************************************************************************** Public Sub FillScreen(color as byte) for index1 As Byte = 0 To 7 bufferRed(index1) = 0 bufferGreen(index1) = 0 bufferBlue(index1) = 0 bufferBarriers(index1) = 0 if color.bits(0) = 1 then bufferRed(index1) = 255 end if if color.bits(1) = 1 then bufferGreen(index1) = 255 end if if color.bits(2) = 1 then bufferBlue(index1) = 255 end if if color.bits(3) = 1 then bufferBarriers(index1) = 255 end if next end sub '**************************************************************************** '* Name : RotateScreen() * '* Purpose : Rotate the screen 90, 180 or 270 degrees in an anti-clockwise * '* : direction. * '**************************************************************************** Public Sub RotateScreen(degrees as integer) dim tempRed(8) as byte dim tempGreen(8) as byte dim tempBlue(8) as byte dim tempBarriers(8) as byte for index1 As Byte = 0 To 7 tempRed(index1) = bufferRed(index1) tempGreen(index1) = bufferGreen(index1) tempBlue(index1) = bufferBlue(index1) tempBarriers(index1) = bufferBarriers(index1) next select degrees case 90 for index1 As Byte = 0 To 7 for index2 As Byte = 0 To 7 bufferRed(index1).bits(index2) = tempRed(index2).bits(7-index1) bufferGreen(index1).bits(index2) = tempGreen(index2).bits(7-index1) bufferBlue(index1).bits(index2) = tempBlue(index2).bits(7-index1) bufferBarriers(index1).bits(index2) = tempBarriers(index2).bits(7-index1) next next case 180 for index1 As Byte = 0 To 7 for index2 As Byte = 0 To 7 bufferRed(index1).bits(index2) = tempRed(7-index1).bits(7-index2) bufferGreen(index1).bits(index2) = tempGreen(7-index1).bits(7-index2) bufferBlue(index1).bits(index2) = tempBlue(7-index1).bits(7-index2) bufferBarriers(index1).bits(index2) = tempBarriers(7-index1).bits(7-index2) next next case 270 for index1 As Byte = 0 To 7 for index2 As Byte = 0 To 7 bufferRed(index1).bits(index2) = tempRed(7-index2).bits(index1) bufferGreen(index1).bits(index2) = tempGreen(7-index2).bits(index1) bufferBlue(index1).bits(index2) = tempBlue(7-index2).bits(index1) bufferBarriers(index1).bits(index2) = tempBarriers(7-index2).bits(index1) next next end select end sub '**************************************************************************** '* Name : GetPixel() * '* Purpose : Return the color of a certain pixel. * '**************************************************************************** function GetPixel(pixelX as byte, pixelY as byte) as byte dim tempByte as byte tempByte.bits(0) = bufferRed(pixelX).bits(pixelY) tempByte.bits(1) = bufferGreen(pixelX).bits(pixelY) tempByte.bits(2) = bufferBlue(pixelX).bits(pixelY) tempByte.bits(3) = bufferBarriers(pixelX).bits(pixelY) return tempByte end function '**************************************************************************** '* Name : CheckBarrier() * '* Purpose : Return a boolean variable with a true or false, * '**************************************************************************** public function CheckBarrier(pixelX as byte, pixelY as byte) as boolean if bufferBarriers(pixelX).bits(pixelY) = 1 then return true else return false end if end function '**************************************************************************** '* Name : SaveButtonStates() * '* Purpose : Store the state of the six buttons in the six button, * '* : boolean variables. * '**************************************************************************** Public Sub SaveButtonStates() low(clockPin) // start with the clock line low low(latchShiftNotLoadPin) // first load the parallel data and then high(clockPin) // send a clock pulse to grab the parallel data low(clockPin) high(latchShiftNotLoadPin) // now that it's loaded we need to shift the data out to the microcontroller and save it. for index1 as byte = 0 to 7 // the first two bits will always be logic 1's, the next six are A, B, R, L, D, U)) buttonStatus.bits(index1) = buttonDataPin high(clockPin) low(clockPin) next low(latchShiftNotLoadPin) //Before we finish, inhibit the serial data from shifting by setting it back to LOAD. if (buttonStatus and &B00000100) = 4 then buttonAPressed = true else buttonAPressed = false end if if (buttonStatus and &B00001000) = 8 then buttonBPressed = true else buttonBPressed = false end if if (buttonStatus and &B00010000) = 16 then buttonRightPressed = true else buttonRightPressed = false end if if (buttonStatus and &B00100000) = 32 then buttonLeftPressed = true else buttonLeftPressed = false end if if (buttonStatus and &B01000000) = 64 then buttonDownPressed = true else buttonDownPressed = false end if if (buttonStatus and &B10000000) = 128 then buttonUpPressed = true else buttonUpPressed = false end if end sub '**************************************************************************** '* Name : InvertColors() * '* Purpose : Invert all colors currently displayed on the screen. * '**************************************************************************** Public Sub InvertColors() for index1 As Byte = 0 To 7 bufferRed(index1) = not bufferRed(index1) bufferGreen(index1) = not bufferGreen(index1) bufferBlue(index1) = not bufferBlue(index1) next end sub '**************************************************************************** '* Name : ShiftOut() * '* Purpose : Shifts all data to digipixel. * '**************************************************************************** private Sub ShiftOut(dataOut as byte) low(ledDataPin) low(clockPin) for index2 as byte = 0 to 7 low(clockPin) if dataOut.bits(index2) = 1 then ledDataPin = 1 else ledDataPin = 0 end if high(clockPin) low(ledDataPin) next low(clockPin) end sub '**************************************************************************** '* Name : Random() * '* Purpose : Returns a random number (0 to 65535). * '* : rndMax = Set max number to return. * '**************************************************************************** Public Function Random(rndMax as ushort) As UShort static LCG as ushort = 21844 static GLFSR As UShort = 1 LCG = (127 * LCG + 259) If (GLFSR And 1) = 1 Then GLFSR = GLFSR Xor 447 GLFSR = (GLFSR >> 1) Or &H8000 Else GLFSR = (GLFSR >> 1) End If return (GLFSR Xor LCG) mod rndMax End Function '**************************************************************************** '* Name : Initialize() * '* Purpose : Configure the DigiPixel module before use. * '**************************************************************************** private Sub Main() output(latchShiftNotLoadPin) output(clockPin) output(ledDataPin) output(outputEnablePin) input(buttonDataPin) End Sub end module
Download Files
Some of the added files may contain additional files (modules) which are needed.
Main Library
- DigiPixel.zip - DigiPixel Library.
Games
- ConnectFour.zip - Connect Four.
- PixelBird.zip - Pixel Bird (Flappy Bird).
- SnakePixel.zip - Snake Pixel.
- SpaceInvader.zip - Space Invader (BreakOutPixel).
Progs
- MovePixel.zip - Move Pixel.
- PixelAdventure.zip - Pixel Adventure.
- ScreenScan.zip - Screen Scan.
- ScrollingColorBars.zip - Scrolling Color Bars.
- TrafficLights.zip - Traffic Lights.


