Esempio n. 1
0
 public void Stop()
 {
     RgbLed?.TurnOff();
     MotorSpeed  = 0;
     IsOperating = false;
     operationTimer.Stop();
 }
Esempio n. 2
0
        public MeadowApp()
        {
            var led = new RgbLed(Device, Device.Pins.OnboardLedRed, Device.Pins.OnboardLedGreen, Device.Pins.OnboardLedBlue);

            led.SetColor(RgbLed.Colors.Red);

            leds[0] = new Led(Device.CreateDigitalOutputPort(Device.Pins.D10));
            leds[1] = new Led(Device.CreateDigitalOutputPort(Device.Pins.D09));
            leds[2] = new Led(Device.CreateDigitalOutputPort(Device.Pins.D08));
            leds[3] = new Led(Device.CreateDigitalOutputPort(Device.Pins.D07));

            pushButtons[0]          = new PushButton(Device.CreateDigitalInputPort(Device.Pins.D01, InterruptMode.EdgeBoth, ResistorMode.Disabled));
            pushButtons[0].Clicked += ButtonRedClicked;
            pushButtons[1]          = new PushButton(Device.CreateDigitalInputPort(Device.Pins.D02, InterruptMode.EdgeBoth, ResistorMode.Disabled));
            pushButtons[1].Clicked += ButtonGreenClicked;
            pushButtons[2]          = new PushButton(Device.CreateDigitalInputPort(Device.Pins.D03, InterruptMode.EdgeBoth, ResistorMode.Disabled));
            pushButtons[2].Clicked += ButtonBlueClicked;
            pushButtons[3]          = new PushButton(Device.CreateDigitalInputPort(Device.Pins.D04, InterruptMode.EdgeBoth, ResistorMode.Disabled));
            pushButtons[3].Clicked += ButtonYellowClicked;

            speaker = new PiezoSpeaker(Device.CreatePwmPort(Device.Pins.D11));

            Console.WriteLine("Welcome to Simon");
            SetAllLEDs(true);
            game.OnGameStateChanged += OnGameStateChanged;
            game.Reset();

            led.SetColor(RgbLed.Colors.Green);
        }
Esempio n. 3
0
        public MeadowApp()
        {
            var led = new RgbLed(Device, Device.Pins.OnboardLedRed, Device.Pins.OnboardLedGreen, Device.Pins.OnboardLedBlue);

            led.SetColor(RgbLed.Colors.Red);

            mcp = new Mcp23x08(Device.CreateI2cBus(), true, true, true);

            IDigitalOutputPort[] ports =
            {
                Device.CreateDigitalOutputPort(Device.Pins.D01),
                Device.CreateDigitalOutputPort(Device.Pins.D00),
                mcp.CreateDigitalOutputPort(mcp.Pins.GP7,       false,  OutputType.PushPull),
                mcp.CreateDigitalOutputPort(mcp.Pins.GP6,       false,  OutputType.PushPull),
                mcp.CreateDigitalOutputPort(mcp.Pins.GP5,       false,  OutputType.PushPull),
                mcp.CreateDigitalOutputPort(mcp.Pins.GP4,       false,  OutputType.PushPull),
                mcp.CreateDigitalOutputPort(mcp.Pins.GP3,       false,  OutputType.PushPull),
                mcp.CreateDigitalOutputPort(mcp.Pins.GP2,       false,  OutputType.PushPull),
                mcp.CreateDigitalOutputPort(mcp.Pins.GP1,       false,  OutputType.PushPull),
                mcp.CreateDigitalOutputPort(mcp.Pins.GP0,       false,  OutputType.PushPull),
            };

            ledBarGraph = new LedBarGraph(ports);

            led.SetColor(RgbLed.Colors.Green);

            ledBarGraph.Percentage = 1;
            //CycleLeds();
        }
Esempio n. 4
0
        private async void MainPage_Loaded(object sender, RoutedEventArgs e)
        {
            // Start GPIO
            var gpioController = GpioController.GetDefault();

            // Create PWM manager
            var pwmManager = new PwmProviderManager();

            // Add providers
            pwmManager.Providers.Add(new SoftPwm());
            // pwmManager.Providers.Add(new PCA9685());

            // Get the well-known controller collection back
            var pwmControllers = await pwmManager.GetControllersAsync();

            // Using the first PWM controller
            var controller = pwmControllers[0];

            // Set desired frequency
            controller.SetDesiredFrequency(60);

            // Create light sensor
            led = new RgbLed()
            {
                // SoftPwm
                RedPin   = controller.OpenPin(4),
                GreenPin = controller.OpenPin(5),
                BluePin  = controller.OpenPin(6),

                // PCA9685
                //RedPin = controller.OpenPin(0),
                //GreenPin = controller.OpenPin(1),
                //BluePin = controller.OpenPin(2),
            };
        }
        public MeadowApp()
        {
            Console.WriteLine("Initializing...");

            led = new RgbLed(Device, Device.Pins.OnboardLedRed, Device.Pins.OnboardLedGreen, Device.Pins.OnboardLedBlue);
            led.SetColor(RgbLed.Colors.Red);

            // Important note: You can only use on Push Button per Group Set (GSXX)
            pushButtons = new List <PushButton>
            {
                new PushButton(Device, Device.Pins.A04, Meadow.Hardware.ResistorMode.PullUp),         // <- GS00
                //new PushButton(Device, Device.Pins.D06, Meadow.Hardware.ResistorMode.PullUp),         // <- GS00

                new PushButton(Device, Device.Pins.A05, Meadow.Hardware.ResistorMode.PullUp),         // <- GS01
                //new PushButton(Device, Device.Pins.D09, Meadow.Hardware.ResistorMode.PullUp),         // <- GS01

                new PushButton(Device, Device.Pins.A02, Meadow.Hardware.ResistorMode.PullUp),         // <- GS03
                //new PushButton(Device, Device.Pins.D14, Meadow.Hardware.ResistorMode.PullUp),         // <- GS03
                //new PushButton(Device, Device.Pins.D15, Meadow.Hardware.ResistorMode.PullUp)          // <- GS03

                new PushButton(Device, Device.Pins.A00, Meadow.Hardware.ResistorMode.PullUp),         // <- GS04

                new PushButton(Device, Device.Pins.A01, Meadow.Hardware.ResistorMode.PullUp),         // <- GS05
                //new PushButton(Device, Device.Pins.ESP_MOSI, Meadow.Hardware.ResistorMode.PullUp),    // <- GS05

                new PushButton(Device, Device.Pins.D02, Meadow.Hardware.ResistorMode.PullUp),         // <- GS06
                //new PushButton(Device, Device.Pins.D08, Meadow.Hardware.ResistorMode.PullUp),         // <- GS06

                new PushButton(Device, Device.Pins.A03, Meadow.Hardware.ResistorMode.PullUp),         // <- GS07
                //new PushButton(Device, Device.Pins.D05, Meadow.Hardware.ResistorMode.PullUp),         // <- GS07
                //new PushButton(Device, Device.Pins.D07, Meadow.Hardware.ResistorMode.PullUp),         // <- GS07

                new PushButton(Device, Device.Pins.D03, Meadow.Hardware.ResistorMode.PullUp),         // <- GS08

                new PushButton(Device, Device.Pins.D00, Meadow.Hardware.ResistorMode.PullUp),         // <- GS09
                //new PushButton(Device, Device.Pins.D04, Meadow.Hardware.ResistorMode.PullUp),         // <- GS09
                //new PushButton(Device, Device.Pins.D11, Meadow.Hardware.ResistorMode.PullUp),         // <- GS09

                new PushButton(Device, Device.Pins.D10, Meadow.Hardware.ResistorMode.PullUp),         // <- GS10

                new PushButton(Device, Device.Pins.ESP_MISO, Meadow.Hardware.ResistorMode.PullUp),    // <- GS11

                new PushButton(Device, Device.Pins.D01, Meadow.Hardware.ResistorMode.PullUp),         // <- GS13

                new PushButton(Device, Device.Pins.D12, Meadow.Hardware.ResistorMode.PullUp),         // <- GS14

                new PushButton(Device, Device.Pins.D13, Meadow.Hardware.ResistorMode.PullUp),         // <- GS15
            };

            for (int i = 0; i < pushButtons.Count; i++)
            {
                pushButtons[i].Clicked += PushbuttonClicked;
                //pushButtons[i].PressStarted += PushbuttonPressStarted;
                //pushButtons[i].PressEnded += PushbuttonPressEnded;
            }

            Console.WriteLine("PushButton(s) ready!!!");
        }
