public void PropertySetAppliesCorrectBitMask(byte bitMask) { var piface = new PiFaceDevice(new VirtualSpiDevice()); piface.SetOutputPinStates(bitMask); Assert.AreEqual(piface.GetOutputPinStates(), bitMask); }
static void Main(string[] args) { // get reference to default piface device with all inputs enabled for ISR var piface = new PiFaceDevice(255); var pinDetector = new InputPinController(piface, 0); pinDetector.PinChanged += pinDetector_PinChanged; var buttonDetector = new ButtonInputController(piface, 1); buttonDetector.ButtonClicked += buttonDetector_ButtonClicked; while (Console.KeyAvailable) { Console.ReadKey(true); } Console.WriteLine("Detectin changes on PiFace input pin 0 and Button clicks on pin 1. Press <Enter> key to exit.."); var ki = Console.ReadKey(true); while (ki.Key != ConsoleKey.Enter) { System.Threading.Thread.Sleep(100); ki = Console.ReadKey(true); } }
public void PropertySetAppliesCorrectBitMask(byte bitMask) { var spiDevice = new VirtualSpiDevice(); var piface = new PiFaceDevice(spiDevice); spiDevice.WriteByte((byte)PiFaceRegisterAddress.GPIOB, bitMask); Assert.AreEqual(piface.GetInputPinStates(), bitMask); }
public void PropertySetAppliesCorrectPinStates(byte bitMask, bool[] pinStates) { var piface = new PiFaceDevice(new VirtualSpiDevice()); piface.SetOutputPinStates(bitMask); for (var i = (byte)0; i < pinStates.Length; i++) { Assert.AreEqual(pinStates[i], piface.GetOutputPinState(i)); } }
static void Main(string[] args) { var settings = Properties.Settings.Default; // initialise the PiFace device to bind the server to var device = default(IPiFaceDevice); switch (settings.DeviceType) { case "Physical": device = new PiFaceDevice(); break; case "Emulated": device = new PiFaceEmulator(); break; default: throw new System.Configuration.ConfigurationErrorsException("The 'DeviceType' setting in app.config must be either 'Physical' or 'Emulated'."); } // get the address to run the server on var address = default(IPAddress); if (string.IsNullOrEmpty(settings.ServerAddress)) { address = PiFaceTcpHelper.GetLocalIPAddress(); } else { address = IPAddress.Parse(settings.ServerAddress); } // get the port to run the server on var port = (uint)0; if (!uint.TryParse(settings.ServerPort, out port)) { throw new System.Configuration.ConfigurationErrorsException("The 'ServerPort' setting in app.config must be an unsigned integer."); } // start the server var endpoint = new IPEndPoint(address, (int)port); var server = new PiFaceTcpServer(device, endpoint); server.MessageReceived += Program.PiFaceTcpServer_MessageReceived; server.ResponseSent += Program.PiFaceTcpServer_ResponseSent; server.Start(); // wait around while the server runs while (true) { System.Threading.Thread.Sleep(1000); } }
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)); } }
static void Main(string[] args) { // get reference to default piface device var piface = new PiFaceDevice(); Console.WriteLine(piface.DeviceName); for (int i = 0; i < 7; i++) { piface.SetOutputPinState((byte)i, true); Thread.Sleep(1000); piface.SetOutputPinState((byte)i, false); Thread.Sleep(1000); } }
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); } } }
public static void x(string received_data) { if (synced == false) { sync_ip = received_data.Split(new char[] { ';' })[0]; highjack = received_data.Split(new char[] { ';' })[1]; } else { #region input var piface = new PiFaceDevice(); button_a = Convert.ToDouble(received_data.Split(new char[] { ';' })[0]); button_b = Convert.ToDouble(received_data.Split(new char[] { ';' })[1]); button_y = Convert.ToDouble(received_data.Split(new char[] { ';' })[2]); button_x = Convert.ToDouble(received_data.Split(new char[] { ';' })[3]); dpad_up = Convert.ToDouble(received_data.Split(new char[] { ';' })[4]); dpad_down = Convert.ToDouble(received_data.Split(new char[] { ';' })[5]); dpad_right = Convert.ToDouble(received_data.Split(new char[] { ';' })[6]); dpad_left = Convert.ToDouble(received_data.Split(new char[] { ';' })[7]); r_schulter = Convert.ToDouble(received_data.Split(new char[] { ';' })[8]); l_schulter = Convert.ToDouble(received_data.Split(new char[] { ';' })[9]); r_stick_x = Convert.ToDecimal(received_data.Split(new char[] { ';' })[10]); r_stick_y = Convert.ToDecimal(received_data.Split(new char[] { ';' })[11]); l_stick_x = Convert.ToDecimal(received_data.Split(new char[] { ';' })[12]); l_stick_y = Convert.ToDecimal(received_data.Split(new char[] { ';' })[13]); r_stick_click = Convert.ToDouble(received_data.Split(new char[] { ';' })[14]); l_stick_click = Convert.ToDouble(received_data.Split(new char[] { ';' })[15]); l_trigger = Convert.ToDouble(received_data.Split(new char[] { ';' })[16]); r_trigger = Convert.ToDouble(received_data.Split(new char[] { ';' })[17]); big = Convert.ToDouble(received_data.Split(new char[] { ';' })[18]); select = Convert.ToDouble(received_data.Split(new char[] { ';' })[19]); start = Convert.ToDouble(received_data.Split(new char[] { ';' })[20]); #endregion input #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; } } } } }