Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections;
- using System.Threading;
- using Microsoft.SPOT;
- using Microsoft.SPOT.Presentation;
- using Microsoft.SPOT.Presentation.Controls;
- using Microsoft.SPOT.Presentation.Media;
- using Microsoft.SPOT.Touch;
- using Microsoft.SPOT.Hardware;
- using Gadgeteer.Networking;
- using GT = Gadgeteer;
- using GTM = Gadgeteer.Modules;
- using Gadgeteer.Modules.GHIElectronics;
- namespace Gadgeteer_LEDMatrix_01
- {
- public partial class Program
- {
- // create a timer object
- GT.Timer timer = new GT.Timer(100);
- LEDMatrix[] displays = new LEDMatrix[4];
- // array to hold the character shapes
- byte[] displayArray = new byte[] { };
- //object[] displays = new object[2];
- Hashtable AsciiLookup = new Hashtable();
- //
- int arrayOffset = 0;
- // This method is run when the mainboard is powered up or reset.
- void ProgramStarted()
- {
- /*******************************************************************************************
- Modules added in the Program.gadgeteer designer view are used by typing
- their name followed by a period, e.g. button. or camera.
- Many modules generate useful events. Type +=<tab><tab> to add a handler to an event, e.g.:
- button.ButtonPressed +=<tab><tab>
- If you want to do something periodically, use a GT.Timer and handle its Tick event, e.g.:
- GT.Timer timer = new GT.Timer(1000); // every second (1000ms)
- timer.Tick +=<tab><tab>
- timer.Start();
- *******************************************************************************************/
- //AsciiLookup.Add((int)'1', new byte[] { 0x02, 0xFE, 0x42 });
- //AsciiLookup.Add((int)'2', new byte[] { 0xF2, 0x92, 0x9E });
- //AsciiLookup.Add((int)'3', new byte[] { 0xFE, 0x92, 0x92 });
- //AsciiLookup.Add((int)'4', new byte[] { 0xFE, 0x10, 0xF0 });
- //AsciiLookup.Add((int)'5', new byte[] { 0x9E, 0x92, 0xF2 });
- //AsciiLookup.Add((int)'6', new byte[] { 0x9E, 0x92, 0xFE });
- //AsciiLookup.Add((int)'7', new byte[] { 0xFE, 0x80, 0x80 });
- //AsciiLookup.Add((int)'8', new byte[] { 0xFE, 0x92, 0xFE });
- //AsciiLookup.Add((int)'9', new byte[] { 0xFE, 0x90, 0xF0 });
- //AsciiLookup.Add((int)'0', new byte[] { 0xFE, 0x82, 0xFE });
- //AsciiLookup.Add((int)' ', new byte[] { 0x00 });
- AsciiLookup.Add((int)':', new byte[] { 0x28 });
- AsciiLookup.Add((int)'!', new byte[] { 0x20, 0x10, 0xD7, 0xF8, 0xD7, 0x10, 0x20 });
- AsciiLookup.Add((int)'+', new byte[] { 0x06, 0x63, 0x63, 0x0B, 0x63, 0x63, 0x06 });
- AsciiLookup.Add((int)'0', new byte[] { 126, 66, 66, 66, 66, 66, 66, 126 });
- AsciiLookup.Add((int)'1', new byte[] { 8, 24, 40, 8, 8, 8, 8, 8 });
- AsciiLookup.Add((int)'2', new byte[] { 126, 2, 2, 126, 64, 64, 64, 126 });
- AsciiLookup.Add((int)'3', new byte[] { 124, 2, 2, 126, 2, 2, 2, 124 });
- AsciiLookup.Add((int)'4', new byte[] { 2, 4, 8, 16, 34, 66, 254, 2 });
- AsciiLookup.Add((int)'5', new byte[] { 126, 64, 64, 124, 2, 2, 2, 124 });
- AsciiLookup.Add((int)'6', new byte[] { 126, 64, 64, 126, 66, 66, 66, 126 });
- AsciiLookup.Add((int)'7', new byte[] { 126, 2, 2, 4, 8, 16, 32, 64 });
- AsciiLookup.Add((int)'8', new byte[] { 60, 66, 66, 60, 66, 66, 66, 60 });
- AsciiLookup.Add((int)'9', new byte[] { 126, 66, 66, 126, 2, 2, 2, 124 });
- AsciiLookup.Add((int)'A', new byte[] { 60, 66, 66, 66, 126, 66, 66, 66 });
- AsciiLookup.Add((int)'B', new byte[] { 124, 66, 66, 126, 66, 66, 66, 124 });
- AsciiLookup.Add((int)'C', new byte[] { 62, 64, 64, 64, 64, 64, 64, 62 });
- AsciiLookup.Add((int)'D', new byte[] { 124, 66, 66, 66, 66, 66, 66, 60 });
- AsciiLookup.Add((int)'E', new byte[] { 126, 64, 64, 126, 64, 64, 64, 126 });
- AsciiLookup.Add((int)'F', new byte[] { 126, 64, 64, 126, 64, 64, 64, 64 });
- AsciiLookup.Add((int)'G', new byte[] { 126, 64, 64, 94, 66, 66, 66, 126 });
- AsciiLookup.Add((int)'H', new byte[] { 66, 66, 66, 126, 66, 66, 66, 66 });
- AsciiLookup.Add((int)'I', new byte[] { 124, 16, 16, 16, 16, 16, 16, 124 });
- AsciiLookup.Add((int)'J', new byte[] { 126, 8, 8, 8, 8, 40, 40, 16 });
- AsciiLookup.Add((int)'K', new byte[] { 68, 72, 80, 96, 80, 72, 68, 66 });
- AsciiLookup.Add((int)'L', new byte[] { 64, 64, 64, 64, 64, 64, 64, 126 });
- AsciiLookup.Add((int)'M', new byte[] { 66, 102, 90, 90, 66, 66, 66, 66 });
- AsciiLookup.Add((int)'N', new byte[] { 66, 98, 82, 74, 70, 66, 66, 66 });
- AsciiLookup.Add((int)'O', new byte[] { 60, 66, 66, 66, 66, 66, 66, 60 });
- AsciiLookup.Add((int)'P', new byte[] { 60, 66, 66, 66, 124, 64, 64, 64 });
- AsciiLookup.Add((int)'Q', new byte[] { 60, 66, 66, 66, 66, 74, 70, 127 });
- AsciiLookup.Add((int)'R', new byte[] { 124, 66, 66, 66, 124, 72, 68, 66 });
- AsciiLookup.Add((int)'S', new byte[] { 126, 64, 64, 126, 2, 2, 2, 126 });
- AsciiLookup.Add((int)'T', new byte[] { 124, 16, 16, 16, 16, 16, 16, 16 });
- AsciiLookup.Add((int)'U', new byte[] { 66, 66, 66, 66, 66, 66, 66, 60 });
- AsciiLookup.Add((int)'V', new byte[] { 130, 130, 130, 130, 130, 68, 40, 16 });
- AsciiLookup.Add((int)'W', new byte[] { 130, 130, 130, 130, 146, 170, 198, 130 });
- AsciiLookup.Add((int)'X', new byte[] { 130, 130, 68, 40, 16, 40, 68, 130 });
- AsciiLookup.Add((int)'Y', new byte[] { 66, 66, 66, 126, 2, 2, 2, 126 });
- AsciiLookup.Add((int)'Z', new byte[] { 255, 2, 4, 8, 16, 32, 64, 255 });
- AsciiLookup.Add((int)'*', new byte[] { 255, 255, 255, 255, 255, 255, 255, 255 });
- AsciiLookup.Add((int)' ', new byte[] { 0, 0, 0, 0, 0, 0, 0, 0 });
- /*
- Hex values for lcd fonts
- AsciiLookup.Add((int)’A‘, new byte[] {0x7F, 0x88, 0x88, 0x88, 0x7F, 0x00, 0x00, 0x00});
- AsciiLookup.Add((int)’B‘, new byte[] { 0xFF, 0x91, 0x91, 0x91, 0x6E, 0x00, 0x00, 0x00});
- AsciiLookup.Add((int)’C‘, new byte[] { 0x7E, 0x81, 0x81, 0x81, 0x42, 0x00, 0x00, 0x00});
- AsciiLookup.Add((int)’D‘, new byte[] { 0xFF, 0x81, 0x81, 0x42, 0x3C, 0x00, 0x00, 0x00});
- AsciiLookup.Add((int)’E‘, new byte[] { 0xFF, 0x91, 0x91, 0x91, 0x81, 0x00, 0x00, 0x00});
- AsciiLookup.Add((int)’F‘, new byte[] { 0xFF, 0x90, 0x90, 0x90, 0x80, 0x00, 0x00, 0x00});
- AsciiLookup.Add((int)’G‘, new byte[] { 0x7E, 0x81, 0x89, 0x89, 0x4E, 0x00, 0x00, 0x00});
- AsciiLookup.Add((int)’H‘, new byte[] { 0xFF, 0x10, 0x10, 0x10, 0xFF, 0x00, 0x00, 0x00});
- AsciiLookup.Add((int)’I‘, new byte[] { 0x81, 0x81, 0xFF, 0x81, 0x81, 0x00, 0x00, 0x00});
- AsciiLookup.Add((int)’J‘, new byte[] { 0x06, 0x01, 0x01, 0x01, 0xFE, 0x00, 0x00, 0x00});
- AsciiLookup.Add((int)’K‘, new byte[] { 0xFF, 0x18, 0x24, 0x42, 0x81, 0x00, 0x00, 0x00});
- AsciiLookup.Add((int)’L‘, new byte[] { 0xFF, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00});
- AsciiLookup.Add((int)’M‘, new byte[] { 0xFF, 0x40, 0x30, 0x40, 0xFF, 0x00, 0x00, 0x00});
- AsciiLookup.Add((int)’N‘, new byte[] { 0xFF, 0x40, 0x30, 0x08, 0xFF, 0x00, 0x00, 0x00});
- AsciiLookup.Add((int)’O‘, new byte[] { 0x7E, 0x81, 0x81, 0x81, 0x7E, 0x00, 0x00, 0x00});
- AsciiLookup.Add((int)’P‘, new byte[] { 0xFF, 0x88, 0x88, 0x88, 0x70, 0x00, 0x00, 0x00});
- AsciiLookup.Add((int)’Q‘, new byte[] { 0x7E, 0x81, 0x85, 0x82, 0x7D, 0x00, 0x00, 0x00});
- AsciiLookup.Add((int)’R‘, new byte[] { 0xFF, 0x88, 0x8C, 0x8A, 0x71, 0x00, 0x00, 0x00});
- AsciiLookup.Add((int)’S‘, new byte[] { 0x61, 0x91, 0x91, 0x91, 0x8E, 0x00, 0x00, 0x00});
- AsciiLookup.Add((int)’T‘, new byte[] { 0x80, 0x80, 0xFF, 0x80, 0x80, 0x00, 0x00, 0x00});
- AsciiLookup.Add((int)’U‘, new byte[] { 0xFE, 0x01, 0x01, 0x01, 0xFE, 0x00, 0x00, 0x00});
- AsciiLookup.Add((int)’V‘, new byte[] { 0xF0, 0x0C, 0x03, 0x0C, 0xF0, 0x00, 0x00, 0x00});
- AsciiLookup.Add((int)’W‘, new byte[] { 0xFF, 0x02, 0x0C, 0x02, 0xFF, 0x00, 0x00, 0x00});
- AsciiLookup.Add((int)’X‘, new byte[] { 0xC3, 0x24, 0x18, 0x24, 0xC3, 0x00, 0x00, 0x00});
- AsciiLookup.Add((int)’Y‘, new byte[] { 0xE0, 0x10, 0x0F, 0x10, 0xE0, 0x00, 0x00, 0x00});
- AsciiLookup.Add((int)’Z‘, new byte[] { 0x83, 0x85, 0x99, 0xA1, 0xC1, 0x00, 0x00, 0x00});
- AsciiLookup.Add((int)’a‘, new byte[] { 0x06, 0x29, 0x29, 0x29, 0x1F, 0x00, 0x00, 0x00});
- AsciiLookup.Add((int)’b‘, new byte[] { 0xFF, 0x09, 0x11, 0x11, 0x0E, 0x00, 0x00, 0x00});
- AsciiLookup.Add((int)’c‘, new byte[] { 0x1E, 0x21, 0x21, 0x21, 0x12, 0x00, 0x00, 0x00});
- AsciiLookup.Add((int)’d‘, new byte[] { 0x0E, 0x11, 0x11, 0x09, 0xFF, 0x00, 0x00, 0x00});
- AsciiLookup.Add((int)’e‘, new byte[] { 0x0E, 0x15, 0x15, 0x15, 0x0C, 0x00, 0x00, 0x00});
- AsciiLookup.Add((int)’f‘, new byte[] { 0x08, 0x7F, 0x88, 0x80, 0x40, 0x00, 0x00, 0x00});
- AsciiLookup.Add((int)’g‘, new byte[] { 0x30, 0x49, 0x49, 0x49, 0x7E, 0x00, 0x00, 0x00});
- AsciiLookup.Add((int)’h‘, new byte[] { 0xFF, 0x08, 0x10, 0x10, 0x0F, 0x00, 0x00, 0x00});
- AsciiLookup.Add((int)’i‘, new byte[] { 0x00, 0x00, 0x5F, 0x00, 0x00, 0x00, 0x00, 0x00});
- AsciiLookup.Add((int)’j‘, new byte[] { 0x02, 0x01, 0x21, 0xBE, 0x00, 0x00, 0x00, 0x00});
- AsciiLookup.Add((int)’k‘, new byte[] { 0xFF, 0x04, 0x0A, 0x11, 0x00, 0x00, 0x00, 0x00});
- AsciiLookup.Add((int)’l‘, new byte[] { 0x00, 0x81, 0xFF, 0x01, 0x00, 0x00, 0x00, 0x00});
- AsciiLookup.Add((int)’m‘, new byte[] { 0x3F, 0x20, 0x18, 0x20, 0x1F, 0x00, 0x00, 0x00});
- AsciiLookup.Add((int)’n‘, new byte[] { 0x3F, 0x10, 0x20, 0x20, 0x1F, 0x00, 0x00, 0x00});
- AsciiLookup.Add((int)’o‘, new byte[] { 0x0E, 0x11, 0x11, 0x11, 0x0E, 0x00, 0x00, 0x00});
- AsciiLookup.Add((int)’p‘, new byte[] { 0x3F, 0x24, 0x24, 0x24, 0x18, 0x00, 0x00, 0x00});
- AsciiLookup.Add((int)’q‘, new byte[] { 0x10, 0x28, 0x28, 0x18, 0x3F, 0x00, 0x00, 0x00});
- AsciiLookup.Add((int)’r‘, new byte[] { 0x1F, 0x08, 0x10, 0x10, 0x08, 0x00, 0x00, 0x00});
- AsciiLookup.Add((int)’s‘, new byte[] { 0x09, 0x15, 0x15, 0x15, 0x02, 0x00, 0x00, 0x00});
- AsciiLookup.Add((int)’t‘, new byte[] { 0x20, 0xFE, 0x21, 0x01, 0x02, 0x00, 0x00, 0x00});
- AsciiLookup.Add((int)’u‘, new byte[] { 0x1E, 0x01, 0x01, 0x02, 0x1F, 0x00, 0x00, 0x00});
- AsciiLookup.Add((int)’v‘, new byte[] { 0x1C, 0x02, 0x01, 0x02, 0x1C, 0x00, 0x00, 0x00});
- AsciiLookup.Add((int)’w‘, new byte[] { 0x1E, 0x01, 0x0E, 0x01, 0x1E, 0x00, 0x00, 0x00});
- AsciiLookup.Add((int)’x‘, new byte[] { 0x11, 0x0A, 0x04, 0x0A, 0x11, 0x00, 0x00, 0x00});
- AsciiLookup.Add((int)’y‘, new byte[] { 0x00, 0x39, 0x05, 0x05, 0x3E, 0x00, 0x00, 0x00});
- AsciiLookup.Add((int)’z‘, new byte[] { 0x11, 0x13, 0x15, 0x19, 0x11, 0x00, 0x00, 0x00});
- AsciiLookup.Add((int)’1‘, new byte[] { 0x00, 0x41, 0xFF, 0x01, 0x00, 0x00, 0x00, 0x00});
- AsciiLookup.Add((int)’2‘, new byte[] { 0x43, 0x85, 0x89, 0x91, 0x61, 0x00, 0x00, 0x00});
- AsciiLookup.Add((int)’3‘, new byte[] { 0x42, 0x81, 0x91, 0x91, 0x6E, 0x00, 0x00, 0x00});
- AsciiLookup.Add((int)’4‘, new byte[] { 0x18, 0x28, 0x48, 0xFF, 0x08, 0x00, 0x00, 0x00});
- AsciiLookup.Add((int)’5‘, new byte[] { 0xF2, 0x91, 0x91, 0x91, 0x8E, 0x00, 0x00, 0x00});
- AsciiLookup.Add((int)’6‘, new byte[] { 0x1E, 0x29, 0x49, 0x89, 0x86, 0x00, 0x00, 0x00});
- AsciiLookup.Add((int)’7‘, new byte[] { 0x80, 0x8F, 0x90, 0xA0, 0xC0, 0x00, 0x00, 0x00});
- AsciiLookup.Add((int)’8‘, new byte[] { 0x6E, 0x91, 0x91, 0x91, 0x6E, 0x00, 0x00, 0x00});
- AsciiLookup.Add((int)’9‘, new byte[] { 0x70, 0x89, 0x89, 0x8A, 0x7C, 0x00, 0x00, 0x00});
- AsciiLookup.Add((int)’?‘, new byte[] { 0x60, 0x80, 0x8D, 0x90, 0x60, 0x00, 0x00, 0x00});
- AsciiLookup.Add((int)’!‘, new byte[] { 0x00, 0x00, 0xFD, 0x00, 0x00, 0x00, 0x00, 0x00});
- AsciiLookup.Add((int)’0‘, new byte[] { 0x7E, 0x89, 0x91, 0xA1, 0x7E, 0x00, 0x00, 0x00});
- AsciiLookup.Add((int)’@‘, new byte[] { 0x66, 0x89, 0x8F, 0x81, 0x7E, 0x00, 0x00, 0x00});
- AsciiLookup.Add((int)’#‘, new byte[] { 0x24, 0xFF, 0x24, 0xFF, 0x24, 0x00, 0x00, 0x00});
- AsciiLookup.Add((int)’&‘, new byte[] { 0x76, 0x89, 0x95, 0x62, 0x05, 0x00, 0x00, 0x00});
- AsciiLookup.Add((int)’(‘, new byte[] { 0x00, 0x3C, 0x42, 0x81, 0x00, 0x00, 0x00, 0x00});
- AsciiLookup.Add((int)’)‘, new byte[] { 0x00, 0x81, 0x42, 0x3C, 0x00, 0x00, 0x00, 0x00});
- AsciiLookup.Add((int)’+‘, new byte[] { 0x08, 0x08, 0x3E, 0x08, 0x08, 0x00, 0x00, 0x00});
- AsciiLookup.Add((int)’-‘, new byte[] { 0x08, 0x08, 0x08, 0x08, 0x08, 0x00, 0x00, 0x00});
- AsciiLookup.Add((int)’=‘, new byte[] { 0x14, 0x14, 0x14, 0x14, 0x14, 0x00, 0x00, 0x00});
- AsciiLookup.Add((int)’>‘, new byte[] { 0x10, 0x10, 0x54, 0x38, 0x10, 0x00, 0x00, 0x00});
- AsciiLookup.Add((int)’<‘, new byte[] { 0x08, 0x1C, 0x2A, 0x08, 0x08, 0x00, 0x00, 0x00});
- AsciiLookup.Add((int)’$‘, new byte[] { 0x12, 0x2A, 0x7F, 0x2A, 0x24, 0x00, 0x00, 0x00});
- AsciiLookup.Add((int)’*‘, new byte[] { 0x44, 0x02, 0x12, 0x02, 0x44, 0x00, 0x00, 0x00});
- AsciiLookup.Add((int)’%‘, new byte[] { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00});
- */
- displays[0] = ledMatrix3;
- displays[1] = ledMatrix2;
- displays[2] = ledMatrix1;
- displays[3] = ledMatrix;
- // ceate a timer ticking event
- timer.Tick += new GT.Timer.TickEventHandler(timer_Tick);
- timer.Start();
- arrayOffset = 1;
- //drawString("tina xu is the best ");
- drawString("+ + + + + + ");
- // Use Debug.Print to show messages in Visual Studio's "Output" window during debugging.
- Debug.Print("Program Started");
- }
- void timer_Tick(GT.Timer timer)
- {
- Debug.Print("tick");
- // draw the array to the ledmatrix
- drawArray();
- }
- void drawString(string str)
- {
- Debug.Print("draw string");
- char[] characterArray = str.ToUpper().ToCharArray();
- foreach (char c in characterArray)
- {
- addCharacter((byte[])this.AsciiLookup[(int)c]);
- }
- drawArray();
- }
- void addCharacter(byte[] characterBytes)
- {
- //Debug.Print("add charactar");
- displayArray = Utility.CombineArrays(characterBytes, displayArray);
- }
- void drawArray()
- {
- Debug.Print("draw");
- //pad array to display size - minimum
- if (displayArray.Length < displays.Length * 8)
- {
- Debug.Print("padded the array");
- displayArray = Utility.CombineArrays(displayArray, new byte[(displays.Length * 8) - displayArray.Length]);
- }
- //For each matrix.
- for (int ctr = 0; ctr < displays.Length; ctr++)
- {
- byte[] currentDisplayData = new byte[] { };
- // if the currentDisplayData is in the middle of the string
- //
- if ((displayArray.Length >= (ctr + 1) * 8))
- {
- currentDisplayData = Utility.ExtractRangeFromArray(displayArray, ctr * 8, 8);
- }
- else
- // take from the start and end of the array
- {
- currentDisplayData = Utility.ExtractRangeFromArray(displayArray, ctr * 8, displayArray.Length - (ctr * 8));
- currentDisplayData = Utility.CombineArrays(currentDisplayData, new byte[8 - currentDisplayData.Length]);
- }
- //ledMatrix.DrawBitmap(currentDisplayData);
- //ledMatrix1.DrawBitmap(currentDisplayData);
- displays[ctr].DrawBitmap(currentDisplayData);
- }
- // shift the array to an offset
- //displayArray = Utility.CombineArrays(displayArray, displayArray.Length - arrayOffset, arrayOffset, displayArray, 0, displayArray.Length - arrayOffset);
- displayArray = Utility.CombineArrays(displayArray, displayArray.Length - arrayOffset, arrayOffset, displayArray, 0, displayArray.Length - arrayOffset);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment