static void Main(string[] args) { var left1 = ConnectorPin.P1Pin26.Output(); var left2 = ConnectorPin.P1Pin21.Output(); var right1 = ConnectorPin.P1Pin24.Output(); var right2 = ConnectorPin.P1Pin19.Output(); var ultrasonic = ConnectorPin.P1Pin08.Input(); var servoBase = ConnectorPin.P1Pin22.Output(); var servoPitch = ConnectorPin.P1Pin18.Output(); var leftMotor = ConnectorPin.P1Pin07.Input().OnStatusChanged(b => Evt("Left Motor", b)); var rightMotor = ConnectorPin.P1Pin11.Input().OnStatusChanged(b => Evt("Right Motor", b)); var irLeft = ConnectorPin.P1Pin12.Input().OnStatusChanged(b => Evt("Left IR", b)); var irRight = ConnectorPin.P1Pin13.Input().OnStatusChanged(b => Evt("Right IR", b)); var lineLeft = ConnectorPin.P1Pin16.Input().OnStatusChanged(b => Evt("Left Line", b)); var lineRight = ConnectorPin.P1Pin15.Input().OnStatusChanged(b => Evt("Right Line", b)); var connection = new GpioConnection(left1, left2, right1, right2, irLeft, irRight, lineLeft, lineRight, leftMotor, rightMotor, servoBase, servoPitch, ultrasonic); connection.Open(); var p = Process.Start("/usr/bin/servod", "--pcm --p1pins=22,18 --min=50 --max=250 --idle-timeout=500ms"); p.WaitForExit(); var cmd = Process.Start("/bin/bash", "-c 'echo 0=125 > /dev/servoblaster'"); if (cmd != null) { cmd.WaitForExit(); } var cmd2 = new Process(); cmd2.StartInfo.FileName = "/usr/bin/python"; cmd2.StartInfo.Arguments = "Ultrasonic.py"; cmd2.StartInfo.RedirectStandardOutput = true; cmd2.StartInfo.UseShellExecute = false; cmd2.Start(); cmd2.WaitForExit(); Console.WriteLine(cmd2.StandardOutput.ReadToEnd()); /*connection[left1] = true; connection[left2] = false; connection[right1] = true; connection[right2] = false;*/ Thread.Sleep(5000); /*connection[left1] = false; connection[left2] = false; connection[right1] = false; connection[right2] = false;*/ connection.Close(); Process.Start("/usr/bin/killall", "servod"); }
static void Main(string[] args) { var led1 = ConnectorPin.P1Pin18.Output(); //This is Pin 24 on the Pi var connection = new GpioConnection(led1); for(var i=0; i<100; i++) { Console.WriteLine(i); connection.Toggle(led1); System.Threading.Thread.Sleep(250); } connection.Close(); }
static void Main(string[] args) { var led1 = ConnectorPin.P1Pin07.Output(); using (var connection = new GpioConnection(led1)) { for (var i = 0; i < 100; i++) { Console.Write("."); connection.Toggle(led1); System.Threading.Thread.Sleep(2000); } connection.Close(); } }
private static void TestDriveCommands(string[] args) { Console.WriteLine("Testing drive commands"); if (args.Length <= 1) { Console.WriteLine("No commands provided"); } var connection = new GpioConnection(driveForward, driveBackward, driveTurnLeft, driveTurnRight); var command = ""; for (int i = 1; i < args.Length-1; i++) { command = args[i]; switch (command) { case "U": connection.Toggle(driveForward); System.Threading.Thread.Sleep(300); connection.Toggle(driveForward); break; case "D": connection.Toggle(driveBackward); System.Threading.Thread.Sleep(300); connection.Toggle(driveBackward); break; case "UL": connection.Toggle(driveForward); connection.Toggle(driveTurnLeft); System.Threading.Thread.Sleep(400); connection.Toggle(driveForward); connection.Toggle(driveTurnLeft); break; case "UR": connection.Toggle(driveForward); connection.Toggle(driveTurnRight); System.Threading.Thread.Sleep(400); connection.Toggle(driveForward); connection.Toggle(driveTurnRight); break; case "DL": connection.Toggle(driveBackward); connection.Toggle(driveTurnLeft); System.Threading.Thread.Sleep(400); connection.Toggle(driveBackward); connection.Toggle(driveTurnLeft); break; case "DR": connection.Toggle(driveBackward); connection.Toggle(driveTurnRight); System.Threading.Thread.Sleep(400); connection.Toggle(driveBackward); connection.Toggle(driveTurnRight); break; default: Console.WriteLine("Unknown command {0} Expected command to be one of U D UL UR DL DR", command); break; } } connection.Close(); }
private static void TestDrive() { Console.WriteLine("Testing arrows with car driving"); ConsoleKeyInfo cki; var connection = new GpioConnection(driveForward, driveBackward, driveTurnLeft, driveTurnRight); Console.WriteLine("Press the Escape (Esc) key to quit: \n"); do { cki = Console.ReadKey(); Console.Write(" --- You pressed "); Console.WriteLine(cki.Key.ToString()); switch (cki.Key) { case ConsoleKey.UpArrow: //connection.Blink(driveForward, new TimeSpan(0, 0, 0, 0, 300)); //Hack as we don't have immediate mode in managed code //Blink appears to have issues as it uses Timer connection.Toggle(driveForward); System.Threading.Thread.Sleep(300); connection.Toggle(driveForward); break; case ConsoleKey.DownArrow: connection.Toggle(driveBackward); System.Threading.Thread.Sleep(300); connection.Toggle(driveBackward); break; case ConsoleKey.LeftArrow: connection.Toggle(driveForward); connection.Toggle(driveTurnLeft); System.Threading.Thread.Sleep(400); connection.Toggle(driveForward); connection.Toggle(driveTurnLeft); break; case ConsoleKey.RightArrow: connection.Toggle(driveForward); connection.Toggle(driveTurnRight); System.Threading.Thread.Sleep(400); connection.Toggle(driveForward); connection.Toggle(driveTurnRight); break; default: break; } } while (cki.Key != ConsoleKey.Escape); connection.Close(); }
private static void TestLEDs() { Console.WriteLine("Test GPIO"); var led1 = ConnectorPin.P1Pin31.Output(); var led2 = ConnectorPin.P1Pin33.Output(); var led3 = ConnectorPin.P1Pin35.Output(); var led4 = ConnectorPin.P1Pin37.Output(); var connection = new GpioConnection(led1, led2, led3, led4); for (int i = 0; i < 5; i++) { connection.Blink(led1, new TimeSpan(0, 0, 1)); connection.Blink(led2, new TimeSpan(0, 0, 1)); connection.Blink(led3, new TimeSpan(0, 0, 1)); connection.Blink(led4, new TimeSpan(0, 0, 1)); } connection.Close(); }