Esempio n. 6
0
        public MeadowApp()
        {
            Console.WriteLine("Start...");
            var rgbLed = new RgbLed(
                Device,
                Device.Pins.OnboardLedRed,
                Device.Pins.OnboardLedGreen,
                Device.Pins.OnboardLedBlue);

            rgbLed.SetColor(RgbLed.Colors.Red);

            Console.Write("Initializing I2C...");
            displayI2C              = new Ssd1306(Device.CreateI2cBus(), 60, Ssd1306.DisplayType.OLED128x32);
            graphicsI2C             = new GraphicsLibrary(displayI2C);
            graphicsI2C.CurrentFont = new Font8x12();
            graphicsI2C.Clear();
            graphicsI2C.Stroke = 1;
            graphicsI2C.DrawRectangle(0, 0, 128, 32);
            graphicsI2C.DrawText(5, 12, "I2C WORKING");
            graphicsI2C.Show();
            Console.WriteLine("done");

            Console.Write("Initializing SPI...");
            displaySPI = new Ili9163(
                device: Device,
                spiBus: Device.CreateSpiBus(),
                chipSelectPin: Device.Pins.D14,
                dcPin: Device.Pins.D11,
                resetPin: Device.Pins.D10,
                width: 128, height: 160);
            graphicsSPI          = new GraphicsLibrary(displaySPI);
            graphicsSPI.Rotation = GraphicsLibrary.RotationType._90Degrees;
            graphicsSPI.Clear();
            graphicsSPI.Stroke = 1;
            graphicsSPI.DrawRectangle(0, 0, 160, 128);
            graphicsSPI.CurrentFont = new Font8x12();
            graphicsSPI.DrawText(7, 7, "SPI WORKING!", Color.White);
            graphicsSPI.Show();
            Console.WriteLine("done");

            temperatures = new List <AnalogTemperature>
            {
                new AnalogTemperature(Device, Device.Pins.A00, AnalogTemperature.KnownSensorType.LM35),
                new AnalogTemperature(Device, Device.Pins.A01, AnalogTemperature.KnownSensorType.LM35),
                new AnalogTemperature(Device, Device.Pins.A02, AnalogTemperature.KnownSensorType.LM35),
                new AnalogTemperature(Device, Device.Pins.A03, AnalogTemperature.KnownSensorType.LM35),
                new AnalogTemperature(Device, Device.Pins.A04, AnalogTemperature.KnownSensorType.LM35),
                new AnalogTemperature(Device, Device.Pins.A05, AnalogTemperature.KnownSensorType.LM35),
            };

            rgbLed.SetColor(RgbLed.Colors.Green);

            TestTemperatures();
        }
        public App()
        {
            object spiLock = new object();             //two devices on one spi bus, needs a lockObject

            ST7567.ST7567Pinning displayPinning = new ST7567.ST7567Pinning()
            {
                RST     = 2,
                A0      = 7,
                CS      = 0, //note this is not the pin but the /dev/spi1.x
                SpiBus  = 1,
                SpiLock = spiLock,
            };
            Display = new ST7567(displayPinning, 128, 64);

            PN5180.PN5180Pinning pn5180Pinning = new PN5180.PN5180Pinning()
            {
                RST  = 19,
                BUSY = 18,
                NSS  = 10,
                //IRQ = 18,
                CS      = 1, //note this is not the pin but the /dev/spi1.x
                SpiBus  = 1,
                SpiLock = spiLock,
            };
            Mifare = new PN5180(pn5180Pinning);

            RgbLed.RgbLedPinning rgbLedPinning = new RgbLed.RgbLedPinning()
            {
                Red   = 0,
                Green = 1,
                Blue  = 3
            };
            RgbLed = new RgbLed(rgbLedPinning);

            DigitalEncoder.DigitalEncoderPinning digitalEncoderPinning = new DigitalEncoder.DigitalEncoderPinning()
            {
                Enc0 = 12,
                Enc1 = 198,
                Enc2 = 199
            };
            DigitalEncoder            = new DigitalEncoder(digitalEncoderPinning);
            DigitalEncoder.Pushed    += DigitalEncoder_Pushed;
            DigitalEncoder.Releashed += DigitalEncoder_Releashed;
            DigitalEncoder.Right     += DigitalEncoder_Right;
            DigitalEncoder.Left      += DigitalEncoder_Left;

            Buzzer.BuzzerPinning buzzerPinning = new Buzzer.BuzzerPinning()
            {
                BuzzerPin = 6, //PA6
            };
            Buzzer = new Buzzer(buzzerPinning);

            UpdateScreen();
        }
Esempio n. 8
0
        public MeadowApp()
        {
            var led = new RgbLed(Device, Device.Pins.OnboardLedRed, Device.Pins.OnboardLedGreen, Device.Pins.OnboardLedBlue);

            led.SetColor(RgbLed.Colors.Red);

            servo = new Servo(Device.CreatePwmPort(Device.Pins.D03), NamedServoConfigs.SG90);
            servo.RotateTo(0);
            Thread.Sleep(1000);
            servo.RotateTo(180);

            button          = new PushButton(Device, Device.Pins.D04);
            button.Clicked += ButtonClicked;

            led.SetColor(RgbLed.Colors.Green);
        }
