diff --git a/Getting_Started_with_the_Internet_of_Things_LED_Controller.pdf b/Getting_Started_with_the_Internet_of_Things_LED_Controller.pdf new file mode 100644 index 0000000..25a69ef Binary files /dev/null and b/Getting_Started_with_the_Internet_of_Things_LED_Controller.pdf differ diff --git a/NetduinoGarageDoorOpener/NetduinoGarageDoorOpener.sln b/NetduinoGarageDoorOpener/NetduinoGarageDoorOpener.sln new file mode 100644 index 0000000..05f1002 --- /dev/null +++ b/NetduinoGarageDoorOpener/NetduinoGarageDoorOpener.sln @@ -0,0 +1,22 @@ + +Microsoft Visual Studio Solution File, Format Version 11.00 +# Visual Studio 2010 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NetduinoGarageDoorOpener", "NetduinoGarageDoorOpener\NetduinoGarageDoorOpener.csproj", "{CFCB4443-0CFD-4AA7-92EE-291C70A205B9}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {CFCB4443-0CFD-4AA7-92EE-291C70A205B9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {CFCB4443-0CFD-4AA7-92EE-291C70A205B9}.Debug|Any CPU.Build.0 = Debug|Any CPU + {CFCB4443-0CFD-4AA7-92EE-291C70A205B9}.Debug|Any CPU.Deploy.0 = Debug|Any CPU + {CFCB4443-0CFD-4AA7-92EE-291C70A205B9}.Release|Any CPU.ActiveCfg = Release|Any CPU + {CFCB4443-0CFD-4AA7-92EE-291C70A205B9}.Release|Any CPU.Build.0 = Release|Any CPU + {CFCB4443-0CFD-4AA7-92EE-291C70A205B9}.Release|Any CPU.Deploy.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/NetduinoGarageDoorOpener/NetduinoGarageDoorOpener/NetduinoGarageDoorOpener.csproj b/NetduinoGarageDoorOpener/NetduinoGarageDoorOpener/NetduinoGarageDoorOpener.csproj new file mode 100644 index 0000000..2a9969a --- /dev/null +++ b/NetduinoGarageDoorOpener/NetduinoGarageDoorOpener/NetduinoGarageDoorOpener.csproj @@ -0,0 +1,45 @@ + + + + NetduinoGarageDoorOpener + Exe + NetduinoGarageDoorOpener + {b69e3092-b931-443c-abe7-7e7b65f2a37f};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + 9.0.21022 + 2.0 + {CFCB4443-0CFD-4AA7-92EE-291C70A205B9} + v4.1 + $(MSBuildExtensionsPath32)\Microsoft\.NET Micro Framework\ + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/NetduinoGarageDoorOpener/NetduinoGarageDoorOpener/Program.cs b/NetduinoGarageDoorOpener/NetduinoGarageDoorOpener/Program.cs new file mode 100644 index 0000000..4874b68 --- /dev/null +++ b/NetduinoGarageDoorOpener/NetduinoGarageDoorOpener/Program.cs @@ -0,0 +1,23 @@ +using System; +using System.Net; +using System.Net.Sockets; +using System.Threading; +using Microsoft.SPOT; +using Microsoft.SPOT.Hardware; +using SecretLabs.NETMF.Hardware; +using SecretLabs.NETMF.Hardware.NetduinoPlus; + +namespace NetduinoGarageDoorOpener +{ + public class Program + { + public static void Main() + { + Microsoft.SPOT.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces()[0].EnableDhcp(); + WebServer webServer = new WebServer(); + webServer.ListenForRequest(); + + } + + } +} diff --git a/NetduinoGarageDoorOpener/NetduinoGarageDoorOpener/Properties/AssemblyInfo.cs b/NetduinoGarageDoorOpener/NetduinoGarageDoorOpener/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..a3287bd --- /dev/null +++ b/NetduinoGarageDoorOpener/NetduinoGarageDoorOpener/Properties/AssemblyInfo.cs @@ -0,0 +1,25 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("NetduinoGarageDoorOpener")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("Microsoft")] +[assembly: AssemblyProduct("NetduinoGarageDoorOpener")] +[assembly: AssemblyCopyright("Copyright © Microsoft 2011")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/NetduinoGarageDoorOpener/NetduinoGarageDoorOpener/WebServer.cs b/NetduinoGarageDoorOpener/NetduinoGarageDoorOpener/WebServer.cs new file mode 100644 index 0000000..ad4b0b2 --- /dev/null +++ b/NetduinoGarageDoorOpener/NetduinoGarageDoorOpener/WebServer.cs @@ -0,0 +1,101 @@ +using System; +using Microsoft.SPOT; +using System.Net.Sockets; +using System.Net; +using System.Threading; +using System.Text; +using Microsoft.SPOT.Hardware; +using SecretLabs.NETMF.Hardware.NetduinoPlus; + +namespace NetduinoGarageDoorOpener +{ + public class WebServer : IDisposable + { + private Socket socket = null; + //open connection to onbaord led so we can blink it with every request + private OutputPort led = new OutputPort(Pins.ONBOARD_LED, false); + private OutputPort Garage2CarOpener = new OutputPort(Pins.GPIO_PIN_D13, false); + + public WebServer() + { + //Initialize Socket class + socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); + //Request and bind to an IP from DHCP server + socket.Bind(new IPEndPoint(IPAddress.Any, 80)); + //Debug print our IP address + Debug.Print(Microsoft.SPOT.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces()[0].IPAddress); + //Start listen for web requests + socket.Listen(10); + ListenForRequest(); + } + + public void ListenForRequest() + { + while (true) + { + using (Socket clientSocket = socket.Accept()) + { + //Get clients IP + IPEndPoint clientIP = clientSocket.RemoteEndPoint as IPEndPoint; + EndPoint clientEndPoint = clientSocket.RemoteEndPoint; + //int byteCount = cSocket.Available; + int bytesReceived = clientSocket.Available; + if (bytesReceived > 0) + { + //Get request + byte[] buffer = new byte[bytesReceived]; + int byteCount = clientSocket.Receive(buffer, bytesReceived, SocketFlags.None); + string request = new string(Encoding.UTF8.GetChars(buffer)); + string firstLine = request.Substring(0, request.IndexOf('\n')); //Example "GET /activatedoor HTTP/1.1" + string[] words = firstLine.Split(' '); //Split line into words + string command = string.Empty; + if( words.Length > 2) + { + string method = words[0]; //First word should be GET + command = words[1].TrimStart('/'); //Second word is our command - remove the forward slash + } + switch (command.ToLower()) + { + case "activatedoor": + ActivateGarageDoor(); + //Compose a response + string response = "I just opened or closed the garage!"; + string header = "HTTP/1.0 200 OK\r\nContent-Type: text; charset=utf-8\r\nContent-Length: " + response.Length.ToString() + "\r\nConnection: close\r\n\r\n"; + clientSocket.Send(Encoding.UTF8.GetBytes(header), header.Length, SocketFlags.None); + clientSocket.Send(Encoding.UTF8.GetBytes(response), response.Length, SocketFlags.None); + break; + default: + //Did not recognize command + response = "Bad command"; + header = "HTTP/1.0 200 OK\r\nContent-Type: text; charset=utf-8\r\nContent-Length: " + response.Length.ToString() + "\r\nConnection: close\r\n\r\n"; + clientSocket.Send(Encoding.UTF8.GetBytes(header), header.Length, SocketFlags.None); + clientSocket.Send(Encoding.UTF8.GetBytes(response), response.Length, SocketFlags.None); + break; + } + } + } + } + } + private void ActivateGarageDoor() + { + led.Write(true); //Light on-board LED for visual cue + Garage2CarOpener.Write(true); //"Push" garage door button + Thread.Sleep(1000); //For 1 second + led.Write(false); //Turn off on-board LED + Garage2CarOpener.Write(false); //Turn off garage door button + } + #region IDisposable Members + ~WebServer() + { + Dispose(); + } + public void Dispose() + { + if (socket != null) + socket.Close(); + } + #endregion + } +} + + diff --git a/TronDisc Netduino Code/TronDisc.sln b/TronDisc Netduino Code/TronDisc.sln new file mode 100644 index 0000000..ca93986 --- /dev/null +++ b/TronDisc Netduino Code/TronDisc.sln @@ -0,0 +1,22 @@ + +Microsoft Visual Studio Solution File, Format Version 11.00 +# Visual C# Express 2010 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TronDisc", "TronDisc\TronDisc.csproj", "{209B3EC6-E705-4A65-B438-EB4A45EF8299}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {209B3EC6-E705-4A65-B438-EB4A45EF8299}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {209B3EC6-E705-4A65-B438-EB4A45EF8299}.Debug|Any CPU.Build.0 = Debug|Any CPU + {209B3EC6-E705-4A65-B438-EB4A45EF8299}.Debug|Any CPU.Deploy.0 = Debug|Any CPU + {209B3EC6-E705-4A65-B438-EB4A45EF8299}.Release|Any CPU.ActiveCfg = Release|Any CPU + {209B3EC6-E705-4A65-B438-EB4A45EF8299}.Release|Any CPU.Build.0 = Release|Any CPU + {209B3EC6-E705-4A65-B438-EB4A45EF8299}.Release|Any CPU.Deploy.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/TronDisc Netduino Code/TronDisc/Program.cs b/TronDisc Netduino Code/TronDisc/Program.cs new file mode 100644 index 0000000..937bffd --- /dev/null +++ b/TronDisc Netduino Code/TronDisc/Program.cs @@ -0,0 +1,399 @@ +using System; +using System.Threading; +using Microsoft.SPOT; +using Microsoft.SPOT.Hardware; +using SecretLabs.NETMF.Hardware; +using SecretLabs.NETMF.Hardware.Netduino; + +namespace TronDisc +{ + public class Program + { + public static byte new_animation_num = 0; + public static byte animation_num = 0; + public static byte animation_total = 10; + + public static max7219 driver; + + public static void Main() + { + // Define spi pins + OutputPort loadPin = new OutputPort(Pins.GPIO_PIN_D10, false); + OutputPort dataPin = new OutputPort(Pins.GPIO_PIN_D11, false); + OutputPort clkPin = new OutputPort(Pins.GPIO_PIN_D13, false); + + // Tron Button to Change Annimations, pulls high + InterruptPort changeBtn = new InterruptPort(Pins.GPIO_PIN_D0, false, Port.ResistorMode.Disabled, Port.InterruptMode.InterruptEdgeHigh); + changeBtn.OnInterrupt += new NativeEventHandler(changeBtn_OnInterrupt); + + // Voltage detect on base, pulls high + InterruptPort dockBtn = new InterruptPort(Pins.GPIO_PIN_D1, false, Port.ResistorMode.Disabled, Port.InterruptMode.InterruptEdgeBoth); + dockBtn.OnInterrupt += new NativeEventHandler(dockBtn_OnInterrupt); + + // Instance of driver, passing pin assignments + driver = new max7219(dataPin, clkPin, loadPin); + + byte cnt = 0; + + int r; + Random rand = new Random(); + r = rand.Next(25); + int i; + byte j; + byte k; + byte l; + byte[] bitwise = { 1, 2, 4, 8, 16, 32 }; + int dir = 0; + + // Turn on all LED's + for (j = 1; j < 9; j++) + driver.maxSingle(j, 0xFF); + + // Wait 3 seconds to test all LED's + Thread.Sleep(3000); + + // frame based animation uses 6 bits per char + // 5 chars per animation frame + + + // Animation array of animations + // built with http://www.harfordhackerspace.org/ledwiz/tron/ + byte[][] animations = new byte[][] + { + + new byte[] + { + 0x0,0x1,0x0,0x8,0x0, + 0x20,0x3,0x0,0x8,0x0, + 0x20,0x3,0x0,0x1c,0x0, + 0x30,0x7,0x0,0x1c,0x0, + 0x30,0x7,0x0,0x3e,0x0, + 0x38,0xf,0x0,0x3e,0x0, + 0x38,0xf,0x0,0x3f,0x1, + 0x3c,0x1f,0x0,0x3f,0x1, + 0x3c,0x1f,0x20,0x3f,0x3, + 0x3e,0x3f,0x20,0x3f,0x3, + 0x3e,0x3f,0x30,0x3f,0x7, + 0x3f,0x3f,0x31,0x3f,0x7, + 0x3f,0x3f,0x39,0x3f,0xf, + 0x3f,0x3f,0x3b,0x3f,0x2f, + 0x3f,0x3f,0x3f,0x3f,0x3f, + 0x3f,0x3e,0x3f,0x37,0x3f, + 0x1f,0x3c,0x3f,0x37,0x3f, + 0x1f,0x3c,0x3f,0x23,0x3f, + 0xf,0x38,0x3f,0x23,0x3f, + 0xf,0x38,0x3f,0x1,0x3f, + 0x7,0x30,0x3f,0x1,0x3f, + 0x7,0x30,0x3f,0x0,0x3e, + 0x3,0x20,0x3f,0x0,0x3e, + 0x3,0x20,0x1f,0x0,0x3c, + 0x1,0x0,0x1f,0x0,0x3c, + 0x1,0x0,0xf,0x0,0x38, + 0x0,0x0,0xe,0x0,0x38, + 0x0,0x0,0x6,0x0,0x30, + 0x0,0x0,0x4,0x0,0x10, + 0x0,0x0,0x0,0x0,0x0 + }, + + + new byte[] + { + 0x2,0x20,0x0,0x8,0x0, + 0x6,0x20,0x1,0x18,0x0, + 0xe,0x20,0x3,0x38,0x0, + 0x1c,0x0,0x7,0x30,0x1, + 0x38,0x0,0xe,0x20,0x3, + 0x30,0x1,0x1c,0x0,0x7, + 0x20,0x3,0x38,0x0,0xe, + 0x0,0x7,0x30,0x1,0x1c, + 0x0,0xe,0x20,0x3,0x38, + 0x1,0x1c,0x0,0x7,0x30, + 0x1,0x18,0x0,0x6,0x20, + 0x1,0x10,0x0,0x4,0x0, + 0x0,0x0,0x0,0x0,0x0 + }, + + + new byte[] + { + 0x2a,0x2a,0x2a,0x2a,0x2a, + 0x15,0x15,0x15,0x15,0x15 + }, + + + new byte[] + { + 0x0,0x0,0x0,0x8,0x0, + 0x0,0x0,0x0,0x14,0x0, + 0x0,0x0,0x0,0x22,0x0, + 0x0,0x0,0x0,0x1,0x1, + 0x0,0x0,0x20,0x0,0x2, + 0x0,0x0,0x10,0x0,0x4, + 0x0,0x0,0x8,0x0,0x8, + 0x0,0x0,0x4,0x0,0x10, + 0x0,0x0,0x2,0x0,0x20, + 0x1,0x0,0x1,0x0,0x0, + 0x2,0x20,0x0,0x0,0x0, + 0x4,0x10,0x0,0x0,0x0, + 0x8,0x8,0x0,0x0,0x0, + 0x10,0x4,0x0,0x0,0x0, + 0x20,0x2,0x0,0x0,0x0, + 0x0,0x1,0x0,0x0,0x0 + }, + + + new byte[] + { + 0x0,0x0,0x2,0x0,0x20, + 0x1,0x0,0x3,0x0,0x20, + 0x3,0x20,0x3,0x0,0x20, + 0x7,0x30,0x3,0x0,0x20, + 0xf,0x38,0x3,0x0,0x20, + 0x1f,0x3c,0x3,0x0,0x20, + 0x3f,0x3e,0x3,0x0,0x20, + 0x3f,0x3f,0x3,0x0,0x20, + 0x3f,0x3e,0x3,0x0,0x20, + 0x1f,0x3c,0x3,0x0,0x20, + 0xf,0x38,0x3,0x0,0x20, + 0x7,0x30,0x3,0x0,0x20, + 0x3,0x20,0x3,0x0,0x20, + 0x1,0x0,0x3,0x0,0x20, + 0x0,0x0,0x2,0x0,0x20, + 0x0,0x0,0x6,0x0,0x30, + 0x0,0x0,0xe,0x0,0x38, + 0x0,0x0,0x1e,0x0,0x3c, + 0x0,0x0,0x3e,0x0,0x3e, + 0x0,0x0,0x3e,0x1,0x3f, + 0x0,0x0,0x3e,0x23,0x3f, + 0x0,0x0,0x3e,0x37,0x3f, + 0x0,0x0,0x3e,0x3f,0x3f, + 0x0,0x0,0x3e,0x37,0x3f, + 0x0,0x0,0x3e,0x23,0x3f, + 0x0,0x0,0x3e,0x1,0x3f, + 0x0,0x0,0x3e,0x0,0x3e, + 0x0,0x0,0x1e,0x0,0x3c, + 0x0,0x0,0xe,0x0,0x38, + 0x0,0x0,0x6,0x0,0x30, + 0x0,0x0,0x2,0x0,0x20 + }, + + + new byte[] + { + 0x0,0x0,0x0,0x38,0x0, + 0x0,0x0,0x0,0x38,0x1, + 0x0,0x0,0x0,0x30,0x1, + 0x0,0x0,0x0,0x30,0x3, + 0x0,0x0,0x0,0x20,0x3, + 0x0,0x0,0x0,0x20,0x7, + 0x0,0x0,0x0,0x0,0x7, + 0x0,0x0,0x0,0x0,0xf, + 0x0,0x0,0x0,0x0,0xe, + 0x0,0x0,0x0,0x0,0x1e, + 0x0,0x0,0x0,0x0,0x1c, + 0x0,0x0,0x0,0x0,0x3c, + 0x0,0x0,0x0,0x0,0x38, + 0x1,0x0,0x0,0x0,0x38, + 0x1,0x0,0x0,0x0,0x30, + 0x3,0x0,0x0,0x0,0x30, + 0x3,0x0,0x0,0x0,0x20, + 0x7,0x0,0x0,0x0,0x20, + 0x7,0x0,0x0,0x0,0x0, + 0xf,0x0,0x0,0x0,0x0, + 0xe,0x0,0x0,0x0,0x0, + 0x1e,0x0,0x0,0x0,0x0, + 0x1c,0x0,0x0,0x0,0x0, + 0x3c,0x0,0x0,0x0,0x0, + 0x38,0x0,0x0,0x0,0x0, + 0x38,0x1,0x0,0x0,0x0, + 0x30,0x1,0x0,0x0,0x0, + 0x30,0x3,0x0,0x0,0x0, + 0x20,0x3,0x0,0x0,0x0, + 0x20,0x7,0x0,0x0,0x0, + 0x0,0x7,0x0,0x0,0x0, + 0x0,0xf,0x0,0x0,0x0, + 0x0,0xe,0x0,0x0,0x0, + 0x0,0x1e,0x0,0x0,0x0, + 0x0,0x1c,0x0,0x0,0x0, + 0x0,0x3c,0x0,0x0,0x0, + 0x0,0x38,0x0,0x0,0x0, + 0x0,0x38,0x1,0x0,0x0, + 0x0,0x30,0x1,0x0,0x0, + 0x0,0x30,0x3,0x0,0x0, + 0x0,0x20,0x3,0x0,0x0, + 0x0,0x20,0x7,0x0,0x0, + 0x0,0x0,0x7,0x0,0x0, + 0x0,0x0,0xf,0x0,0x0, + 0x0,0x0,0xe,0x0,0x0, + 0x0,0x0,0x1e,0x0,0x0, + 0x0,0x0,0x1c,0x0,0x0, + 0x0,0x0,0x3c,0x0,0x0, + 0x0,0x0,0x38,0x0,0x0, + 0x0,0x0,0x38,0x1,0x0, + 0x0,0x0,0x30,0x1,0x0, + 0x0,0x0,0x30,0x3,0x0, + 0x0,0x0,0x20,0x3,0x0, + 0x0,0x0,0x20,0x7,0x0, + 0x0,0x0,0x0,0x7,0x0, + 0x0,0x0,0x0,0xf,0x0, + 0x0,0x0,0x0,0xe,0x0 + }, + + + new byte[] + { + 0x0,0x0,0x0,0x8,0x0, + 0x0,0x0,0x0,0x14,0x0, + 0x0,0x0,0x0,0x22,0x0, + 0x0,0x0,0x0,0x1,0x1, + 0x0,0x0,0x20,0x0,0x2, + 0x0,0x0,0x10,0x0,0x4, + 0x0,0x0,0x8,0x0,0x8, + 0x0,0x0,0x4,0x0,0x10, + 0x0,0x0,0x2,0x0,0x20, + 0x1,0x0,0x1,0x0,0x0, + 0x2,0x20,0x0,0x0,0x0, + 0x4,0x10,0x0,0x0,0x0, + 0x8,0x8,0x0,0x0,0x0, + 0x10,0x4,0x0,0x0,0x0, + 0x20,0x2,0x0,0x0,0x0, + 0x20,0x3,0x0,0x0,0x0, + 0x20,0x2,0x0,0x0,0x0, + 0x20,0x3,0x0,0x0,0x0, + 0x8,0x9,0x0,0x0,0x0, + 0x10,0x5,0x0,0x0,0x0, + 0x20,0x3,0x0,0x0,0x0, + 0x20,0x2,0x0,0x0,0x0 + }, + + new byte[] + { + 0x30,0x7,0x0,0x0,0x0, + 0x38,0xe,0x0,0x0,0x0, + 0x1c,0x1c,0x0,0x0,0x0, + 0x38,0xe,0x0,0x0,0x0, + 0x30,0x7,0x0,0x0,0x0, + 0x30,0x6,0x0,0x0,0x0, + 0x10,0x4,0x0,0x0,0x0, + 0x14,0x14,0x0,0x0,0x0, + 0x15,0x14,0x1,0x0,0x0, + 0x15,0x14,0x5,0x0,0x10, + 0x15,0x14,0x15,0x0,0x14, + 0x15,0x14,0x15,0x1,0x15, + 0x15,0x14,0x15,0x15,0x15, + 0x15,0x14,0x15,0x9,0x15, + 0x15,0x14,0x15,0x2a,0x14, + 0x15,0x14,0x25,0x2a,0x12, + 0x15,0x14,0x29,0x2a,0xa, + 0x14,0x14,0x2a,0x2a,0x2a, + 0x12,0x24,0x2a,0x2a,0x2a, + 0xa,0x28,0x2a,0x2a,0x2a, + 0x2a,0x2a,0x2a,0x2a,0x2a + }, + + + new byte[] + { + 0x30,0x7,0x0,0x0,0x20, + 0x31,0x7,0x0,0x0,0x0, + 0x32,0x7,0x0,0x0,0x0, + 0x34,0x7,0x0,0x0,0x0, + 0x38,0x7,0x0,0x0,0x0, + 0x38,0xb,0x0,0x0,0x0, + 0x38,0x13,0x0,0x0,0x0, + 0x38,0x23,0x0,0x0,0x0, + 0x38,0x3,0x1,0x0,0x0, + 0x38,0x23,0x0,0x0,0x0, + 0x38,0x13,0x0,0x0,0x0, + 0x38,0xb,0x0,0x0,0x0, + 0x38,0x7,0x0,0x0,0x0, + 0x34,0x7,0x0,0x0,0x0, + 0x32,0x7,0x0,0x0,0x0, + 0x31,0x7,0x0,0x0,0x0 + } + }; + + + // Main loop + while (true) + { + animation_num = new_animation_num; + + // Algorithmic animation + if (animation_num == 10) + { + // fade + if (dir == 1) + cnt--; + else + cnt++; + + if (dir == 1 && cnt == 0) + dir = 0; + + else if (dir == 0 && cnt == 15) + dir = 1; + + for (j = 1; j < 8; j++) + driver.maxSingle(j, 0xFF); + + driver.maxSingle(0x0a, (byte)(cnt & 0x0f)); + + Thread.Sleep(15); + } // Algorithmic animation + else if (animation_num == 9) + { + for (j = 1; j < 6; j++) + { + l = 1; + for (k = 1; k < 6; k++) + if (k != j) + driver.maxSingle(k, 0); + for (i = 0; i < 6; i++) + { + driver.maxSingle(j, bitwise[i]); + } + } + } + else // non algorithmic animation, uses bit data from animation arrays + { + for (i = 0; i < animations[animation_num].Length; i++) + { + driver.maxSingle((byte)((i % 5) + 1), animations[animation_num][i]); + } + } + } + } + + + + //Interrupt Handler for changeBtn to change annimations + static void changeBtn_OnInterrupt(uint data1, uint data2, DateTime time) + { + if (++new_animation_num > animation_total) + { + new_animation_num = 0; + } + driver.maxSingle(0x0a, 0x0f & 0x0f); // reset intensity to max + + Debug.Print("Animation Num: "); + Debug.Print(new_animation_num.ToString()); + + } + + static void dockBtn_OnInterrupt(uint data1, uint data2, DateTime time) + { + if (data2 == 1) + new_animation_num = 10; + else + new_animation_num = 0; + + driver.maxSingle(0x0a, 0x0f & 0x0f); // reset intensity to max + + Debug.Print(data2.ToString()); + + Debug.Print("Animation Num: "); + Debug.Print(new_animation_num.ToString()); + } + } +} diff --git a/TronDisc Netduino Code/TronDisc/Properties/AssemblyInfo.cs b/TronDisc Netduino Code/TronDisc/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..d394699 --- /dev/null +++ b/TronDisc Netduino Code/TronDisc/Properties/AssemblyInfo.cs @@ -0,0 +1,25 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("TronDisc")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("TronDisc")] +[assembly: AssemblyCopyright("Copyright © 2010")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/TronDisc Netduino Code/TronDisc/TronDisc.csproj b/TronDisc Netduino Code/TronDisc/TronDisc.csproj new file mode 100644 index 0000000..09cf07c --- /dev/null +++ b/TronDisc Netduino Code/TronDisc/TronDisc.csproj @@ -0,0 +1,43 @@ + + + + TronDisc + Exe + TronDisc + {b69e3092-b931-443c-abe7-7e7b65f2a37f};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + 9.0.21022 + 2.0 + {209B3EC6-E705-4A65-B438-EB4A45EF8299} + v4.1 + $(MSBuildExtensionsPath32)\Microsoft\.NET Micro Framework\ + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + \ No newline at end of file diff --git a/TronDisc Netduino Code/TronDisc/max7219.cs b/TronDisc Netduino Code/TronDisc/max7219.cs new file mode 100644 index 0000000..a0543cb --- /dev/null +++ b/TronDisc Netduino Code/TronDisc/max7219.cs @@ -0,0 +1,83 @@ +using System; +using System.Threading; +using Microsoft.SPOT; +using Microsoft.SPOT.Hardware; +using SecretLabs.NETMF.Hardware; +using SecretLabs.NETMF.Hardware.Netduino; +using System.Collections; + +namespace TronDisc +{ + public class max7219 + { + // Pin ports for spi + private OutputPort loadPin; + private OutputPort dataPin; + private OutputPort clkPin; + + // Command reference + private byte max7219_reg_noop = 0x00; + private byte max7219_reg_digit0 = 0x01; + private byte max7219_reg_digit1 = 0x02; + private byte max7219_reg_digit2 = 0x03; + private byte max7219_reg_digit3 = 0x04; + private byte max7219_reg_digit4 = 0x05; + private byte max7219_reg_digit5 = 0x06; + private byte max7219_reg_digit6 = 0x07; + private byte max7219_reg_digit7 = 0x08; + private byte max7219_reg_decodeMode = 0x09; + private byte max7219_reg_intensity = 0x0a; + private byte max7219_reg_scanLimit = 0x0b; + private byte max7219_reg_shutdown = 0x0c; + private byte max7219_reg_displayTest = 0x0f; + + // Constructor, pass pin definitions + public max7219(OutputPort in_dataPin, OutputPort in_clockPin, OutputPort in_loadPin) + { + // Assign local port pins to ports passed from constructor + dataPin = in_dataPin; + clkPin = in_clockPin; + loadPin = in_loadPin; + + maxSingle(max7219_reg_scanLimit, 0x07); // set scan limit + maxSingle(max7219_reg_decodeMode, 0x00); // using an led matrix mode (not digits) + maxSingle(max7219_reg_shutdown, 0x01); // not in shutdown mode + maxSingle(max7219_reg_displayTest, 0x00); // no display test + maxSingle(max7219_reg_intensity, 0x0f); // set max intensity (range 00-0f) + } + + // Transmits 1 byte over SPI, bitbang method + public void putByte(byte data) + { + byte i = 8; + int mask; + + while (i > 0) + { + mask = (1 << i - 1); + clkPin.Write(false); + if (((int)data & mask) == 0) + dataPin.Write(false); + else + dataPin.Write(true); + clkPin.Write(true); + --i; + } + } + + // Sends 1 Command / Data pair to a single driver chip + public void maxSingle(byte reg, byte col) + { + // LOAD low + loadPin.Write(false); + + // Transmit Register + putByte(reg); + // Transmit Column + putByte(col); + + // LOAD high latches data sent + loadPin.Write(true); + } + } +}