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;
- OutputPort a = new OutputPort(Pins.GPIO_PIN_D0, false);
- OutputPort b = new OutputPort(Pins.GPIO_PIN_D1, false);
- OutputPort c = new OutputPort(Pins.GPIO_PIN_D2, false);
- OutputPort d = new OutputPort(Pins.GPIO_PIN_D3, false);
- OutputPort e = new OutputPort(Pins.GPIO_PIN_D4, false);
- OutputPort f = new OutputPort(Pins.GPIO_PIN_D5, false);
- OutputPort g = new OutputPort(Pins.GPIO_PIN_D6, false);
- OutputPort point = 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
- {
- a.Write(off);
- b.Write(off);
- c.Write(off);
- d.Write(off);
- e.Write(off);
- f.Write(off);
- g.Write(off);
- point.Write(off);
- }
- public void Write(string inputString)
- {
- // turns off both digits
- rightDigit.Write(false);
- leftDigit.Write(false);
- if (inputString.Length == 1)
- {
- bool[] temp = CharacterCode(inputString);
- rightDigit.Write(true); // picks which digit to write to
- a.Write(temp[0]);
- b.Write(temp[1]);
- c.Write(temp[2]);
- d.Write(temp[3]);
- e.Write(temp[4]);
- f.Write(temp[5]);
- g.Write(temp[6]);
- }
- // seperates the input to two characters and gets their codes for the display
- bool[] digit1 = CharacterCode(inputString.Substring(0, 1));
- bool[] digit2 = CharacterCode(inputString.Substring(1, 1));
- Debug.Print("inputString: " + inputString);
- Debug.Print("substring 0: " + inputString.Substring(0, 1));
- Debug.Print("substring 1: " + inputString.Substring(1, 1));
- while (true) // updates the display to show the 2 digit number, switching between them quickly
- // How do I do this in another thread until an update is 'pushed' to the display?
- {
- leftDigit.Write(false);
- a.Write(digit2[0]);
- b.Write(digit2[1]);
- c.Write(digit2[2]);
- d.Write(digit2[3]);
- e.Write(digit2[4]);
- f.Write(digit2[5]);
- g.Write(digit2[6]);
- rightDigit.Write(true);
- Thread.Sleep(5);
- rightDigit.Write(false);
- a.Write(digit1[0]);
- b.Write(digit1[1]);
- c.Write(digit1[2]);
- d.Write(digit1[3]);
- e.Write(digit1[4]);
- f.Write(digit1[5]);
- g.Write(digit1[6]);
- leftDigit.Write(true);
- Thread.Sleep(5);
- }
- }
- public void Write(int input)
- {
- Write(input.ToString());
- }
- 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;
- case "F":
- bool[] F = { on, off, off, off, on, on, on };
- return F;
- case "G":
- bool[] G = { on, off, on, on, on, on, on };
- return G;
- case "H":
- bool[] H = { off, on, on, off, on, on, on };
- return H;
- case "I":
- bool[] I = { off, on, on, off, off, off, off };
- return I;
- default:
- bool[] error = { off, off, off, off, off, off, off };
- return error;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement