示例#1
0
        void Initialize()
        {
            Console.WriteLine("Initialize hardware...");

            Console.WriteLine("Create Spi bus");

            var config = new SpiClockConfiguration(24000, 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.CurrentFont = new Font12x20();
            graphics.Rotation    = GraphicsLibrary.RotationType._90Degrees;

            Console.WriteLine("Create time of flight sensor");
            var i2cBus = Device.CreateI2cBus(I2cBusSpeed.FastPlus);

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

            Console.WriteLine("Create servo");
        }
示例#2
0
        public MeadowApp()
        {
            Initialize();

            sensor.Updated += Sensor_Updated;
            sensor.StartUpdating();
        }
        public MeadowApp()
        {
            Initialize();

            Console.WriteLine("Start sampling");
            distanceSensor.Updated += DistanceUpdated;
            distanceSensor.StartUpdating(100);
        }
        /// <summary>
        /// Create a new MarsRover object.
        /// </summary>
        public Rover()
        {
            _redLed   = Device.CreateDigitalOutputPort(Device.Pins.OnboardLedRed);
            _greenLed = Device.CreateDigitalOutputPort(Device.Pins.OnboardLedGreen);

            _driveController     = new DriveController(Device);
            _bluetoothController = new BluetoothController(Device);

            _bluetoothController.Forward.ValueSet += Forward_ValueSet;
            _bluetoothController.Reverse.ValueSet += Reverse_ValueSet;
            _bluetoothController.Left.ValueSet    += Left_ValueSet;
            _bluetoothController.Right.ValueSet   += Right_ValueSet;

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

            _distanceSensor = new Vl53l0x(Device, i2cBus);
            _distanceSensor.DistanceUpdated += _distanceSensor_Updated;
            _distanceSensor.StartUpdating(TimeSpan.FromMilliseconds(250));

            EnableDriveSystem();
        }
示例#5
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(
                new Frequency(48000, Frequency.UnitType.Kilohertz),
                SpiClockConfiguration.Mode.Mode3);
            var spiBus = Device.CreateSpiBus(
                Device.Pins.SCK,
                Device.Pins.MOSI,
                Device.Pins.MISO, 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.CurrentFont = new Font12x20();
            graphics.Rotation    = RotationType._270Degrees;

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

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

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

            onboardLed.SetColor(Color.Green);
        }
示例#6
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);
        }