示例#1
0
    public MeadowApp()
    {
        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;
    }
示例#2
0
        public MeadowApp()
        {
            Console.WriteLine("Initializing...");

            rotaryEncoderWithButton          = new RotaryEncoderWithButton(Device, Device.Pins.D15, Device.Pins.D14, Device.Pins.D13);
            rotaryEncoderWithButton.Rotated += (s, e) =>
            {
                if (e.Direction == Meadow.Peripherals.Sensors.Rotary.RotationDirection.Clockwise)
                {
                    value++;
                }
                else
                {
                    value--;
                }

                Console.WriteLine("Value = {0}", value);
            };
            rotaryEncoderWithButton.Clicked += (s, e) =>
            {
                Console.WriteLine("Button Clicked");
            };
            rotaryEncoderWithButton.PressEnded += (s, e) =>
            {
                Console.WriteLine("Press ended");
            };
            rotaryEncoderWithButton.PressStarted += (s, e) =>
            {
                Console.WriteLine("Press started");
            };

            Console.WriteLine("RotaryEncoderWithButton ready...");
        }
        void Initialize()
        {
            Console.WriteLine("Initialize hardware...");

            onboardLed = new RgbPwmLed(device: Device,
                                       redPwmPin: Device.Pins.OnboardLedRed,
                                       greenPwmPin: Device.Pins.OnboardLedGreen,
                                       bluePwmPin: Device.Pins.OnboardLedBlue,
                                       3.3f, 3.3f, 3.3f,
                                       Meadow.Peripherals.Leds.IRgbLed.CommonType.CommonAnode);

            Console.WriteLine("Create Display with SPI...");

            var config = new Meadow.Hardware.SpiClockConfiguration(12000, Meadow.Hardware.SpiClockConfiguration.Mode.Mode0);

            var bus = Device.CreateSpiBus(Device.Pins.SCK, Device.Pins.MOSI, Device.Pins.MISO, config);

            ssd1309 = new Ssd1309
                      (
                device: Device,
                spiBus: bus,
                chipSelectPin: Device.Pins.D02,
                dcPin: Device.Pins.D01,
                resetPin: Device.Pins.D00
                      );



            Console.WriteLine("Create GraphicsLibrary...");

            display = new GraphicsLibrary(ssd1309)
            {
                CurrentFont = new Font8x12(),
                //   Rotation = GraphicsLibrary.RotationType._270Degrees
            };

            Console.WriteLine("Load menu data...");

            var menuData = LoadResource("menu.json");

            Console.WriteLine($"Data length: {menuData.Length}...");

            Console.WriteLine("Create buttons...");
            var encoder = new RotaryEncoderWithButton(Device, Device.Pins.D13, Device.Pins.D14, Device.Pins.D15);

            //   next = new PushButton(Device, Device.Pins.D15);
            //   select = new PushButton(Device, Device.Pins.D12);
            //   previous = new PushButton(Device, Device.Pins.D11);

            Console.WriteLine("Create menu...");

            //     menu = new Menu(display, next, previous, select, menuData, false);


            menu = new Menu(display, encoder, menuData, false);

            Console.WriteLine("Enable menu...");

            menu.Enable();
        }
示例#4
0
        public RotaryEncoderWithButtonApp()
        {
            Console.WriteLine("Initializing...");
            rotaryEncoderWithButton               = new RotaryEncoderWithButton(Device, Device.Pins.D00, Device.Pins.D01, Device.Pins.D02);
            rotaryEncoderWithButton.Rotated      += RotaryEncoderRotated;
            rotaryEncoderWithButton.Clicked      += RotaryEncoderButtonClicked;
            rotaryEncoderWithButton.PressEnded   += RotaryEncoderButtonPressEnded;
            rotaryEncoderWithButton.PressStarted += RotaryEncoderButtonPressStarted;

            Console.WriteLine("Start rotating the encoder or press the button...");
        }
示例#5
0
        public Menu(ITextDisplay display, RotaryEncoderWithButton encoder, byte[] menuResource)
        {
            var menuJson = new string(System.Text.Encoding.UTF8.GetChars(menuResource));
            var menuData = Json.NETMF.JsonSerializer.DeserializeString(menuJson) as Hashtable;

            if (menuData["menu"] == null)
            {
                throw new ArgumentException("JSON root must contain a 'menu' item");
            }
            _rootMenuPage = CreateMenuPage((ArrayList)menuData["menu"], false);
            Init(display, encoder, _rootMenuPage);
        }
