Exemplo n.º 1
0
        static void Main(string[] args)
        {
            var i2cDevice = I2cDevice.Create(new I2cConnectionSettings(busId: 1, deviceAddress: Mpr121.DefaultI2cAddress));

            // Initialize controller with default configuration and auto-refresh the channel statuses every 100 ms.
            var mpr121 = new Mpr121(device: i2cDevice, periodRefresh: 100);

            Console.Clear();
            Console.CursorVisible = false;

            PrintChannelsTable();
            Console.WriteLine("Press Enter to exit.");

            // Subscribe to channel statuses updates.
            mpr121.ChannelStatusesChanged += (object sender, ChannelStatusesChangedEventArgs e) =>
            {
                var channelStatuses = e.ChannelStatuses;
                foreach (var channel in channelStatuses.Keys)
                {
                    Console.SetCursorPosition(14, (int)channel * 2 + 1);
                    Console.Write(channelStatuses[channel] ? "#" : " ");
                }
            };

            using (mpr121)
            {
                Console.ReadLine();
                Console.Clear();
                Console.CursorVisible = true;
            }
        }
Exemplo n.º 2
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);

            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 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 MicroGraphics(display);
            graphics.Rotation    = RotationType._180Degrees;
            graphics.CurrentFont = new Font12x16();

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

            onboardLed.SetColor(Color.Green);
        }
Exemplo n.º 3
0
        public void Init()
        {
            Console.WriteLine("Init...");

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

            Console.WriteLine("Create Spi bus");

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

            Console.WriteLine("Create display driver instance");

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

            Console.WriteLine("Create graphics lib");

            graphics             = new GraphicsLibrary(display);
            graphics.Rotation    = GraphicsLibrary.RotationType._90Degrees;
            graphics.CurrentFont = new Font12x16();
        }
Exemplo n.º 4
0
        public void Init()
        {
            Console.WriteLine("Init...");

            sensor = new Mpr121(Device.CreateI2cBus(Meadow.Hardware.I2cBusSpeed.Standard), 90, 100);
            sensor.ChannelStatusesChanged += Sensor_ChannelStatusesChanged;
        }
Exemplo n.º 5
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);
        }