Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Threading;
- using Komodex.NETMF;
- using Microsoft.SPOT;
- using NetduinoGo;
- namespace NetduinoGo_TestProject
- {
- public class Program
- {
- private static SevenSegmentDisplay display = new SevenSegmentDisplay();
- private static bool F = true;
- public static void Main()
- {
- Potentiometer sensor = new Potentiometer();
- Button button = new Button();
- button.ButtonReleased += new Button.ButtonEventHandler(button_ButtonReleased);
- display.SetBrightness((float)0.5);
- display.SetApostrophe(true);
- double Tc = 19.5;
- int V0c = 400;
- double Ta = 0;
- double raw = 0;
- double Vdiv = (3.3/1023);
- while(true)
- {
- raw = (sensor.GetValue() / Vdiv) * 10;
- //Vout = Tc*Ta+V0c
- //Tc = Temperature Coefficient
- //Ta = Ambient Temperature
- //V0c = Output at 0C
- Ta = (raw - V0c)/Tc;
- //Debug.Print(raw + " : " + Ta.ToString());
- if(F)
- UpdateDisplay(ConvertCtoF(Ta));
- else
- UpdateDisplay(Ta);
- Thread.Sleep(250);
- }
- }
- static void button_ButtonReleased(object sender, bool buttonState)
- {
- F = !F;
- }
- public static double ConvertCtoF(double c)
- {
- return c * 1.8 + 32;
- }
- public static void UpdateDisplay(double value)
- {
- if (value >= 1000)
- throw new ArgumentOutOfRangeException("value");
- string v = value.ToString();//.ToCharArray();
- Digit[] output = new Digit[3];
- if(value < 100)
- {
- output[0] = DivineDigit(v[0].ToString());
- output[1] = (Digit)((byte)DivineDigit(v[1].ToString()) | (byte)Segment.Dp);
- output[2] = DivineDigit(v[3].ToString());
- }
- if(F)
- display.SetValue(output[0], output[1], output[2], (Digit)Letters.F);
- else
- display.SetValue(output[0], output[1], output[2], (Digit)Letters.C);
- }
- public static Digit DivineDigit(string value)
- {
- Digit output;
- if (value == "9")
- {
- output = Digit.D9;
- }
- else if (value == "8")
- {
- output = Digit.D8;
- }
- else if (value == "7")
- {
- output = Digit.D7;
- }
- else if (value == "6")
- {
- output = Digit.D6;
- }
- else if (value == "5")
- {
- output = Digit.D5;
- }
- else if (value == "4")
- {
- output = Digit.D4;
- }
- else if (value == "3")
- {
- output = Digit.D3;
- }
- else if (value == "2")
- {
- output = Digit.D2;
- }
- else if (value == "1")
- {
- output = Digit.D1;
- }
- else
- output = Digit.D0;
- return output;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment