Beispiel #1
0
 private static void ButtonClicked(object sender, EventArgs e)
 {
     if (_led5.State)
     {
         _led5.Off();
     }
     else
     {
         _led5.On();
     }
 }
Beispiel #2
0
        static void Main(string[] args)
        {
            CancellationTokenSource cancellationTokenSource = new CancellationTokenSource();

            var buttonReader = new ButtonReader(RunMachineLearningCode);

            buttonReader.ReadButton(cancellationTokenSource.Token);

            _ledRed   = new Led(Led.LedColor.Red);
            _ledGreen = new Led(Led.LedColor.Green);
            _ledBlue  = new Led(Led.LedColor.Blue);

            _buzzer = new Buzzer();

            // Do the test run
            _ledRed.Flash();
            _ledGreen.Flash();
            _ledBlue.Flash();

            _buzzer.Buzz();

            Console.WriteLine("Ready to get going. Press any key to stop the program.");

            try
            {
                while (!Console.KeyAvailable)
                {
                    _ledBlue.On();

                    RunMachineLearningCode(false);
                    _ledBlue.Off();

                    Task.Delay(2000).Wait();
                }
            }
            finally
            {
                cancellationTokenSource.Cancel();

                cancellationTokenSource.Dispose();
                _ledRed.Off();
                _ledGreen.Off();
                _ledBlue.Off();

                buttonReader.Dispose();
                _buzzer.Dispose();
                _ledRed.Dispose();
                _ledGreen.Dispose();
                _ledBlue.Dispose();
            }
        }
        protected virtual int OnExecute(CommandLineApplication app)
        {
            using FoundationPlate plate = PiTop4Board.Instance.GetOrCreatePlate <FoundationPlate>();

            using Led green  = plate.GetOrCreateLed(DigitalPort.D0);
            using Led yellow = plate.GetOrCreateLed(DigitalPort.D1);
            using Led red    = plate.GetOrCreateLed(DigitalPort.D2);

            Led[] semaphore = new[] { green, yellow, red };

            using Potentiometer potentiometer = plate.GetOrCreatePotentiometer(AnaloguePort.A0);

            potentiometer.Connect();

            int currentPosition = -1;
            Led current         = green;

            while (true)
            {
                // 2.9999 instead of 3 so when the Position is 1 it doesn't return 3 and still returns 2 (red light)
                int newPosition = (int)(potentiometer.Position * 2.9999);
                if (newPosition != currentPosition)
                {
                    current.Off();
                    current         = semaphore[newPosition];
                    currentPosition = newPosition;
                    current.On();
                }

                Thread.Sleep(100);
            }

            return(0);
        }
Beispiel #4
0
 private void Toggle(Led led)
 {
     if (led.IsOn)
     {
         led.Off();
     }
     else
     {
         led.On();
     }
 }
Beispiel #5
0
 private static void Led()
 {
     using (var board = new Arduino.Models.Arduino {
         Debug = true
     })
     {
         var led = new Led(board, 13);
         led.StrobeOn(20);
         Thread.Sleep(3.Seconds());
         led.Off();
     }
 }
        public void Off_should_digitalwrite_low()
        {
            A.CallTo(() => _arduino.DigitalWrite(Pin, DigitalPin.Low)).DoesNothing();
            var ledState = LedState.On;

            _led.OnStateChanged = state => { ledState = state; };

            _led.Off();

            _led.State.ShouldEqual(LedState.Off);
            A.CallTo(() => _arduino.DigitalWrite(Pin, DigitalPin.Low)).MustHaveHappened(Repeated.Exactly.Twice);
            ledState.ShouldEqual(LedState.Off);
        }
        public void Off_should_digitalwrite_low()
        {
            _arduino.Setup(a => a.DigitalWrite(Pin, DigitalPin.Low)).Verifiable();
            var ledState = LedState.On;

            _led.OnStateChanged = state => { ledState = state; };

            _led.Off();

            _led.State.Should().Equal(LedState.Off);
            _arduino.VerifyAll();
            ledState.Should().Equal(LedState.Off);
        }
