Esempio n. 1
0
        public static void SetColor(bool red, bool green, bool blue)
        {
            if (cnx != null && cnx.IsOpened)
            {
                RED_PIN.Enabled   = red;
                GREEN_PIN.Enabled = green;
                BLUE_PIN.Enabled  = blue;

                cnx.Toggle(RED_PIN);
                cnx.Toggle(GREEN_PIN);
                cnx.Toggle(BLUE_PIN);
            }
        }
Esempio n. 2
0
        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();
        }
Esempio n. 3
0
        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();
            }
        }
Esempio n. 4
0
 /// <summary>
 /// Toggles this pin.
 /// </summary>
 public void Toggle()
 {
     connection.Toggle(Configuration);
 }
Esempio n. 5
0
 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();
 }
Esempio n. 6
0
        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();
        }