Hello all,
I am trying to get this program to work for me, but since i'm a noob, I'm probably misunderstanding something here.
I am getting an error saying "An object reference is required for the non-static field, method, or property 'NetduinoPlusApplication1.Program.Inputs()' " and the same with "...Program.Pressure()"
I don't know how to fix this. My code is below. Thanks.
namespace NetduinoPlusApplication1{ public class Program { double VAvgi = 0; double VAvgj = 0; double DeltaVAvg; double VAvgOut; double Dev = 0.01; double tempC; double Rho; double g = 9.81; double calOffset; double PCorrect; double PRead; double calVol; double calPress; double V; double h; public static void Main() { Thread t1 = new Thread(Inputs); t1.Start(); Thread t3 = new Thread(Pressure); t3.Start(); } public void Inputs() { InputPort ReadButton = new InputPort(Pins.GPIO_PIN_D0, false, Port.ResistorMode.PullUp); InputPort CalButton = new InputPort(Pins.GPIO_PIN_D1, false, Port.ResistorMode.PullUp); bool ReadState = false; bool CalState = false; calVol = 1.000; // 1000mL or 1L while (true) { ReadState = !ReadButton.Read(); CalState = !CalButton.Read(); if (ReadState == true) { if (DeltaVAvg <= Dev) { Debug.Print("Value read"); VAvgj = VAvgOut; Thread.Sleep(2000); Debug.Print("Calculated volume of sample is" + VAvgOut); Thread.Sleep(Timeout.Infinite); //Need some way to reset to measure another sample or remeasure.... like a press Enter to Continue or something.... } else { } } if (CalState == true) { if (DeltaVAvg <= Dev) { Debug.Print("Calibrating..."); calVol = Rho * g * (calVol / (4 * System.Math.PI)); calOffset = calVol - PRead; Debug.Print("Calibrated"); } else { Debug.Print("Failed. Please wait till settled"); } } else { } Thread.Sleep(1000); } } public void Pressure() { AnalogInput PT = new AnalogInput(Pins.GPIO_PIN_A1); AnalogInput Tmp36 = new AnalogInput(Pins.GPIO_PIN_A0); OutputPort GLed = new OutputPort(Pins.GPIO_PIN_D2, true); OutputPort RLed = new OutputPort(Pins.GPIO_PIN_D3, true); int sampleSize = 10; Queue rawQueue = new Queue(); Queue avgQueue = new Queue(); while (true) { V = Tmp36.Read() * 3.3 / 1024; tempC = (100 * V) - 50; Rho = -0.0055 * ((tempC) * (tempC)) + 0.0157 * (tempC) + 1000.1; PRead = PT.Read() * 5 / 1024; PCorrect = PRead + calOffset; h = PCorrect / (Rho * g); V = 4 * System.Math.PI * h; while(rawQueue.Count != sampleSize) { rawQueue.Enqueue(V); } while(rawQueue.Count == sampleSize) { rawQueue.Enqueue(V); rawQueue.Dequeue(); double sum = 0; foreach (double d in rawQueue) { sum += d; } VAvgi = VAvgj; VAvgj = sum/sampleSize; } double diffAvg; diffAvg = (VAvgi - VAvgj); if (diffAvg < 0) { DeltaVAvg = diffAvg * -1; } else { DeltaVAvg = diffAvg; } if (DeltaVAvg <= Dev) { GLed.Write(!true); Thread.Sleep(700); GLed.Write(!false); Thread.Sleep(300); } else { RLed.Write(!true); Thread.Sleep(200); RLed.Write(!false); Thread.Sleep(800); } } } }}