public void PropertySetAppliesCorrectPinStates(byte bitMask, bool[] pinStates) { var spiDevice = new VirtualSpiDevice(); var piface = new PiFaceDevice(spiDevice); spiDevice.WriteByte((byte)PiFaceRegisterAddress.GPIOB, bitMask); for (var i = (byte)0; i < pinStates.Length; i++) { Assert.AreEqual(pinStates[i], piface.GetInputPinState(i)); } }
public double GetDistance() { var piface = new PiFaceDevice(); ManualResetEvent mre = new ManualResetEvent(false); mre.WaitOne(500); Stopwatch pulseLength = new Stopwatch(); //Send pulse piface.SetOutputPinState(triggerpin, true); mre.WaitOne(TimeSpan.FromMilliseconds(0.01)); piface.SetOutputPinState(triggerpin, false); //Recieve pusle while (piface.GetInputPinState(echopin) == false) { } pulseLength.Start(); while (piface.GetInputPinState(echopin) == true) { } pulseLength.Stop(); //Calculating distance TimeSpan timeBetween = pulseLength.Elapsed; Debug.WriteLine(timeBetween.ToString()); double distance = timeBetween.TotalSeconds * 17000; return(distance); }
static void Main(string[] args) { // get reference to default piface device var piface = new PiFaceDevice(); // toggle each output pin on and off 50 times for (byte pin = 0; pin < 8; pin++) { Console.WriteLine("toggling input pin {0}", pin); var state = true; for (var i = 0; i < 50; i++) { piface.SetOutputPinState(pin, state); System.Threading.Thread.Sleep(25); state = !state; } } // read the current state of each input pin for (byte pin = 0; pin < 8; pin++) { Console.WriteLine("input pin {0} = {1}", pin, piface.GetInputPinState(pin)); } }
public static int Main() { Console.WriteLine("running"); var piface = new PiFaceDevice(); while (true) { try { gamepadState = GamePad.GetState(PlayerIndex.One); if (gamepadState.Buttons.A == ButtonState.Pressed) { Console.WriteLine("a"); } #region commands if (gamepadState.Buttons.BigButton == ButtonState.Pressed) { big = 1; } else { big = 0; } if (gamepadState.Buttons.Back == ButtonState.Pressed) { select = 1; } else { select = 0; } if (gamepadState.Buttons.Start == ButtonState.Pressed) { start = 1; } else { start = 0; } if (gamepadState.Buttons.A == ButtonState.Pressed) { button_a = 1; } else { button_a = 0; } if (gamepadState.Buttons.B == ButtonState.Pressed) { button_b = 1; } else { button_b = 0; } if (gamepadState.Buttons.Y == ButtonState.Pressed) { button_y = 1; } else { button_y = 0; } if (gamepadState.Buttons.X == ButtonState.Pressed) { button_x = 1; } else { button_x = 0; } if (gamepadState.DPad.Down == ButtonState.Pressed) { dpad_down = 1; } else { dpad_down = 0; } if (gamepadState.DPad.Up == ButtonState.Pressed) { dpad_up = 1; } else { dpad_up = 0; } if (gamepadState.DPad.Right == ButtonState.Pressed) { dpad_right = 1; } else { dpad_right = 0; } if (gamepadState.DPad.Left == ButtonState.Pressed) { dpad_left = 1; } else { dpad_left = 0; } if (gamepadState.Buttons.RightStick == ButtonState.Pressed) { r_stick_click = 1; } else { r_stick_click = 0; } if (gamepadState.Buttons.LeftStick == ButtonState.Pressed) { l_stick_click = 1; } else { l_stick_click = 0; } if (gamepadState.Buttons.LeftShoulder == ButtonState.Pressed) { l_schulter = 1; } else { l_schulter = 0; } if (gamepadState.Buttons.RightShoulder == ButtonState.Pressed) { r_schulter = 1; } else { r_schulter = 0; } r_trigger = Convert.ToInt32(gamepadState.Triggers.Right); l_trigger = Convert.ToInt32(gamepadState.Triggers.Left); r_stick_y = Convert.ToInt32(gamepadState.ThumbSticks.Right.Y); r_stick_x = Convert.ToInt32(gamepadState.ThumbSticks.Right.X); l_stick_y = Convert.ToInt32(gamepadState.ThumbSticks.Left.Y); l_stick_x = Convert.ToInt32(gamepadState.ThumbSticks.Left.X); #endregion commands int licht = 0; bool licht_brennt = false; bool arp = false; int dauerlicht = 1; Console.WriteLine(piface.GetInputPinState(1)); #region gas if (Convert.ToInt32(r_trigger) == 0) { piface.SetOutputPinState(0, false); } else { piface.SetOutputPinState(0, true); } if (Convert.ToInt32(l_trigger) == 0) { piface.SetOutputPinState(1, false); } else { piface.SetOutputPinState(1, true); } #endregion gas #region lenken if (Convert.ToInt32(l_stick_x) == 0) { piface.SetOutputPinState(3, false); piface.SetOutputPinState(2, false); } if (Convert.ToInt32(l_stick_x) > 0) { piface.SetOutputPinState(2, true); piface.SetOutputPinState(3, false); } else { piface.SetOutputPinState(2, false); } if (Convert.ToInt32(l_stick_x) < 0) { piface.SetOutputPinState(3, true); piface.SetOutputPinState(2, false); } else { piface.SetOutputPinState(3, false); } #endregion lenken #region Licht if (Convert.ToInt32(button_a) == 1) { piface.SetOutputPinState(5, true); } if (Convert.ToInt32(button_y) == 1) { var state_l = true; for (var j = 0; j < 50; j++) { piface.SetOutputPinState(5, state_l); System.Threading.Thread.Sleep(25); state_l = !state_l; } } if (Convert.ToInt32(button_x) == 1) { piface.SetOutputPinState(5, true); piface.SetOutputPinState(6, true); } #endregion Licht if (Convert.ToInt32(start) == 1) { for (byte pin = 0; pin < 8; pin++) { var state = true; for (var i = 0; i < 50; i++) { piface.SetOutputPinState(pin, state); System.Threading.Thread.Sleep(25); state = !state; } } } } catch (Exception ex) { Console.WriteLine(ex.Message); } } }