Example #1
0
        static void Main(string[] args)
        {
            Console.WriteLine("\nmikroBUS PWM Output Test\n");

            // Get mikroBUS socket number

            Console.Write("Socket number?       ");
            var num = int.Parse(Console.ReadLine());

            Console.Write("PWM pulse frequency? ");
            var freq = int.Parse(Console.ReadLine());

            // Create objects

            var S    = new IO.Objects.libsimpleio.mikroBUS.Socket(num);
            var outp = new IO.Objects.libsimpleio.PWM.Output(S.PWMOut, freq);

            // Sweep PWM output pulse width

            for (;;)
            {
                for (double d = 0; d <= 100; d++)
                {
                    outp.dutycycle = d;
                    System.Threading.Thread.Sleep(20);
                }

                for (double d = 100; d >= 0; d--)
                {
                    outp.dutycycle = d;
                    System.Threading.Thread.Sleep(20);
                }
            }
        }
Example #2
0
        static void Main(string[] args)
        {
            Console.WriteLine("\nMotor Output Test Using PWM (speed) and GPIO (direction) Outputs\n");

            IO.Objects.libsimpleio.Device.Designator desg_GPIO;

            Console.Write("GPIO chip number:    ");
            desg_GPIO.chip = uint.Parse(Console.ReadLine());

            Console.Write("GPIO line number:    ");
            desg_GPIO.chan = uint.Parse(Console.ReadLine());

            IO.Objects.libsimpleio.Device.Designator desg_PWM;

            Console.Write("PWM chip:            ");
            desg_PWM.chip = uint.Parse(Console.ReadLine());

            Console.Write("PWM channel:         ");
            desg_PWM.chan = uint.Parse(Console.ReadLine());

            // Create GPIO pin object

            IO.Interfaces.GPIO.Pin GPIO0 =
                new IO.Objects.libsimpleio.GPIO.Pin(desg_GPIO,
                                                    IO.Interfaces.GPIO.Direction.Output);

            // Create PWM output object

            IO.Interfaces.PWM.Output PWM0 =
                new IO.Objects.libsimpleio.PWM.Output(desg_PWM, 100);

            // Create motor object

            IO.Interfaces.Motor.Output Motor0 =
                new IO.Objects.Motor.PWM.Output(GPIO0, PWM0);

            // Sweep motor velocity up and down

            Console.WriteLine("\nPress CONTROL-C to exit");

            for (;;)
            {
                int n;

                for (n = -100; n < 100; n++)
                {
                    Motor0.velocity = n / 100.0;
                    System.Threading.Thread.Sleep(50);
                }

                for (n = 100; n >= -100; n--)
                {
                    Motor0.velocity = n / 100.0;
                    System.Threading.Thread.Sleep(50);
                }
            }
        }
Example #3
0
        static void Main(string[] args)
        {
            Console.WriteLine("\nMotor Output Test Using Two PWM outputs (CW and CCW)\n");

            IO.Objects.libsimpleio.Device.Designator desg_CW;

            Console.Write("PWM chip:            ");
            desg_CW.chip = uint.Parse(Console.ReadLine());

            Console.Write("PWM channel:         ");
            desg_CW.chan = uint.Parse(Console.ReadLine());

            IO.Objects.libsimpleio.Device.Designator desg_CCW;

            Console.Write("PWM chip:            ");
            desg_CCW.chip = uint.Parse(Console.ReadLine());

            Console.Write("PWM channel:         ");
            desg_CCW.chan = uint.Parse(Console.ReadLine());

            // Create PWM output objects

            IO.Interfaces.PWM.Output PWMCW =
                new IO.Objects.libsimpleio.PWM.Output(desg_CW, 100);

            IO.Interfaces.PWM.Output PWMCCW =
                new IO.Objects.libsimpleio.PWM.Output(desg_CCW, 100);

            // Create motor object

            IO.Interfaces.Motor.Output Motor0 =
                new IO.Objects.Motor.PWM.Output(PWMCW, PWMCCW);

            // Sweep motor velocity up and down

            Console.WriteLine("\nPress CONTROL-C to exit");

            for (;;)
            {
                int n;

                for (n = -100; n < 100; n++)
                {
                    Motor0.velocity = n / 100.0;
                    System.Threading.Thread.Sleep(50);
                }

                for (n = 100; n >= -100; n--)
                {
                    Motor0.velocity = n / 100.0;
                    System.Threading.Thread.Sleep(50);
                }
            }
        }
Example #4
0
        static void Main(string[] args)
        {
            Console.WriteLine("\nMotor Output Test using libsimpleio\n");

            Console.Write("GPIO chip number:    ");
            uint gpiochip = uint.Parse(Console.ReadLine());

            Console.Write("GPIO line number:    ");
            uint gpioline = uint.Parse(Console.ReadLine());

            Console.Write("PWM chip:            ");
            int pwmchip = int.Parse(Console.ReadLine());

            Console.Write("PWM channel:         ");
            int pwmchan = int.Parse(Console.ReadLine());

            // Create GPIO pin object

            IO.Interfaces.GPIO.Pin GPIO0 =
                new IO.Objects.libsimpleio.GPIO.Pin(gpiochip, gpioline,
                                                    IO.Interfaces.GPIO.Direction.Output);

            // Create PWM output object

            IO.Interfaces.PWM.Output PWM0 =
                new IO.Objects.libsimpleio.PWM.Output(pwmchip, pwmchan, 100);

            // Create motor object

            IO.Interfaces.Motor.Output Motor0 =
                new IO.Objects.Motor.PWM.Output(GPIO0, PWM0);

            // Sweep motor velocity up and down

            Console.WriteLine("\nPress CONTROL-C to exit");

            for (;;)
            {
                int n;

                for (n = -100; n < 100; n++)
                {
                    Motor0.velocity = n / 100.0;
                    Thread.Sleep(50);
                }

                for (n = 100; n >= -100; n--)
                {
                    Motor0.velocity = n / 100.0;
                    Thread.Sleep(50);
                }
            }
        }
