Advertisement
Guest User

Untitled

a guest
Aug 13th, 2013
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.29 KB | None | 0 0
  1. using System;
  2. using Microsoft.SPOT;
  3. using System.Net.Sockets;
  4. using System.Threading;
  5. using Microsoft.SPOT.Hardware;
  6. using SecretLabs.NETMF.Hardware;
  7. using SecretLabs.NETMF.Hardware.Netduino;
  8.  
  9. namespace NetduinoApplication2
  10. {
  11.     class Display
  12.     {
  13.         private bool on, off;
  14.  
  15.         public static OutputPort D0 = new OutputPort(Pins.GPIO_PIN_D0, false);
  16.         public static OutputPort D1 = new OutputPort(Pins.GPIO_PIN_D1, false);
  17.         public static OutputPort D2 = new OutputPort(Pins.GPIO_PIN_D2, false);
  18.         public static OutputPort D3 = new OutputPort(Pins.GPIO_PIN_D3, false);
  19.         public static OutputPort D4 = new OutputPort(Pins.GPIO_PIN_D4, false);
  20.         public static OutputPort D5 = new OutputPort(Pins.GPIO_PIN_D5, false);
  21.         public static OutputPort D6 = new OutputPort(Pins.GPIO_PIN_D6, false);
  22.         public static OutputPort D7 = new OutputPort(Pins.GPIO_PIN_D7, false);
  23.  
  24.         public static OutputPort rightDigit = new OutputPort(Pins.GPIO_PIN_D9, false);
  25.         public static OutputPort leftDigit = new OutputPort(Pins.GPIO_PIN_D10, false);
  26.  
  27.  
  28.         public void Reset() // resets display to off
  29.         {
  30.             D0.Write(off);
  31.             D1.Write(off);
  32.             D2.Write(off);
  33.             D3.Write(off);
  34.             D4.Write(off);
  35.             D5.Write(off);
  36.             D6.Write(off);
  37.             D7.Write(off);
  38.         }
  39.  
  40.  
  41.         public void Write(string inputString)
  42.         {
  43.             if (inputString.Length == 1)
  44.             {
  45.                 bool[] temp = CharacterCode(inputString);
  46.  
  47.                 rightDigit.Write(true);  // picks which digit to write to
  48.  
  49.                 D0.Write(temp[0]);
  50.                 D1.Write(temp[1]);
  51.                 D2.Write(temp[2]);
  52.                 D3.Write(temp[3]);
  53.                 D4.Write(temp[4]);
  54.                 D5.Write(temp[5]);
  55.                 D6.Write(temp[6]);
  56.             }
  57.  
  58.         }
  59.  
  60.         public void Write(int input)
  61.         {
  62.             string inputString = input.ToString();
  63.  
  64.             if (inputString.Length == 1)
  65.             {
  66.                 bool[] temp = CharacterCode(inputString);
  67.  
  68.                 rightDigit.Write(true); // picks which digit to write to
  69.  
  70.                 D0.Write(temp[0]);
  71.                 D1.Write(temp[1]);
  72.                 D2.Write(temp[2]);
  73.                 D3.Write(temp[3]);
  74.                 D4.Write(temp[4]);
  75.                 D5.Write(temp[5]);
  76.                 D6.Write(temp[6]);
  77.             }        
  78.  
  79.         }
  80.  
  81.  
  82.         public void Mode(string mode) // configuration for common anode or common cathode displays
  83.         {
  84.             if (mode == "commonAnode")
  85.             {
  86.                 on = false;
  87.                 off = true;
  88.             }
  89.             else if (mode == "commonCathode")
  90.             {
  91.                 on = true;
  92.                 off = false;
  93.             }
  94.             this.Reset(); // resets the display to off when the mode is set
  95.         }
  96.  
  97.  
  98.         private bool[] CharacterCode(string charInput)  // returns an array of booleans to code for a character
  99.         {
  100.             switch (charInput)
  101.             {
  102.                 // Segments of the display
  103.                 //                   A   B   C   D   E   F   G      
  104.                 case "0":
  105.                     bool[] num0 = { on, on, on, on, on, on, off };
  106.                     return num0;
  107.  
  108.                 case "1":
  109.                     bool[] num1 = { off, on, on, off, off, off, off };
  110.                     return num1;
  111.  
  112.                 case "2":
  113.                     bool[] num2 = { on, on, off, on, on, off, on };
  114.                     return num2;
  115.  
  116.                 case "3":
  117.                     bool[] num3 = { on, on, on, on, off, off, on };
  118.                     return num3;
  119.  
  120.                 case "4":
  121.                     bool[] num4 = { off, on, on, off, off, on, on };
  122.                     return num4;
  123.  
  124.                 case "5":
  125.                     bool[] num5 = { on, off, on, on, off, on, on };
  126.                     return num5;
  127.  
  128.                 case "6":
  129.                     bool[] num6 = { on, off, on, on, on, on, on };
  130.                     return num6;
  131.  
  132.                 case "7":
  133.                     bool[] num7 = { on, on, on, off, off, off, off };
  134.                     return num7;
  135.  
  136.                 case "8":
  137.                     bool[] num8 = { on, on, on, on, on, on, on };
  138.                     return num8;
  139.  
  140.                 case "9":
  141.                     bool[] num9 = { on, on, on, off, off, on, on };
  142.                     return num9;
  143.  
  144.                 case "A":
  145.                     bool[] A = { on, on, on, off, on, on, on };
  146.                     return A;
  147.  
  148.                 case "B":
  149.                     bool[] B = { on, on, on, on, on, on, on };
  150.                     return B;
  151.  
  152.                 case "C":
  153.                     bool[] C = { on, off, off, on, on, on, off };
  154.                     return C;
  155.  
  156.                 case "D":
  157.                     bool[] D = { on, on, on, on, on, on, off };
  158.                     return D;
  159.  
  160.                 case "E":
  161.                     bool[] E = { on, off, off, on, on, on, on };
  162.                     return E;
  163.  
  164.                 default:
  165.                     bool[] error = { off, off, off, off, off, off, off };
  166.                     return error;
  167.             }
  168.         }
  169.  
  170.  
  171.     }
  172. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement