Exemplo n.º 1
0
        static void TestTinyBit()
        {
            var buzzerController = PwmController.FromName(FEZBit.PwmChannel.Controller3.Id);
            var buzzerChannel    = buzzerController.OpenChannel(FEZBit.PwmChannel.Controller3.EdgeP0Channel);
            var lineDetectLeft   = GpioController.GetDefault().OpenPin(FEZBit.GpioPin.EdgeP13);
            var lineDetectRight  = GpioController.GetDefault().OpenPin(FEZBit.GpioPin.EdgeP14);
            var voiceSensor      = AdcController.FromName(FEZBit.AdcChannel.Controller1.Id).OpenChannel(FEZBit.AdcChannel.Controller1.EdgeP1);
            var p2remove         = GpioController.GetDefault().OpenPin(FEZBit.GpioPin.EdgeP1);
            var distanceTrigger  = GpioController.GetDefault().OpenPin(FEZBit.GpioPin.EdgeP16);
            var distanceEcho     = GpioController.GetDefault().OpenPin(FEZBit.GpioPin.EdgeP15);

            p2remove.SetDriveMode(GpioPinDriveMode.Input);

            var bot = new TinyBitController(
                I2cController.FromName(FEZBit.I2cBus.Edge),
                buzzerChannel,
                voiceSensor,
                lineDetectLeft, lineDetectRight, distanceTrigger, distanceEcho,
                FEZBit.GpioPin.EdgeP12
                );

            bot.SetHeadlight(30, 100, 100);
            bot.SetColorLeds(1, 200, 0, 0);
            bot.SetMotorSpeed(0.5, 0.5);
            bot.SetMotorSpeed(0.5, -0.5);
            bot.SetMotorSpeed(-0.5, 0.5);
            bot.SetMotorSpeed(0, 0);
            while (true)
            {
                var l = bot.ReadLineSensor(true);
                var r = bot.ReadLineSensor(false);
                var v = bot.ReadVoiceLevel();

                Thread.Sleep(50);
                bot.Beep();
            }
        }
Exemplo n.º 2
0
        static void TestTinyBit()
        {
            var buzzerController = PwmController.FromName(FEZBit.Timer.Pwm.Controller3.Id);
            var buzzerChannel    = buzzerController.OpenChannel(FEZBit.Timer.Pwm.Controller3.P0);
            var lineDetectLeft   = GpioController.GetDefault().OpenPin(FEZBit.GpioPin.P13);
            var lineDetectRight  = GpioController.GetDefault().OpenPin(FEZBit.GpioPin.P14);
            var voiceSensor      = AdcController.FromName(FEZBit.Adc.Controller1.Id).OpenChannel(FEZBit.Adc.Controller1.P1);
            var p2remove         = GpioController.GetDefault().OpenPin(FEZBit.GpioPin.P1);
            var distanceTrigger  = GpioController.GetDefault().OpenPin(FEZBit.GpioPin.P16);
            var distanceEcho     = GpioController.GetDefault().OpenPin(FEZBit.GpioPin.P15);

            p2remove.SetDriveMode(GpioPinDriveMode.Input);

            var bot = new TinyBitController(
                I2cController.FromName(FEZBit.I2cBus.Edge),
                buzzerChannel,
                voiceSensor,
                lineDetectLeft, lineDetectRight, distanceTrigger, distanceEcho,
                FEZBit.GpioPin.P12
                );


            new Thread(() => {
                while (true)
                {
                    bot.SetHeadlight(100, 0, 0);
                    Thread.Sleep(200);
                    bot.SetHeadlight(0, 0, 100);
                    Thread.Sleep(300);
                }
            }).Start();

            /*new Thread(() => {
             *  while (true) {
             *      bot.Beep();
             *      Thread.Sleep(2_000);
             *  }
             * }).Start();
             */
            while (true)
            {
                bot.SetMotorSpeed(0.5, 0.5);
                var l = bot.ReadLineSensor(true);
                var r = bot.ReadLineSensor(false);
                var v = bot.ReadVoiceLevel();
                var d = bot.ReadDistance();
                if (d < 20)
                {
                    bot.SetMotorSpeed(-0.5, -0.5);
                    Thread.Sleep(200);
                    bot.SetMotorSpeed(-0.5, 0.5);
                    Thread.Sleep(200);
                    bot.SetMotorSpeed(0, 0);
                    Thread.Sleep(1000);


                    bot.Beep();
                    Thread.Sleep(100);
                    bot.Beep();
                    Thread.Sleep(100);
                    bot.Beep();
                    Thread.Sleep(100);
                }
                Thread.Sleep(10);
            }

            bot.SetHeadlight(30, 100, 100);
            bot.SetColorLeds(1, 200, 0, 0);
            bot.SetMotorSpeed(0.5, 0.5);
            bot.SetMotorSpeed(0.5, -0.5);
            bot.SetMotorSpeed(-0.5, 0.5);
            bot.SetMotorSpeed(0, 0);
            while (true)
            {
                var l = bot.ReadLineSensor(true);
                var r = bot.ReadLineSensor(false);
                var v = bot.ReadVoiceLevel();

                Thread.Sleep(50);
                bot.Beep();
            }
        }