protected void MoveRight() { _pinRight.Write(true); Thread.Sleep(400); _pinRight.Write(false); Log("move right"); }
protected void MoveLeft() { _pinLeft.Write(true); Thread.Sleep(400); _pinLeft.Write(false); Log("move left"); }
protected void MoveDown() { _pinDown.Write(true); Thread.Sleep(100); _pinDown.Write(false); Log("move down"); }
protected void MoveUp() { _pinUp.Write(true); Thread.Sleep(100); _pinUp.Write(false); Log("move up"); }
private void TurnLeft() { _pinLeftEngineBackward.Write(true); _pinRightEngineForward.Write(true); Thread.Sleep(200); _pinLeftEngineBackward.Write(false); _pinRightEngineForward.Write(false); Log("Turn left"); }
public void OneLed(int dauer) { GPIOMem led = new GPIOMem(GPIOPins.GPIO_18, GPIODirection.Out); while (true) { led.Write(PinState.High); System.Threading.Thread.Sleep(dauer); led.Write(PinState.Low); System.Threading.Thread.Sleep(dauer); } }
/// <summary> /// Write either command or data, with automatic 4/8-bit selection /// </summary> /// <param name="value">value to write</param> /// <param name="mode">Mode for RS (register select) pin.</param> /// <param name="backlight">Backlight state.</param> public void Send(byte value, bool mode, bool backlight) { if (_disposed) { throw new ObjectDisposedException("NetopiaGPIOLcdTransferProvider"); } //TODO: set backlight _rsPort.Write(mode); // if there is a RW pin indicated, set it low to Write if (_rwPort != null) { _rwPort.Write(false); } if (!_fourBitMode) { Write8Bits(value); } else { Write4Bits((byte)(value >> 4)); Write4Bits(value); } }
/// <summary> /// Called for checking interrupts on specified pin. /// </summary> static void interruptCheck() { while (true) { if ((DateTime.Now - LEDTimer).TotalSeconds > 3) { LED_On = !LED_On; led.Write(LED_On); LEDTimer = DateTime.Now; } var pinState = pin.Read(); if (lastInterruptState != pinState) { lastInterruptState = pinState; Interrupt(); } Thread.Sleep(1); /*Interrupt (); * Thread.Sleep (20);*/ } }
/// <summary> /// Called when Power Out CB changes or when Power Default CB changes. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void cb_PowerSensorOut_CheckedChanged(object sender, EventArgs e) { if (!(powerSensor is null)) { powerSensor.Write(!(cb_GPIO_PWR_Default.Checked ^ cb_PowerSensorOut.Checked)); } }
public void BlinkyMain() { //display.Write ("Hallo"); //GPIOPins.GPIO_17 = GPIO17 auf PIN11 GPIOMem pin11 = new GPIOMem(GPIOPins.GPIO_17); GPIOMem button = new GPIOMem(GPIOPins.GPIO_18, GPIODirection.In); button.Write(PinState.High); pin11.Write(PinState.Low); int power = 1; int pause = 1; bool toggle = true; while (true) { if (button.Read() == PinState.Low) { //test (); if (toggle) { power++; } else { power--; }; Console.WriteLine("Power;{0} Pause:{1}", power.ToString(), pause.ToString()); pause = power / 2; if (power == 20 || power == 0) { toggle = !toggle; Console.Write(toggle.ToString()); } System.Threading.Thread.Sleep(5); } pin11.Write(PinState.High); System.Threading.Thread.Sleep(pause); pin11.Write(PinState.Low); System.Threading.Thread.Sleep(power); } }
public string RequestListener(HttpListenerRequest request) { GPIOMem gpio = null; string rtnValue = null; try { // log out requests for debugging Console.WriteLine(request.Url); // set pin direction via "dir" argument GPIODirection dir = (GPIODirection)((new[] { "OUT", "TRUE", "1" }).Contains(request.QueryString["dir"].ToUpper()) ? 1 : 0); // set pin number via "pin" argument GPIOPins pin = (GPIOPins)int.Parse(request.QueryString["pin"]); gpio = new GPIOMem((GPIOPins)pin, dir); if (dir == GPIODirection.Out) { // set pin state via "state" argument bool state = (new[] { "HIGH", "1", "TRUE", "T" }).Contains(request.QueryString["state"].ToUpper()); gpio.Write(state); rtnValue = state.ToString(); } else { rtnValue = (gpio.Read() == PinState.High).ToString(); } } catch (Exception ex) { Console.WriteLine("ERROR:"); Console.WriteLine(ex.Message); Console.WriteLine(ex.Source); Console.WriteLine(ex.StackTrace); rtnValue = "ERROR"; } finally { gpio.Dispose(); } return(rtnValue); }
private void PulseEnable() { _enablePort.Write(false); _enablePort.Write(true); // enable pulse must be >450ns _enablePort.Write(false); // commands need > 37us to settle }
/// <summary> /// Called whenever pin state goes from High to Low or vice-versa. /// </summary> static void Interrupt() { /* Prevent from maximum size collision. */ if (triggerCount >= Int32.MaxValue - 1024) { triggerCount = 0; } if (pulses >= Int32.MaxValue - 1024) { pulses = 0; } /* Calibration. */ if (calibrating) { triggerCount++; WriteMultidimensionalPacket(OpCodes.CaliberTransmit, triggerCount); } else if (projectStarted) { /* Preform no caliber (single caliber) triggers and pulses. */ if (caliberNumber <= 1) { triggerCount++; new Thread(() => { flash.Write(true); Thread.Sleep(1); flash.Write(false); }).Start(); WriteMultidimensionalPacket(OpCodes.Trigger, triggerCount); /* Display console information every 500 trigs. */ if (triggerCount % 500 == 0) { WriteLineNoLog("Performing trigger: " + triggerCount.ToString() + "."); } } else { /* Calculate pulses and trigger, then decide to send it or not. */ pulses++; if (pulses >= caliberNumber) { triggerCount++; pulses = 0; new Thread(() => { flash.Write(true); Thread.Sleep(1); flash.Write(false); }).Start(); WriteMultidimensionalPacket(OpCodes.Trigger, triggerCount); /* Display console information every 500 trigs. */ if (triggerCount % 500 == 0) { WriteLineNoLog("Performing trigger: " + triggerCount.ToString() + "."); } } } } }
public void Execute(params object[] list) { string MType = ((string)list [0]); switch (MType) { case "READ_TEMPERATURE": GPIOPins X1 = (GPIOPins)Enum.Parse(typeof(GPIOPins), (string)list [1], true); GPIOFile Sensor1 = new GPIOFile(X1); break; case "READ_LUMINANCE": GPIOPins X2 = (GPIOPins)Enum.Parse(typeof(GPIOPins), (string)list [1], true); GPIOFile Sensor2 = new GPIOFile(X2); break; case "READ_HUMIDITY": GPIOPins X3 = (GPIOPins)Enum.Parse(typeof(GPIOPins), (string)list [1], true); GPIOFile Sensor3 = new GPIOFile(X3); break; case "READ_PRESSURE": GPIOPins X4 = (GPIOPins)Enum.Parse(typeof(GPIOPins), (string)list [1], true); GPIOFile Sensor4 = new GPIOFile(X4); break; case "LEDON": new System.Threading.Thread(delegate() { GPIOPins X = (GPIOPins)Enum.Parse(typeof(GPIOPins), (string)list [1], true); GPIOMem led = new GPIOMem(X); led.Write(PinState.High); }).Start(); break; case "LEDOFF": new System.Threading.Thread(delegate() { GPIOPins X = (GPIOPins)Enum.Parse(typeof(GPIOPins), (string)list [1], true); GPIOMem led = new GPIOMem(X); led.Write(PinState.Low); }).Start(); break; case "LEDBLINK_SLOW": new System.Threading.Thread(delegate() { GPIOPins X = (GPIOPins)Enum.Parse(typeof(GPIOPins), (string)list [1], true); GPIOMem led = new GPIOMem(X); for (int i = 0; i < (int.Parse((string)list [2])); i++) { led.Write(PinState.High); System.Threading.Thread.Sleep(500); led.Write(PinState.Low); System.Threading.Thread.Sleep(500); } }).Start(); break; case "LEDBLINK_FAST": new System.Threading.Thread(delegate() { GPIOPins X = (GPIOPins)Enum.Parse(typeof(GPIOPins), (string)list [1], true); GPIOMem led = new GPIOMem(X); for (int i = 0; i < (int.Parse((string)list [2])); i++) { led.Write(PinState.High); System.Threading.Thread.Sleep(250); led.Write(PinState.Low); System.Threading.Thread.Sleep(250); led.Write(PinState.High); System.Threading.Thread.Sleep(250); led.Write(PinState.Low); System.Threading.Thread.Sleep(250); } }).Start(); break; case "LEDBLINK_UFAST": new System.Threading.Thread(delegate() { GPIOPins X = (GPIOPins)Enum.Parse(typeof(GPIOPins), (string)list [1], true); GPIOMem led = new GPIOMem(X); for (int i = 0; i < (int.Parse((string)list [2])); i++) { led.Write(PinState.High); System.Threading.Thread.Sleep(125); led.Write(PinState.Low); System.Threading.Thread.Sleep(125); led.Write(PinState.High); System.Threading.Thread.Sleep(125); led.Write(PinState.Low); System.Threading.Thread.Sleep(125); led.Write(PinState.High); System.Threading.Thread.Sleep(125); led.Write(PinState.Low); System.Threading.Thread.Sleep(125); led.Write(PinState.High); System.Threading.Thread.Sleep(125); led.Write(PinState.Low); System.Threading.Thread.Sleep(125); } }).Start(); break; } }
/// <summary> /// Is called as a thread. Manages turning on and off the GPIOs as set by static variables above. /// </summary> /// <param name="sensor">If false, use sensor 1 and 2 otherwise 3 and 4</param> private static void RunPulseGen(bool sensor) { var sw = new System.Diagnostics.Stopwatch(); sw.Reset(); while (!sensor ? run1 : run2) { sw.Reset(); sw.Start(); // start pulse 1 bool boolExpr = false; int sleepTime = 0; if (!sensor) { if (!(rotationSensor1_1 is null)) { rotationSensor1_1.Write(!s1_default); } // determine which comes first: start pulse 2 or stop pulse 1 boolExpr = pulseLength1 < delay1; } else { if (!(rotationSensor2_1 is null)) { rotationSensor2_1.Write(!s1_default); } // determine which comes first: start pulse 2 or stop pulse 1 boolExpr = pulseLength2 < delay2; } if (boolExpr) { // S1: ****________... // S2: ______****__... // // stop pulse 1 sleepTime = !sensor ? pulseLength1 : pulseLength2; Thread.Sleep(sleepTime); if (!sensor) { if (!(rotationSensor1_1 is null)) { rotationSensor1_1.Write(s1_default); } } else { if (!(rotationSensor2_1 is null)) { rotationSensor2_1.Write(s1_default); } } // do pulse 2 // pulseLength1 is over, but measure for more accuracy { sleepTime = (!sensor ? delay1 : delay2) - (int)sw.ElapsedMilliseconds; if (sleepTime > 0) { Thread.Sleep(sleepTime); } } if (!sensor) { if (!(rotationSensor1_2 is null)) { rotationSensor1_2.Write(!s2_default); } // sleep until pulse duration over sleepTime = pulseLength1; } else { if (!(rotationSensor2_2 is null)) { rotationSensor2_2.Write(!s2_default); } sleepTime = pulseLength2; } Thread.Sleep(sleepTime); // stop pulse 2 if (!sensor) { if (!(rotationSensor1_2 is null)) { rotationSensor1_2.Write(s2_default); } } else { if (!(rotationSensor2_2 is null)) { rotationSensor2_2.Write(s2_default); } } } else { // S1: ****______... // S2: __****____... // pulse 2 starts first, pulse 1 still running sleepTime = (!sensor ? delay1 : delay2); Thread.Sleep(sleepTime); if (!sensor) { if (!(rotationSensor2_2 is null)) { rotationSensor2_2.Write(!s2_default); } } else { if (!(rotationSensor2_2 is null)) { rotationSensor2_2.Write(!s2_default); } } // sleep till stop of pulse 1 sleepTime = !sensor ? pulseLength1 - delay1 : pulseLength2 - delay2; if (sleepTime > 0) { Thread.Sleep(sleepTime); } // stop pulse 1 if (!sensor) { if (!(rotationSensor1_1 is null)) { rotationSensor1_1.Write(s1_default); } } else { if (!(rotationSensor2_1 is null)) { rotationSensor2_1.Write(s1_default); } } // sleep till end of pulse 2 sleepTime = (!sensor ? pulseLength1 : pulseLength2) - ((int)sw.ElapsedMilliseconds - (!sensor ? delay1 : delay2)); if (sleepTime > 0) { Thread.Sleep(sleepTime); } // stop pulse 2 if (!sensor) { if (!(rotationSensor1_2 is null)) { rotationSensor1_2.Write(s2_default); } } else { if (!(rotationSensor2_2 is null)) { rotationSensor2_2.Write(s2_default); } } } // sleep for the rest of the cycle, measure time for more accuracy // TODO: random pulses sleepTime = cycleLength1 - (int)sw.ElapsedMilliseconds; if (sleepTime > 0) { Thread.Sleep(sleepTime); } } // \while(!sensor ? run1 : run2) // if (!sensor) { if (!(rotationSensor1_1 is null)) { rotationSensor1_1.Write(false); } if (!(rotationSensor1_2 is null)) { rotationSensor1_2.Write(false); } } else { if (!(rotationSensor2_1 is null)) { rotationSensor2_1.Write(false); } if (!(rotationSensor2_2 is null)) { rotationSensor2_2.Write(false); } } }