示例#6
0
        public App()
        {
            _encoder = new RotaryEncoderWithButton(
                N.Pins.GPIO_PIN_D2, N.Pins.GPIO_PIN_D3, N.Pins.GPIO_PIN_D4,
                Netduino.Foundation.CircuitTerminationType.CommonGround);
            _display = new SerialLCD(new TextDisplayConfig()
            {
                Height = 4, Width = 20
            }) as ITextDisplay;

            // set display brightness
            _display.SetBrightness();

            _menu               = new Menu(_display, _encoder, Resources.GetBytes(Resources.BinaryResources.menu));
            _menu.Selected     += HandleMenuSelected;
            _menu.ValueChanged += HandleMenuValueChanged;
        }
        public MeadowApp()
        {
            var onboardLed = new RgbPwmLed(
                device: Device,
                redPwmPin: Device.Pins.OnboardLedRed,
                greenPwmPin: Device.Pins.OnboardLedGreen,
                bluePwmPin: Device.Pins.OnboardLedBlue);

            onboardLed.SetColor(Color.Red);

            x = y = 120;

            var config = new SpiClockConfiguration(
                speed: new Frequency(48000, Frequency.UnitType.Kilohertz),
                mode: SpiClockConfiguration.Mode.Mode3);
            var spiBus = Device.CreateSpiBus(
                clock: Device.Pins.SCK,
                copi: Device.Pins.MOSI,
                cipo: Device.Pins.MISO,
                config: config);
            var st7789 = new St7789(
                device: Device,
                spiBus: spiBus,
                chipSelectPin: null,
                dcPin: Device.Pins.D01,
                resetPin: Device.Pins.D00,
                width: 240, height: 240);

            graphics = new MicroGraphics(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;

            onboardLed.SetColor(Color.Green);
        }
示例#8
0
        private void Init(ITextDisplay display, RotaryEncoderWithButton encoder, MenuPage menuTree)
        {
            _display = display;
            _encoder = encoder;

            _rootMenuPage = menuTree;
            UpdatedCurrentMenuPage();
            RenderCurrentMenuPage();
            _menuLevel = new Stack();

            _encoder.Rotated += HandlEncoderRotation;
            _encoder.Clicked += HandleEncoderClick;

            // Save our custom characters
            _display.SaveCustomCharacter(TextCharacters.RightArrow.CharMap, TextCharacters.RightArrow.MemorySlot);
            _display.SaveCustomCharacter(TextCharacters.RightArrowSelected.CharMap, TextCharacters.RightArrow.MemorySlot);
            _display.SaveCustomCharacter(TextCharacters.BoxSelected.CharMap, TextCharacters.BoxSelected.MemorySlot);
        }
示例#9
0
        protected void InitializePeripherals()
        {
            // display
            //_display = new Lcd2004(new MCP23008());
            _display = new Lcd2004(N.Pins.GPIO_PIN_D8, N.Pins.GPIO_PIN_D9, N.Pins.GPIO_PIN_D10, N.Pins.GPIO_PIN_D11, N.Pins.GPIO_PIN_D12, N.Pins.GPIO_PIN_D13);
            _display.Clear();
            _display.WriteLine("Display up!", 0);

            // rotary encoder
            _encoder = new RotaryEncoderWithButton(N.Pins.GPIO_PIN_D4, N.Pins.GPIO_PIN_D5, N.Pins.GPIO_PIN_D7, CircuitTerminationType.CommonGround);

            // door stuff
            _doorServo          = new ContinuousRotationServo(N.PWMChannels.PWM_PIN_D6, NamedServoConfigs.IdealContinuousRotationServo);
            _openEndStopSwitch  = new PushButton(N.Pins.GPIO_PIN_D2, CircuitTerminationType.CommonGround);
            _closeEndStopSwitch = new PushButton(N.Pins.GPIO_PIN_D3, CircuitTerminationType.CommonGround);
            _display.WriteLine("Door stuff up!", 1);

            // temp stuff
            _heatLampRelay = new SoftPwm(N.Pins.GPIO_PIN_D0, 0, 1f / 60f);
            _tempSensor    = new AnalogTemperature(N.AnalogChannels.ANALOG_PIN_A0, AnalogTemperature.KnownSensorType.LM35, updateInterval: 5000, temperatureChangeNotificationThreshold: 1.0f);
            _display.WriteLine("Temp stuff up!", 2);

            //==== now wire up all the peripheral events
            // Analog Temp Sensor. Setup to notify at half a degree changes
            _tempSensor.TemperatureChanged += (object sender, SensorFloatEventArgs e) => {
                _currentTemp = e.CurrentValue;
                Debug.Print("Current Temp: " + _currentTemp.ToString("N1"));
                UpdateInfoScreen();
            };

            _encoder.Clicked += (s, e) =>
            {
                // if the menu isn't displayed, display it. otherwise
                // encoder click events are handled by menu
                if (!_inMenu)
                {
                    this.DisplayMenu();
                }
            };


            Debug.Print("Peripherals initialized.");
        }
示例#10
0
        public App()
        {
            // SETUP CONTROL

            // use encoder with push button
            _encoder = new RotaryEncoderWithButton(
                N.Pins.GPIO_PIN_D7, N.Pins.GPIO_PIN_D6, N.Pins.GPIO_PIN_D5,
                Netduino.Foundation.CircuitTerminationType.CommonGround);

            // use buttons
            //_next = new PushButton(N.Pins.GPIO_PIN_D6, Netduino.Foundation.CircuitTerminationType.CommonGround);
            //_previous = new PushButton(N.Pins.GPIO_PIN_D7, Netduino.Foundation.CircuitTerminationType.CommonGround);
            //_select = new PushButton(N.Pins.GPIO_PIN_D5, Netduino.Foundation.CircuitTerminationType.CommonGround);

            // SETUP DISPLAY

            // GPIO
            _display = new Lcd2004(N.Pins.GPIO_PIN_D13, N.Pins.GPIO_PIN_D12, N.Pins.GPIO_PIN_D11, N.Pins.GPIO_PIN_D10, N.Pins.GPIO_PIN_D9, N.Pins.GPIO_PIN_D8);

            // SERIAL LCD
            //_display = new SerialLCD(new TextDisplayConfig() { Height = 4, Width = 20 }) as ITextDisplay;

            // MCP (i2c)
            //_mcp = new MCP23008();
            //_display = new Lcd2004(_mcp);

            // set display brightness
            _display.SetBrightness();

            // Create menu with encoder
            _menu = new Menu(_display, _encoder, Resources.GetBytes(Resources.BinaryResources.menu), true);

            // Create menu with buttons
            //_menu = new Menu(_display, _next, _previous, _select, Resources.GetBytes(Resources.BinaryResources.menu));

            _menu.Selected     += HandleMenuSelected;
            _menu.ValueChanged += HandleMenuValueChanged;
            _menu.Exited       += HandleMenuExited;

            _menu.Enable();
        }
示例#11
0
        /// <summary>
        /// Configures the hardware perihperals (LCD, temp sensor, relays, etc.)
        /// so they can be used by the application.
        /// </summary>
        protected void InitializePeripherals()
        {
            // pushbutton (for testing)
            _pushButton = new PushButton(
                (H.Cpu.Pin) 0x15, CircuitTerminationType.Floating);

            // Rotary Encoder
            _encoder = new RotaryEncoderWithButton(
                N.Pins.GPIO_PIN_D7, N.Pins.GPIO_PIN_D6, N.Pins.GPIO_PIN_D5,
                CircuitTerminationType.CommonGround);

            // LCD
            //_display = new Lcd2004(new MCP23008());
            _display = new Lcd2004(N.Pins.GPIO_PIN_D8, N.Pins.GPIO_PIN_D9, N.Pins.GPIO_PIN_D10, N.Pins.GPIO_PIN_D11, N.Pins.GPIO_PIN_D12, N.Pins.GPIO_PIN_D13);
            _display.Clear();
            Debug.Print("Display up.");
            _display.WriteLine("Display up!", 0);

            // Analog Temp Sensor. Setup to notify at half a degree changes
            _tempSensor = new AnalogTemperature(N.AnalogChannels.ANALOG_PIN_A0,
                                                AnalogTemperature.KnownSensorType.LM35, temperatureChangeNotificationThreshold: 0.5F);
            Debug.Print("TempSensor up.");
            _display.WriteLine("Temp Sensor up!", 1);

            // Heater driven by Software PWM
            _heaterRelayPwm = new SoftPwm(N.Pins.GPIO_PIN_D2, 0.5f, 1.0f / 30.0f);
            Debug.Print("Heater PWM up.");
            _display.WriteLine("Heater PWM up!", 2);

            // Fan Relay
            _fanRelay = new Relay(N.Pins.GPIO_PIN_D3);
            Debug.Print("Fan up.");
            _display.WriteLine("Fan up!", 3);

            // output status
            Debug.Print("Peripherals up");
            _display.WriteLine("Peripherals online!", 0);
        }
示例#12
0
 public void Init(ITextDisplay display, RotaryEncoderWithButton encoder)
 {
     _display = display;
     _encoder = encoder;
     _isInit  = true;
 }
示例#13
0
        /// <summary>
        /// Initializes a new instance of the MeadowApp class
        /// </summary>
        public MeadowApp()
        {
            MeadowApp.DebugWriteLine("Initializing...");

            this.soundGenerator = new SoundGenerator(
                Device.CreateDigitalInputPort(Device.Pins.D03),
                Device.CreateDigitalInputPort(Device.Pins.D04),
                Device.CreatePwmPort(Device.Pins.D07));

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

            this.rotaryPaddle          = new RotaryEncoderWithButton(Device, Device.Pins.D10, Device.Pins.D09, Device.Pins.D08, debounceDuration: 100);
            this.rotaryPaddle.Rotated += this.RotaryPaddle_Rotated;

            this.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);

            this.displayWidth  = Convert.ToInt32(this.st7789.Width);
            this.displayHeight = Convert.ToInt32(this.st7789.Height);

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

            this.asyncGraphics = new AsyncGraphics(graphics);

            this.debounceTimer.AutoReset = false;
            this.debounceTimer.Elapsed  += this.DebounceTimer_Elapsed;

            this.backgroundColor = Color.Blue;

            this.scoreBanner = new Banner(this.displayWidth, this.asyncGraphics, fontHeight: 16, this.backgroundColor, color: Color.Yellow, top: 0)
            {
                Text = Banner.SCORE_TEXT
            };

            this.instructionBanner = new Banner(
                displayWidth: this.displayWidth,
                graphics: this.asyncGraphics,
                fontHeight: 16,
                backgroundColor: this.backgroundColor,
                color: Color.White,
                top: Banner.HEIGHT * 2);
            this.ShowInstructionBanner(Banner.START_TEXT);

            this.paddle = new Paddle(this.asyncGraphics, this.displayWidth, this.displayWidth, this.backgroundColor);

            this.scoreKeeper = new ScoreKeeper();
            this.scoreKeeper.ScoreChanged += this.scoreBanner.OnScoreChanged;

            this.ball = new Ball(
                asyncGraphics: this.asyncGraphics,
                displayWidth: this.displayWidth,
                displayHeight: this.displayHeight,
                backgroundColor: this.backgroundColor,
                paddle: this.paddle,
                soundGenerator: this.soundGenerator,
                minimumY: Banner.HEIGHT + 1,
                scoreKeeper: this.scoreKeeper);

            this.ball.ExplosionOccurred += this.OnExplosionOccurred;

            this.rotaryPaddle.Clicked += this.RotaryPaddle_Clicked;

            this.soundGenerator.PlayConstructionCompleteSound();
        }
示例#14
0
 public Menu(ITextDisplay display, RotaryEncoderWithButton encoder, MenuPage menuTree)
 {
     Init(display, encoder, menuTree);
 }
示例#15
0
 public App()
 {
     // instantiate our peripherals
     this._rotary = new RotaryEncoderWithButton(N.Pins.GPIO_PIN_D6, N.Pins.GPIO_PIN_D7, N.Pins.GPIO_PIN_D5, CircuitTerminationType.CommonGround);
     this._led    = new PwmLed(N.PWMChannels.PWM_PIN_D11, TypicalForwardVoltage.Green);
 }