Example #5
0
        static void Main(string[] args)
        {
            Console.WriteLine("\nMotor Output Test using libsimpleio\n");

            Console.Write("PWM chip:            ");
            int chipCW = int.Parse(Console.ReadLine());

            Console.Write("PWM channel:         ");
            int chanCW = int.Parse(Console.ReadLine());

            Console.Write("PWM chip:            ");
            int chipCCW = int.Parse(Console.ReadLine());

            Console.Write("PWM channel:         ");
            int chanCCW = int.Parse(Console.ReadLine());

            // Create PWM output objects

            IO.Interfaces.PWM.Output PWMCW =
                new IO.Objects.libsimpleio.PWM.Output(chipCW, chanCW, 100);

            IO.Interfaces.PWM.Output PWMCCW =
                new IO.Objects.libsimpleio.PWM.Output(chipCCW, chanCCW, 100);

            // Create motor object

            IO.Interfaces.Motor.Output Motor0 =
                new IO.Objects.Motor.PWM.Output(PWMCW, PWMCCW);

            // Sweep motor velocity up and down

            Console.WriteLine("\nPress CONTROL-C to exit");

            for (;;)
            {
                int n;

                for (n = -100; n < 100; n++)
                {
                    Motor0.velocity = n / 100.0;
                    Thread.Sleep(50);
                }

                for (n = 100; n >= -100; n--)
                {
                    Motor0.velocity = n / 100.0;
                    Thread.Sleep(50);
                }
            }
        }
Example #6
0
        static void Main(string[] args)
        {
            Console.WriteLine("\nServo Output Test\n");

            IO.Objects.libsimpleio.Device.Designator desg;

            Console.Write("PWM chip:            ");
            desg.chip = uint.Parse(Console.ReadLine());

            Console.Write("PWM channel:         ");
            desg.chan = uint.Parse(Console.ReadLine());

            // Create PWM output object

            IO.Interfaces.PWM.Output PWM0 =
                new IO.Objects.libsimpleio.PWM.Output(desg, 50);

            // Create servo output object

            IO.Interfaces.Servo.Output Servo0 =
                new IO.Objects.Servo.PWM.Output(PWM0, 50);

            // Sweep servo position back and forth

            Console.WriteLine("\nPress CONTROL-C to exit");

            for (;;)
            {
                int n;

                for (n = -100; n < 100; n++)
                {
                    Servo0.position = n / 100.0;
                    System.Threading.Thread.Sleep(50);
                }

                for (n = 100; n >= -100; n--)
                {
                    Servo0.position = n / 100.0;
                    System.Threading.Thread.Sleep(50);
                }
            }
        }
Example #7
0
        static void Main(string[] args)
        {
            Console.WriteLine("\nPWM Output Test\n");

            IO.Objects.libsimpleio.Device.Designator desg_PWM;

            Console.Write("PWM chip:            ");
            desg_PWM.chip = uint.Parse(Console.ReadLine());

            Console.Write("PWM channel:         ");
            desg_PWM.chan = uint.Parse(Console.ReadLine());

            Console.Write("PWM pulse frequency: ");
            int freq = int.Parse(Console.ReadLine());

            // Create PWM output object

            IO.Interfaces.PWM.Output PWM0 =
                new IO.Objects.libsimpleio.PWM.Output(desg_PWM, freq);

            // Sweep PWM pulse width back and forth

            Console.WriteLine("\nPress CONTROL-C to exit");

            for (;;)
            {
                int n;

                for (n = 0; n < 100; n++)
                {
                    PWM0.dutycycle = n;
                    System.Threading.Thread.Sleep(50);
                }

                for (n = 100; n >= 0; n--)
                {
                    PWM0.dutycycle = n;
                    System.Threading.Thread.Sleep(50);
                }
            }
        }
Example #8
0
        static void Main(string[] args)
        {
            Console.WriteLine("\nLED Toggle Test Using PWM Output\n");

            IO.Objects.libsimpleio.Device.Designator desg;

            Console.Write("PWM chip:              ");
            desg.chip = uint.Parse(Console.ReadLine());

            Console.Write("PWM channel:           ");
            desg.chan = uint.Parse(Console.ReadLine());

            Console.Write("PWM pulse frequency:   ");
            int freq = int.Parse(Console.ReadLine());

            Console.Write("PWM output duty cycle: ");
            double duty = double.Parse(Console.ReadLine());

            // Create PWM output object

            IO.Interfaces.PWM.Output PWM0 =
                new IO.Objects.libsimpleio.PWM.Output(desg, freq);

            // Create GPIO pin object

            IO.Interfaces.GPIO.Pin LED =
                new IO.Objects.GPIO.PWM.Pin(PWM0, false, duty);

            // Toggle the LED

            Console.WriteLine("\nPress CONTROL-C to exit");

            for (;;)
            {
                LED.state = !LED.state;
                System.Threading.Thread.Sleep(500);
            }
        }