Beispiel #8
0
        public LEDService()
        {
            _module = new PiTopModule();

            _plate = _module.GetOrCreatePlate <FoundationPlate>();

            _green = _plate.GetOrCreateDevice <Led>(DigitalPort.D0);
            _green.DisplayProperties.Add(new NamedCssColor("green"));

            _amber = _plate.GetOrCreateDevice <Led>(DigitalPort.D1);
            _amber.DisplayProperties.Add(new NamedCssColor("gold"));

            _red = _plate.GetOrCreateDevice <Led>(DigitalPort.D2);
            _red.DisplayProperties.Add(new NamedCssColor("red"));

            _green.Off();
            _amber.Off();
            _red.Off();
        }
 private void MainPage_Loaded(object sender, RoutedEventArgs e)
 {
     // GPIOの初期化
     RPi.gpio = GpioController.GetDefault();
     if (RPi.gpio != null)
     {
         motorLeft = new Motor(23, 24);
         motorRight = new Motor(27, 22);
         /// 停止状態
         motorLeft.Direction = 0;
         motorRight.Direction = 0;
         // LED
         led = new Led(4);
         led.Off();
     }
     this.KeyLFront.PointerPressed += Key_PointerPressed;
     this.KeyLBack.PointerPressed += Key_PointerPressed;
     this.KeyRFront.PointerPressed += Key_PointerPressed;
     this.KeyRBack.PointerPressed += Key_PointerPressed;
     this.sw1.Toggled += Sw1_Toggled;
     // バインド
     _model = new DataModel();
     this.DataContext = _model;
 }
        public async void Run(IBackgroundTaskInstance taskInstance)
        {
            _deferral = taskInstance.GetDeferral();


            // How to use the ADS1015 and MCP3002 ADC/Converters

            AdcProviderManager adcManager = new AdcProviderManager();

            adcManager.Providers.Add(new ADS1015(ADS1015.Gain.Volt33));                            // Load up ADS1015 4 Channel ADC Converter
            adcManager.Providers.Add(new MCP3002());                                               // Load up MCP3002 2 Channel ADC Converter

            IReadOnlyList <AdcController> adcControllers = await adcManager.GetControllersAsync(); // load ADCs


            //use the ADCs create above
            Ldr      light = new Ldr(adcControllers[0].OpenChannel(0));      // create new light sensor using the ADS1015 ADC provider
            MCP9700A temp  = new MCP9700A(adcControllers[1].OpenChannel(0)); // create temperature sensor using MCP3002 ADC Provider

            var lightLevel = light.ReadValue;                                // read light level from the first ADC ADS1015
            var lightRatio = light.ReadRatio;

            var celsius    = temp.Temperature.DegreesCelsius;    // read temp in celsius
            var fahrenheit = temp.Temperature.DegreesFahrenheit; // read temp in celsius


            BMP280 tempAndPressure = new BMP280();

            var degreesCelsius    = tempAndPressure.Temperature.DegreesCelsius; // read temp in celsius - plenty of other units
            var degreesFahrenheit = tempAndPressure.Temperature.DegreesFahrenheit;

            var bars         = tempAndPressure.Pressure.Bars;         // read air pressure in bars - plenty of other units
            var hectopascals = tempAndPressure.Pressure.Hectopascals; // read air pressure in Hectopascals
            var Atmospheres  = tempAndPressure.Pressure.Atmospheres;


            // LED demo

            Led led = new Led(4);   // open led on pin 4

            led.On();               // turn on
            await Task.Delay(1000); // wait for 1 second

            led.Off();              // turn off

            // relay Demo
            Relay relay = new Relay(6);

            relay.On();             // turn relay on
            await Task.Delay(1000); // wait for 1 second

            led.Off();              // turn relay off


            // motor demo
            Motor leftMotor  = new Motor(22, 24);
            Motor rightMotor = new Motor(12, 25);

            //now do a tight circle
            leftMotor.Forward();
            rightMotor.Backward();
            await Task.Delay(5000);  // wait for 5 second

            leftMotor.Stop();
            rightMotor.Stop();
        }
 public void GreenLedOff()
 {
     mGreenLed.Off();
 }
 public void YellowLedOff()
 {
     mYellowLed.Off();
 }
 public void RedLedOff()
 {
     mRedLed.Off();
 }