/// <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);*/ } }
static void Main(string[] args) { Console.WriteLine("Hello Raspberry Pi"); GPIOMem button = new GPIOMem(GPIOPins.V2_Pin_P1_16); while (true) { Console.WriteLine(button.Read().ToString()); } }
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); }
public static string GetStatus(HttpListenerRequest request) { bool occupied = false; GPIOMem gpio = null; try { gpio = new GPIOMem((GPIOPins)DOOR_SENSOR_PIN, GPIODirection.In, true); occupied = gpio.Read() == PinState.Low; } catch (Exception ex) { Console.WriteLine(ex.Message); } finally { gpio.Dispose(); } // if the restroom is now occupied where it previously was not // update the status object by moving a user out of the queue if (occupied && !Status.Occupied) { if (Status.Queue.Count > 0) { Status.OccupiedBy = Status.Queue.Dequeue(); } else { Status.OccupiedBy = "?"; // unknown user (user not using queue?) } Status.Occupied = true; Status.OccupiedOn = DateTime.UtcNow; // this isn't meant to be exact } // otherwise if the restroom is no longer occupied where previously it was // update the status object to reflect this else if (!occupied && Status.Occupied) { Status.Occupied = false; Status.OccupiedBy = null; // not occupied } return(JsonConvert.SerializeObject(Status)); }
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); } }