Esempio n. 9
0
        public MeadowApp()
        {
            var led = new RgbLed(Device, Device.Pins.OnboardLedRed, Device.Pins.OnboardLedGreen, Device.Pins.OnboardLedBlue);

            led.SetColor(RgbLed.Colors.Red);

            stopwatch = new Stopwatch();

            startStop = new PushButton(
                device: Device,
                inputPin: Device.Pins.D12,
                resistorMode: Meadow.Hardware.ResistorMode.InternalPullUp);
            startStop.Clicked += StartStopClicked;

            reset = new PushButton(
                device: Device,
                inputPin: Device.Pins.D13,
                resistorMode: Meadow.Hardware.ResistorMode.InternalPullUp);
            reset.Clicked += ResetClicked;

            display = new FourDigitSevenSegment
                      (
                portDigit1: Device.CreateDigitalOutputPort(Device.Pins.D00),
                portDigit2: Device.CreateDigitalOutputPort(Device.Pins.D03),
                portDigit3: Device.CreateDigitalOutputPort(Device.Pins.D04),
                portDigit4: Device.CreateDigitalOutputPort(Device.Pins.D06),
                portA: Device.CreateDigitalOutputPort(Device.Pins.D01),
                portB: Device.CreateDigitalOutputPort(Device.Pins.D05),
                portC: Device.CreateDigitalOutputPort(Device.Pins.D08),
                portD: Device.CreateDigitalOutputPort(Device.Pins.D10),
                portE: Device.CreateDigitalOutputPort(Device.Pins.D11),
                portF: Device.CreateDigitalOutputPort(Device.Pins.D02),
                portG: Device.CreateDigitalOutputPort(Device.Pins.D07),
                portDecimal: Device.CreateDigitalOutputPort(Device.Pins.D09),
                isCommonCathode: true
                      );
            display.SetDisplay("0000".ToCharArray());

            led.SetColor(RgbLed.Colors.Green);

            while (true)
            {
                string time = stopwatch.Elapsed.Minutes.ToString("D2") + stopwatch.Elapsed.Seconds.ToString("D2");
                display.SetDisplay(time.ToCharArray());
                Thread.Sleep(1000);
            }
        }
        private async void initialize()
        {
            controller = GpioController.GetDefault();
            resetLights();
            //IoTHub connection
            var key = AuthenticationMethodFactory.CreateAuthenticationWithRegistrySymmetricKey(Config.Default.DeviceName, Config.Default.DeviceKey);
            deviceClient = DeviceClient.Create(Config.Default.IotHubUri, key, TransportType.Http1);

            //RGB LED PWM controller
            if (ApiInformation.IsApiContractPresent("Windows.Devices.DevicesLowLevelContract", 1))
            {
                try
                {
                    //check if the GPIO exists
                    if (controller != null)
                    {
                        var provider = PwmProviderSoftware.GetPwmProvider();
                        if (provider != null)
                        {
                            var controllers = (await PwmController.GetControllersAsync(provider));
                            if (controllers != null)
                            {
                                var controller = controllers.FirstOrDefault();
                                if (controller != null)
                                {
                                    controller.SetDesiredFrequency(100);
                                    var pinR = controller.OpenPin(ledPinNumberR);
                                    var pinG = controller.OpenPin(ledPinNumberG);
                                    var pinB = controller.OpenPin(ledPinNumberB);
                                    rgbLed = new RgbLed(pinR, pinG, pinB);
                                    rgbLed.On();
                                    rgbLed.Color = Colors.White;
                                    Task.Delay(50).Wait();
                                    rgbLed.Color = Colors.Black;
                                }
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    System.Diagnostics.Debug.WriteLine(ex.Message);
                }
            }

            await receiveCommands(deviceClient);
        }
Esempio n. 11
0
        public MeadowApp()
        {
            var led = new RgbLed(Device, Device.Pins.OnboardLedRed, Device.Pins.OnboardLedGreen, Device.Pins.OnboardLedBlue);

            led.SetColor(RgbLed.Colors.Red);

            shiftRegister = new x74595(
                device: Device,
                spiBus: Device.CreateSpiBus(),
                pinChipSelect: Device.Pins.D03,
                pins: 8);

            shiftRegister.Clear(true);

            TestX74595();

            led.SetColor(RgbLed.Colors.Green);
        }
Esempio n. 12
0
        void Initialize()
        {
            led = new RgbLed(
                Device,
                Device.Pins.OnboardLedRed,
                Device.Pins.OnboardLedGreen,
                Device.Pins.OnboardLedBlue);
            led.SetColor(RgbLed.Colors.Red);

            ledUp      = new PwmLed(Device, Device.Pins.D13, TypicalForwardVoltage.Red);
            ledDown    = new PwmLed(Device, Device.Pins.D10, TypicalForwardVoltage.Red);
            ledLeft    = new PwmLed(Device, Device.Pins.D11, TypicalForwardVoltage.Red);
            ledRight   = new PwmLed(Device, Device.Pins.D12, TypicalForwardVoltage.Red);
            ledUp.IsOn = ledDown.IsOn = ledLeft.IsOn = ledRight.IsOn = true;

            var motorLeft = new HBridgeMotor
                            (
                device: Device,
                a1Pin: Device.Pins.D05,
                a2Pin: Device.Pins.D06,
                enablePin: Device.Pins.D07
                            );
            var motorRight = new HBridgeMotor
                             (
                device: Device,
                a1Pin: Device.Pins.D02,
                a2Pin: Device.Pins.D03,
                enablePin: Device.Pins.D04
                             );

            carController = new CarController(motorLeft, motorRight);

            led.SetColor(RgbLed.Colors.Blue);

            bleTreeDefinition = GetDefinition();
            Device.BluetoothAdapter.StartBluetoothServer(bleTreeDefinition);

            up.ValueSet    += UpValueSet;
            down.ValueSet  += DownValueSet;
            left.ValueSet  += LeftValueSet;
            right.ValueSet += RightValueSet;

            led.SetColor(RgbLed.Colors.Green);
        }
Esempio n. 13
0
        async void InitPwm()
        {
            var gpio_controller = GpioController.GetDefault();
            var manager         = new PwmProviderManager();

            manager.Providers.Add(new SoftPwm());
            var controllers = await manager.GetControllersAsync();

            _controller = controllers[0];
            _controller.SetDesiredFrequency(120);

            _led = new RgbLed
            {
                RedPin   = _controller.OpenPin(PIN_R),
                GreenPin = _controller.OpenPin(PIN_G),
                BluePin  = _controller.OpenPin(PIN_B),
                Color    = Colors.Black
            };
        }
Esempio n. 14
0
        public MeadowApp()
        {
            var led = new RgbLed(Device, Device.Pins.OnboardLedRed, Device.Pins.OnboardLedGreen, Device.Pins.OnboardLedBlue);

            led.SetColor(RgbLed.Colors.Red);

            up    = new Led(Device.CreateDigitalOutputPort(Device.Pins.D15));
            down  = new Led(Device.CreateDigitalOutputPort(Device.Pins.D12));
            left  = new Led(Device.CreateDigitalOutputPort(Device.Pins.D14));
            right = new Led(Device.CreateDigitalOutputPort(Device.Pins.D13));

            mpu = new Mpu6050(Device.CreateI2cBus());
            //mpu.AccelerationChangeThreshold = 0.05f;
            //mpu.Updated += MpuUpdated;
            //mpu.StartUpdating(100);

            up.IsOn = true;

            led.SetColor(RgbLed.Colors.Green);
        }
Esempio n. 15
0
        public MeadowApp()
        {
            var led = new RgbLed(Device, Device.Pins.OnboardLedRed, Device.Pins.OnboardLedGreen, Device.Pins.OnboardLedBlue);

            led.SetColor(RgbLed.Colors.Red);

            x = y = 120;

            var config = new SpiClockConfiguration(
                speedKHz: 6000,
                mode: SpiClockConfiguration.Mode.Mode3);

            st7789 = new St7789(
                device: Device,
                spiBus: Device.CreateSpiBus(
                    clock: Device.Pins.SCK,
                    mosi: Device.Pins.MOSI,
                    miso: Device.Pins.MISO,
                    config: config),
                chipSelectPin: null,
                dcPin: Device.Pins.D01,
                resetPin: Device.Pins.D00,
                width: 240, height: 240);

            graphics = new GraphicsLibrary(st7789);
            graphics.Clear(true);
            graphics.DrawRectangle(0, 0, 240, 240, Color.White, true);
            graphics.DrawPixel(x, y, Color.Red);
            graphics.Show();

            rotaryX = new RotaryEncoderWithButton(Device,
                                                  Device.Pins.A00, Device.Pins.A01, Device.Pins.A02);
            rotaryX.Rotated += RotaryXRotated;

            rotaryY = new RotaryEncoderWithButton(Device,
                                                  Device.Pins.D02, Device.Pins.D03, Device.Pins.D04);
            rotaryY.Rotated += RotaryYRotated;
            rotaryY.Clicked += RotaryYClicked;

            led.SetColor(RgbLed.Colors.Green);
        }
Esempio n. 16
0
        public MeadowApp()
        {
            var rgbLed = new RgbLed(
                Device,
                Device.Pins.OnboardLedRed,
                Device.Pins.OnboardLedGreen,
                Device.Pins.OnboardLedBlue
                );

            rgbLed.SetColor(RgbLed.Colors.Red);

            var config = new SpiClockConfiguration(
                speedKHz: 6000,
                mode: SpiClockConfiguration.Mode.Mode3);

            display = new St7789
                      (
                device: Device,
                spiBus: Device.CreateSpiBus(
                    Device.Pins.SCK,
                    Device.Pins.MOSI,
                    Device.Pins.MISO,
                    config),
                chipSelectPin: null,
                dcPin: Device.Pins.D01,
                resetPin: Device.Pins.D00,
                width: 240, height: 240
                      );

            graphics          = new GraphicsLibrary(display);
            graphics.Rotation = GraphicsLibrary.RotationType._270Degrees;

            motionSensor = new ParallaxPir(Device, Device.Pins.D08, InterruptMode.EdgeFalling, ResistorMode.Disabled, 5, 0);
            motionSensor.OnMotionStart += MotionSensorMotionStart;
            motionSensor.OnMotionEnd   += MotionSensorMotionEnd;

            rgbLed.SetColor(RgbLed.Colors.Green);

            LoadScreen();
        }
Esempio n. 17
0
        public MeadowApp()
        {
            var led = new RgbLed(Device, Device.Pins.OnboardLedRed, Device.Pins.OnboardLedGreen, Device.Pins.OnboardLedBlue);

            led.SetColor(RgbLed.Colors.Red);

            mcp = new Mcp23x08(Device.CreateI2cBus(), true, true, true);

            leds = new List <Led>();
            leds.Add(new Led(mcp.CreateDigitalOutputPort(mcp.Pins.GP0)));
            leds.Add(new Led(mcp.CreateDigitalOutputPort(mcp.Pins.GP1)));
            leds.Add(new Led(mcp.CreateDigitalOutputPort(mcp.Pins.GP2)));
            leds.Add(new Led(mcp.CreateDigitalOutputPort(mcp.Pins.GP3)));
            leds.Add(new Led(mcp.CreateDigitalOutputPort(mcp.Pins.GP4)));
            leds.Add(new Led(mcp.CreateDigitalOutputPort(mcp.Pins.GP5)));
            leds.Add(new Led(mcp.CreateDigitalOutputPort(mcp.Pins.GP6)));
            leds.Add(new Led(mcp.CreateDigitalOutputPort(mcp.Pins.GP7)));

            led.SetColor(RgbLed.Colors.Green);

            CycleLeds();
        }
Esempio n. 18
0
        void InitializePeripherals()
        {
            var led = new RgbLed(Device, Device.Pins.OnboardLedRed, Device.Pins.OnboardLedGreen, Device.Pins.OnboardLedBlue);

            led.SetColor(RgbLed.Colors.Red);

            var i2CBus = Device.CreateI2cBus();

            radio = new Tea5767(i2CBus);

            display           = new Ssd1306(i2CBus, 60, Ssd1306.DisplayType.OLED128x32);
            graphics          = new GraphicsLibrary(display);
            graphics.Rotation = GraphicsLibrary.RotationType._180Degrees;

            btnNext          = new PushButton(Device, Device.Pins.D03, ResistorMode.InternalPullUp);
            btnNext.Clicked += BtnNextClicked;

            btnPrevious          = new PushButton(Device, Device.Pins.D04, ResistorMode.InternalPullUp);
            btnPrevious.Clicked += BtnPreviousClicked;

            led.SetColor(RgbLed.Colors.Green);
        }
Esempio n. 19
0
        public MeadowApp()
        {
            var led = new RgbLed(Device, Device.Pins.OnboardLedRed, Device.Pins.OnboardLedGreen, Device.Pins.OnboardLedBlue);

            led.SetColor(RgbLed.Colors.Red);

            leds    = new PwmLed[7];
            leds[0] = new PwmLed(Device.CreatePwmPort(Device.Pins.D06), TypicalForwardVoltage.Red);  //
            leds[1] = new PwmLed(Device.CreatePwmPort(Device.Pins.D07), TypicalForwardVoltage.Red);  // [6]       [5]
            leds[2] = new PwmLed(Device.CreatePwmPort(Device.Pins.D08), TypicalForwardVoltage.Red);  //
            leds[3] = new PwmLed(Device.CreatePwmPort(Device.Pins.D09), TypicalForwardVoltage.Red);  // [4]  [3]  [2]
            leds[4] = new PwmLed(Device.CreatePwmPort(Device.Pins.D10), TypicalForwardVoltage.Red);  //
            leds[5] = new PwmLed(Device.CreatePwmPort(Device.Pins.D11), TypicalForwardVoltage.Red);  // [1]       [0]
            leds[6] = new PwmLed(Device.CreatePwmPort(Device.Pins.D12), TypicalForwardVoltage.Red);  //

            button          = new PushButton(Device, Device.Pins.D05);
            button.Clicked += ButtonClicked;

            led.SetColor(RgbLed.Colors.Green);

            ShuffleAnimation();
        }
Esempio n. 20
0
        //Max7219 display;
        //GraphicsLibrary graphics;

        public MeadowApp()
        {
            Console.Write("Initializing...");

            var led = new RgbLed(Device, Device.Pins.OnboardLedRed, Device.Pins.OnboardLedGreen, Device.Pins.OnboardLedBlue);

            led.SetColor(RgbLed.Colors.Red);

            display = new CharacterDisplay
                      (
                device: Device,
                pinV0: Device.Pins.D11,
                pinRS: Device.Pins.D10,
                pinE: Device.Pins.D09,
                pinD4: Device.Pins.D08,
                pinD5: Device.Pins.D07,
                pinD6: Device.Pins.D06,
                pinD7: Device.Pins.D05
                      );

            //display = new Max7219(Device, Device.CreateSpiBus(), Device.Pins.D01, 4, Max7219.Max7219Type.Display);
            //graphics = new GraphicsLibrary(display);
            //graphics.CurrentFont = new Font4x8();
            //graphics.Rotation = RotationType._180Degrees;

            hour            = new PushButton(Device, Device.Pins.D15);
            hour.Clicked   += HourClicked;
            minute          = new PushButton(Device, Device.Pins.D12);
            minute.Clicked += MinuteClicked;

            Device.SetClock(new DateTime(2020, 03, 31, 00, 45, 00));

            led.SetColor(RgbLed.Colors.Green);
            Console.WriteLine("done");

            CharacterDisplayClock();
            //RunClock();
        }
Esempio n. 21
0
        private void CycleLedsMeadowFoundation()
        {
            const int wait = 200;

            RgbLed led = new RgbLed(Device,
                                    redPin: Device.Pins.OnboardLedRed,
                                    greenPin: Device.Pins.OnboardLedGreen,
                                    bluePin: Device.Pins.OnboardLedBlue);

            RgbLed.Colors currentColor = RgbLed.Colors.count;

            while (true)
            {
                do
                {
                    currentColor = currentColor.GetNext();
                }while (currentColor == RgbLed.Colors.count); // Skip RgbLed.Colors.count

                Console.WriteLine($"Setting color to {currentColor}.");
                led.SetColor(currentColor);
                Thread.Sleep(wait);
            }
        }
Esempio n. 22
0
        void Initialize()
        {
            var onboardLed = new RgbPwmLed(
                device: Device,
                redPwmPin: Device.Pins.OnboardLedRed,
                greenPwmPin: Device.Pins.OnboardLedGreen,
                bluePwmPin: Device.Pins.OnboardLedBlue);

            onboardLed.SetColor(Color.Red);

            rgbLed = new RgbLed(
                Device.CreateDigitalOutputPort(Device.Pins.D02),
                Device.CreateDigitalOutputPort(Device.Pins.D03),
                Device.CreateDigitalOutputPort(Device.Pins.D04)
                );
            rgbPwmLed = new RgbPwmLed(
                Device.CreatePwmPort(Device.Pins.D02),
                Device.CreatePwmPort(Device.Pins.D03),
                Device.CreatePwmPort(Device.Pins.D04)
                );

            onboardLed.SetColor(Color.Green);
        }
Esempio n. 23
0
        public MeadowApp()
        {
            var led = new RgbLed(
                Device,
                Device.Pins.OnboardLedRed,
                Device.Pins.OnboardLedGreen,
                Device.Pins.OnboardLedBlue);

            led.SetColor(RgbLed.Colors.Red);

            up      = new PwmLed(Device, Device.Pins.D13, TypicalForwardVoltage.Red);
            down    = new PwmLed(Device, Device.Pins.D10, TypicalForwardVoltage.Red);
            left    = new PwmLed(Device, Device.Pins.D11, TypicalForwardVoltage.Red);
            right   = new PwmLed(Device, Device.Pins.D12, TypicalForwardVoltage.Red);
            up.IsOn = down.IsOn = left.IsOn = right.IsOn = false;

            var motorLeft = new HBridgeMotor
                            (
                device: Device,
                a1Pin: Device.Pins.D05,
                a2Pin: Device.Pins.D06,
                enablePin: Device.Pins.D07
                            );
            var motorRight = new HBridgeMotor
                             (
                device: Device,
                a1Pin: Device.Pins.D02,
                a2Pin: Device.Pins.D03,
                enablePin: Device.Pins.D04
                             );

            carController = new CarController(motorLeft, motorRight);

            led.SetColor(RgbLed.Colors.Green);

            TestCar();
        }
Esempio n. 24
0
        public MeadowApp()
        {
            var led = new RgbLed(Device, Device.Pins.OnboardLedRed, Device.Pins.OnboardLedGreen, Device.Pins.OnboardLedBlue);

            led.SetColor(RgbLed.Colors.Red);

            buttonUp          = new PushButton(Device, Device.Pins.D03);
            buttonUp.Clicked += ButtonUpClicked;

            buttonDown          = new PushButton(Device, Device.Pins.D04);
            buttonDown.Clicked += ButtonDownClicked;

            var config = new SpiClockConfiguration(
                speedKHz: 6000,
                mode: SpiClockConfiguration.Mode.Mode3);

            display = new St7789
                      (
                device: Device,
                spiBus: Device.CreateSpiBus(
                    clock: Device.Pins.SCK,
                    mosi: Device.Pins.MOSI,
                    miso: Device.Pins.MISO,
                    config: config),
                chipSelectPin: null,
                dcPin: Device.Pins.D01,
                resetPin: Device.Pins.D00,
                width: 240, height: 240
                      );

            graphics          = new GraphicsLibrary(display);
            graphics.Rotation = GraphicsLibrary.RotationType._270Degrees;

            DisplayJPG();

            led.SetColor(RgbLed.Colors.Green);
        }
Esempio n. 25
0
        public MeadowApp()
        {
            var led = new RgbLed(Device, Device.Pins.OnboardLedRed, Device.Pins.OnboardLedGreen, Device.Pins.OnboardLedBlue);

            led.SetColor(RgbLed.Colors.Red);

            analogTemperature = new AnalogTemperature(
                device: Device,
                analogPin: Device.Pins.A00,
                sensorType: AnalogTemperature.KnownSensorType.LM35
                );
            analogTemperature.Updated += AnalogTemperatureUpdated;

            var config = new SpiClockConfiguration(
                speedKHz: 6000,
                mode: SpiClockConfiguration.Mode.Mode3);

            st7789 = new St7789
                     (
                device: Device,
                spiBus: Device.CreateSpiBus(Device.Pins.SCK, Device.Pins.MOSI, Device.Pins.MISO, config),
                chipSelectPin: Device.Pins.D02,
                dcPin: Device.Pins.D01,
                resetPin: Device.Pins.D00,
                width: 240, height: 240
                     );
            displayWidth  = Convert.ToInt32(st7789.Width);
            displayHeight = Convert.ToInt32(st7789.Height);

            graphics          = new GraphicsLibrary(st7789);
            graphics.Rotation = GraphicsLibrary.RotationType._270Degrees;

            led.SetColor(RgbLed.Colors.Green);

            LoadScreen();
            analogTemperature.StartUpdating();
        }
Esempio n. 26
0
        public static void Main()
        {
            // Defines an RGB Led connected to three PWM pins, common cathode
            // Some RGB-leds are common anode, in those cases, set the last boolean on true
            RgbLed Led = new RgbLed(new Netduino.PWM(Pins.GPIO_PIN_D9), new Netduino.PWM(Pins.GPIO_PIN_D6), new Netduino.PWM(Pins.GPIO_PIN_D5), false);

            while (true)
            {
                // Fade to red
                for (byte Red = 0; Red < 255; ++Red)
                {
                    Led.Write(Red, 0, 0);
                    Thread.Sleep(25);
                }
                // Fade to green
                for (byte Green = 0; Green < 255; ++Green)
                {
                    Led.Write(0, Green, 0);
                    Thread.Sleep(25);
                }
                // Fade to blue
                for (byte Blue = 0; Blue < 255; ++Blue)
                {
                    Led.Write(0, 0, Blue);
                    Thread.Sleep(25);
                }

                Led.Write(0x0000ff); Thread.Sleep(500); // Blue
                Led.Write(0x00ff00); Thread.Sleep(500); // Green
                Led.Write(0x00ffff); Thread.Sleep(500); // Turquoise
                Led.Write(0xff0000); Thread.Sleep(500); // Red
                Led.Write(0xff00ff); Thread.Sleep(500); // Purple
                Led.Write(0xffff00); Thread.Sleep(500); // Yellow
                Led.Write(0xffffff); Thread.Sleep(500); // White
                Led.Write(0x000000); Thread.Sleep(500); // Off
            }
        }
Esempio n. 27
0
        void Initialize()
        {
            var led = new RgbLed(
                Device,
                Device.Pins.OnboardLedRed,
                Device.Pins.OnboardLedGreen,
                Device.Pins.OnboardLedBlue);

            led.SetColor(RgbLed.Colors.Red);

            var config = new SpiClockConfiguration(24000, SpiClockConfiguration.Mode.Mode3);
            var spiBus = Device.CreateSpiBus(
                Device.Pins.SCK,
                Device.Pins.MOSI,
                Device.Pins.MISO, config);

            display = new St7789(device: Device, spiBus: spiBus,
                                 chipSelectPin: Device.Pins.D02,
                                 dcPin: Device.Pins.D01,
                                 resetPin: Device.Pins.D00,
                                 width: 240, height: 240);

            graphics             = new GraphicsLibrary(display);
            graphics.CurrentFont = new Font12x20();
            graphics.Rotation    = GraphicsLibrary.RotationType._270Degrees;

            var i2cBus = Device.CreateI2cBus(I2cBusSpeed.FastPlus);

            sensor = new Vl53l0x(Device, i2cBus);
            sensor.StartUpdating(200);

            servo = new Servo(Device.CreatePwmPort(Device.Pins.D05), NamedServoConfigs.SG90);
            servo.RotateTo(0);

            led.SetColor(RgbLed.Colors.Green);
        }
Esempio n. 28
0
        public MeadowApp()
        {
            var led = new RgbLed(Device, Device.Pins.OnboardLedRed, Device.Pins.OnboardLedGreen, Device.Pins.OnboardLedBlue);

            led.SetColor(RgbLed.Colors.Red);

            Up    = new PwmLed(Device.CreatePwmPort(Device.Pins.D07, 100, 0.0f), TypicalForwardVoltage.Red);
            Down  = new PwmLed(Device.CreatePwmPort(Device.Pins.D04, 100, 0.0f), TypicalForwardVoltage.Red);
            Left  = new PwmLed(Device.CreatePwmPort(Device.Pins.D02, 100, 0.0f), TypicalForwardVoltage.Red);
            Right = new PwmLed(Device.CreatePwmPort(Device.Pins.D03, 100, 0.0f), TypicalForwardVoltage.Red);

            joystick = new AnalogJoystick(
                Device.CreateAnalogInputPort(Device.Pins.A01),
                Device.CreateAnalogInputPort(Device.Pins.A00),
                null, true);

            joystick.SetCenterPosition();
            joystick.Updated += JoystickUpdated;
            joystick.StartUpdating();

            led.SetColor(RgbLed.Colors.Green);

            //TestAnalogJoystick();
        }
Esempio n. 29
0
        public MeadowApp()
        {
            var led = new RgbLed(Device, Device.Pins.OnboardLedRed, Device.Pins.OnboardLedGreen, Device.Pins.OnboardLedBlue);

            led.SetColor(RgbLed.Colors.Red);

            var config = new SpiClockConfiguration(6000, SpiClockConfiguration.Mode.Mode3);
            var spiBus = Device.CreateSpiBus(Device.Pins.SCK, Device.Pins.MOSI, Device.Pins.MISO, config);

            display = new St7789(device: Device, spiBus: spiBus,
                                 chipSelectPin: Device.Pins.D02,
                                 dcPin: Device.Pins.D01,
                                 resetPin: Device.Pins.D00,
                                 width: 240, height: 240);

            graphics             = new GraphicsLibrary(display);
            graphics.Rotation    = GraphicsLibrary.RotationType._180Degrees;
            graphics.CurrentFont = new Font12x16();

            sensor = new Mpr121(Device.CreateI2cBus(I2cBusSpeed.Standard), 90, 100);
            sensor.ChannelStatusesChanged += SensorChannelStatusesChanged;

            led.SetColor(RgbLed.Colors.Green);
        }
Esempio n. 30
0
 public LEDService()
 {
     this.rgbLed = new RgbLed();
 }