Esempio n. 1
0
 public void Setup()
 {
     _arduino = A.Fake <IArduino>();
     _timer   = new FakeTimer();
     _led     = new LedPwm(_arduino, Pin, _timer);
     _led.Intensity.ShouldEqual(0);
 }
Esempio n. 2
0
 public void Setup()
 {
     _arduino = new Mock <IArduino>(MockBehavior.Strict);
     _timer   = new MockedTimer();
     _arduino.Setup(a => a.DigitalWrite(Pin, DigitalPin.Low)).Verifiable();
     _arduino.Setup(a => a.PinMode(Pin, PinMode.Pwm)).Verifiable();
     _led = new LedPwm(_arduino.Object, Pin, _timer);
     _led.Intensity.Should().Equal(0);
 }
Esempio n. 3
0
 private static void LedPwm()
 {
     using (var board = new Arduino.Models.Arduino {
         Debug = true
     })
     {
         var led = new LedPwm(board, 9);
         led.Fade(255, 1.Second());
         Thread.Sleep(2.Seconds());
         led.Fade(0, 1.Second());
         led.Off();
     }
 }
Esempio n. 4
0
        private static void TestLedPwmLightSensor()
        {
            LedPwm      ledPwm      = new LedPwm(_goPiGo3, GrovePort.Grove2);
            LightSensor lightSensor = new LightSensor(_goPiGo3, GrovePort.Grove1);

            Console.WriteLine($"Test {lightSensor.SensorName} on port {lightSensor.Port} controlling a {ledPwm.SensorName} on port {ledPwm.Port}. The intensity of the led will change proportionnaly to the intensity read by the sensor. Press enter to stop the test");
            AddLines();
            while (!Console.KeyAvailable)
            {
                Console.CursorLeft = 0;
                Console.Write($"Intensity: {lightSensor.ValueAsPercent} %");
                ledPwm.Duty = lightSensor.ValueAsPercent;
                Thread.Sleep(50);
                CleanALine();
            }

            ledPwm.Stop();
        }
Esempio n. 5
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            // TODO: Add your initialization logic here
            InitalizeSerialCommunication();

            lowerLeftBumper      = new Bumper();
            upperLeftBumper      = new Bumper();
            upperRightBumper     = new Bumper();
            lowerRightBumper     = new Bumper();
            wheels               = new CoupledWheels();
            wheels.ClicksPerTurn = 3900;
            wheels.WheelDistance = 0.345f;
            wheels.WheelRadius   = 0.0467f;
            wheels.Updated      += new EventHandler(wheels_Updated);

            sonar0 = new MaxbotixSonar();
            sonar1 = new MaxbotixSonar();
            sonar2 = new MaxbotixSonar();
            sonar3 = new MaxbotixSonar();
            sonar4 = new MaxbotixSonar();

            groundSensor0 = new InfraredSensor();
            groundSensor1 = new InfraredSensor();
            groundSensor2 = new InfraredSensor();

            redLed   = new LedPwm();
            greenLed = new LedPwm();
            blueLed  = new LedPwm();

            drive     = new DifferentialDrive(wheels);
            odometry  = new DifferentialOdometry(wheels);
            proximity = new ProximityArray
            {
                { new Transform(0.15f, 0.14f, MathHelper.ToRadians(45)), sonar0 },
                { new Transform(0.165f, 0.07f, MathHelper.ToRadians(20)), sonar1 },
                { new Transform(0.18f, 0.0f, MathHelper.ToRadians(0)), sonar2 },
                { new Transform(0.165f, -0.07f, MathHelper.ToRadians(-20)), sonar3 },
                { new Transform(0.15f, -0.14f, MathHelper.ToRadians(-45)), sonar4 },
            };

            protocol = new ProtocolManager();
            protocol.SubscribeComponent(lowerLeftBumper);
            protocol.SubscribeComponent(upperLeftBumper);
            protocol.SubscribeComponent(upperRightBumper);
            protocol.SubscribeComponent(lowerRightBumper);
            protocol.SubscribeComponent(wheels);
            protocol.SubscribeComponent(sonar0);
            protocol.SubscribeComponent(sonar1);
            protocol.SubscribeComponent(sonar2);
            protocol.SubscribeComponent(sonar3);
            protocol.SubscribeComponent(sonar4);
            protocol.SubscribeComponent(groundSensor0);
            protocol.SubscribeComponent(groundSensor1);
            protocol.SubscribeComponent(groundSensor2);
            protocol.SubscribeComponent(greenLed);
            protocol.SubscribeComponent(redLed);
            protocol.SubscribeComponent(blueLed);
            transport.Protocol = protocol;

            renderer = new SpriteRenderer(this);
            renderer.PixelsPerMeter = 100;
            Components.Add(renderer);

            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);
            Services.AddService(typeof(SpriteBatch), spriteBatch);

            base.Initialize();
        }
Esempio n. 6
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            // TODO: Add your initialization logic here
            InitalizeSerialCommunication();

            lowerLeftBumper = new Bumper();
            upperLeftBumper = new Bumper();
            upperRightBumper = new Bumper();
            lowerRightBumper = new Bumper();
            wheels = new CoupledWheels();
            wheels.ClicksPerTurn = 3900;
            wheels.WheelDistance = 0.345f;
            wheels.WheelRadius = 0.0467f;
            wheels.Updated += new EventHandler(wheels_Updated);

            sonar0 = new MaxbotixSonar();
            sonar1 = new MaxbotixSonar();
            sonar2 = new MaxbotixSonar();
            sonar3 = new MaxbotixSonar();
            sonar4 = new MaxbotixSonar();

            groundSensor0 = new InfraredSensor();
            groundSensor1 = new InfraredSensor();
            groundSensor2 = new InfraredSensor();

            redLed = new LedPwm();
            greenLed = new LedPwm();
            blueLed = new LedPwm();

            drive = new DifferentialDrive(wheels);
            odometry = new DifferentialOdometry(wheels);
            proximity = new ProximityArray
            {
                { new Transform(0.15f, 0.14f, MathHelper.ToRadians(45)), sonar0 },
                { new Transform(0.165f, 0.07f, MathHelper.ToRadians(20)), sonar1 },
                { new Transform(0.18f, 0.0f, MathHelper.ToRadians(0)), sonar2 },
                { new Transform(0.165f, -0.07f, MathHelper.ToRadians(-20)), sonar3 },
                { new Transform(0.15f, -0.14f, MathHelper.ToRadians(-45)), sonar4 },
            };

            protocol = new ProtocolManager();
            protocol.SubscribeComponent(lowerLeftBumper);
            protocol.SubscribeComponent(upperLeftBumper);
            protocol.SubscribeComponent(upperRightBumper);
            protocol.SubscribeComponent(lowerRightBumper);
            protocol.SubscribeComponent(wheels);
            protocol.SubscribeComponent(sonar0);
            protocol.SubscribeComponent(sonar1);
            protocol.SubscribeComponent(sonar2);
            protocol.SubscribeComponent(sonar3);
            protocol.SubscribeComponent(sonar4);
            protocol.SubscribeComponent(groundSensor0);
            protocol.SubscribeComponent(groundSensor1);
            protocol.SubscribeComponent(groundSensor2);
            protocol.SubscribeComponent(greenLed);
            protocol.SubscribeComponent(redLed);
            protocol.SubscribeComponent(blueLed);
            transport.Protocol = protocol;

            renderer = new SpriteRenderer(this);
            renderer.PixelsPerMeter = 100;
            Components.Add(renderer);

            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);
            Services.AddService(typeof(SpriteBatch), spriteBatch);

            base.Initialize();
        }