Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using Microsoft.SPOT;
- using System.Net.Sockets;
- using System.Threading;
- using Microsoft.SPOT.Hardware;
- using SecretLabs.NETMF.Hardware;
- using SecretLabs.NETMF.Hardware.Netduino;
- namespace NetduinoApplication2
- {
- class Display
- {
- private bool on, off;
- public static OutputPort D0 = new OutputPort(Pins.GPIO_PIN_D0, false);
- public static OutputPort D1 = new OutputPort(Pins.GPIO_PIN_D1, false);
- public static OutputPort D2 = new OutputPort(Pins.GPIO_PIN_D2, false);
- public static OutputPort D3 = new OutputPort(Pins.GPIO_PIN_D3, false);
- public static OutputPort D4 = new OutputPort(Pins.GPIO_PIN_D4, false);
- public static OutputPort D5 = new OutputPort(Pins.GPIO_PIN_D5, false);
- public static OutputPort D6 = new OutputPort(Pins.GPIO_PIN_D6, false);
- public static OutputPort D7 = new OutputPort(Pins.GPIO_PIN_D7, false);
- public static OutputPort rightDigit = new OutputPort(Pins.GPIO_PIN_D9, false);
- public static OutputPort leftDigit = new OutputPort(Pins.GPIO_PIN_D10, false);
- public void Reset() // resets display to off
- {
- D0.Write(off);
- D1.Write(off);
- D2.Write(off);
- D3.Write(off);
- D4.Write(off);
- D5.Write(off);
- D6.Write(off);
- D7.Write(off);
- }
- public void Write(string inputString)
- {
- if (inputString.Length == 1)
- {
- bool[] temp = CharacterCode(inputString);
- rightDigit.Write(true); // picks which digit to write to
- D0.Write(temp[0]);
- D1.Write(temp[1]);
- D2.Write(temp[2]);
- D3.Write(temp[3]);
- D4.Write(temp[4]);
- D5.Write(temp[5]);
- D6.Write(temp[6]);
- }
- }
- public void Write(int input)
- {
- string inputString = input.ToString();
- if (inputString.Length == 1)
- {
- bool[] temp = CharacterCode(inputString);
- rightDigit.Write(true); // picks which digit to write to
- D0.Write(temp[0]);
- D1.Write(temp[1]);
- D2.Write(temp[2]);
- D3.Write(temp[3]);
- D4.Write(temp[4]);
- D5.Write(temp[5]);
- D6.Write(temp[6]);
- }
- }
- public void Mode(string mode) // configuration for common anode or common cathode displays
- {
- if (mode == "commonAnode")
- {
- on = false;
- off = true;
- }
- else if (mode == "commonCathode")
- {
- on = true;
- off = false;
- }
- this.Reset(); // resets the display to off when the mode is set
- }
- private bool[] CharacterCode(string charInput) // returns an array of booleans to code for a character
- {
- switch (charInput)
- {
- // Segments of the display
- // A B C D E F G
- case "0":
- bool[] num0 = { on, on, on, on, on, on, off };
- return num0;
- case "1":
- bool[] num1 = { off, on, on, off, off, off, off };
- return num1;
- case "2":
- bool[] num2 = { on, on, off, on, on, off, on };
- return num2;
- case "3":
- bool[] num3 = { on, on, on, on, off, off, on };
- return num3;
- case "4":
- bool[] num4 = { off, on, on, off, off, on, on };
- return num4;
- case "5":
- bool[] num5 = { on, off, on, on, off, on, on };
- return num5;
- case "6":
- bool[] num6 = { on, off, on, on, on, on, on };
- return num6;
- case "7":
- bool[] num7 = { on, on, on, off, off, off, off };
- return num7;
- case "8":
- bool[] num8 = { on, on, on, on, on, on, on };
- return num8;
- case "9":
- bool[] num9 = { on, on, on, off, off, on, on };
- return num9;
- case "A":
- bool[] A = { on, on, on, off, on, on, on };
- return A;
- case "B":
- bool[] B = { on, on, on, on, on, on, on };
- return B;
- case "C":
- bool[] C = { on, off, off, on, on, on, off };
- return C;
- case "D":
- bool[] D = { on, on, on, on, on, on, off };
- return D;
- case "E":
- bool[] E = { on, off, off, on, on, on, on };
- return E;
- default:
- bool[] error = { off, off, off, off, off, off, off };
- return error;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement