コード例 #1
0
        public static void Main(string[] args)
        {
            const byte AdafruitSeesawSoilSensorI2cAddress = 0x36;
            const byte AdafruitSeesawSoilSensorI2cBus     = 0x1;

            using (I2cDevice i2cDevice = I2cDevice.Create(new I2cConnectionSettings(AdafruitSeesawSoilSensorI2cBus, AdafruitSeesawSoilSensorI2cAddress)))
                using (Seesaw ssDevice = new Seesaw(i2cDevice))
                {
                    while (true)
                    {
                        Console.WriteLine($"Temperature: {ssDevice.GetTemperature()}'C");
                        Console.WriteLine($"Capacitive: {ssDevice.TouchRead(0)}");
                        ssDevice.SetGpioPinMode(1, PinMode.Output);
                        System.Threading.Tasks.Task.Delay(1000).Wait();
                    }
                }
        }
コード例 #2
0
        static void Main()
        {
            const byte AdafruitSeesawBreakoutI2cAddress = 0x49;
            const byte AdafruitSeesawBreakoutI2cBus     = 0x1;

            using (I2cDevice i2cDevice = I2cDevice.Create(new I2cConnectionSettings(AdafruitSeesawBreakoutI2cBus, AdafruitSeesawBreakoutI2cAddress)))
                using (Seesaw ssDevice = new Seesaw(i2cDevice))
                {
                    Console.WriteLine();
                    Console.WriteLine($"Seesaw Version: {ssDevice.Version}");
                    Console.WriteLine();

                    foreach (Seesaw.SeesawModule module in Enum.GetValues(typeof(Seesaw.SeesawModule)))
                    {
                        Console.WriteLine($"Module: {Enum.GetName(typeof(Seesaw.SeesawModule), module)} - {(ssDevice.HasModule(module) ? "available" : "not-available")}");
                    }

                    Console.WriteLine();
                }
        }
コード例 #3
0
ファイル: Volume.cs プロジェクト: vqbridgedev/iot
 public static Volume EnableVolume(Seesaw seesawDevice)
 {
     return(new Volume(seesawDevice));
 }
コード例 #4
0
ファイル: Volume.cs プロジェクト: vqbridgedev/iot
 public Volume(Seesaw seesawDevice)
 {
     _seesawDevice = seesawDevice;
     Init();
 }
コード例 #5
0
        static void Main()
        {
            // pins
            const int ledOne    = 9;
            const int ledTwo    = 10;
            const int ledThree  = 11;
            const int buttonOne = 14;

            const int buttonSleep = 50;
            const int volumeSleep = 50;

            // volume support
            const int initialSleep = 100;
            int       sleep        = initialSleep;
            Volume    volume       = null;

            TimeEnvelope[] envelopes = new TimeEnvelope[] { new TimeEnvelope(1000), new TimeEnvelope(1000), new TimeEnvelope(4000) };

            Console.WriteLine("Hello World!");

            Console.WriteLine($"Let's blink some LEDs!");

            using (Seesaw seesawDevice = new Seesaw(I2cDevice.Create(new I2cConnectionSettings(1, 0x49))))
                using (SeesawGpioDriver seesawGpioDevice = new SeesawGpioDriver(seesawDevice))
                    using (GpioController controller = new GpioController(PinNumberingScheme.Logical, seesawGpioDevice))
                    {
                        // this line should only be enabled if a trimpot is connected
                        volume = Volume.EnableVolume(seesawDevice);

                        controller.OpenPin(ledOne, PinMode.Output);
                        controller.OpenPin(ledTwo, PinMode.Output);
                        controller.OpenPin(ledThree, PinMode.Output);
                        controller.OpenPin(buttonOne, PinMode.InputPullDown);

                        Console.CancelKeyPress += (object sender, ConsoleCancelEventArgs eventArgs) =>
                        {
                            controller.Dispose();
                            Console.WriteLine("Pin cleanup complete!");
                        };

                        while (true)
                        {
                            // behavior for ledOne
                            if (envelopes[0].Time == 0)
                            {
                                Console.WriteLine($"Light LED one for 800ms");
                                controller.Write(ledOne, PinValue.High);
                            }
                            else if (envelopes[0].IsLastMultiple(200))
                            {
                                Console.WriteLine($"Dim LED one for 200ms");
                                controller.Write(ledOne, PinValue.Low);
                            }

                            // behavior for ledTwo
                            if (envelopes[1].IsMultiple(200))
                            {
                                Console.WriteLine($"Light LED two for 100ms");
                                controller.Write(ledTwo, PinValue.High);
                            }
                            else if (envelopes[1].IsMultiple(100))
                            {
                                Console.WriteLine($"Dim LED two for 100ms");
                                controller.Write(ledTwo, PinValue.Low);
                            }

                            // behavior for ledThree
                            if (envelopes[2].Time == 0)
                            {
                                Console.WriteLine("Light LED three for 2000 ms");
                                controller.Write(ledThree, PinValue.High);
                            }
                            else if (envelopes[2].IsFirstMultiple(2000))
                            {
                                Console.WriteLine("Dim LED three for 2000 ms");
                                controller.Write(ledThree, PinValue.Low);
                            }

                            // behavior for buttonOne
                            if (volume != null)
                            {
                                var update = true;
                                var value  = 0;
                                while (update)
                                {
                                    (update, value) = volume.GetSleepForVolume(initialSleep);
                                    if (update)
                                    {
                                        sleep = value;
                                        Thread.Sleep(volumeSleep);
                                    }
                                }
                            }

                            while (controller.Read(buttonOne) == PinValue.High)
                            {
                                Console.WriteLine("Button one pin value high!");
                                controller.Write(ledOne, PinValue.High);
                                controller.Write(ledTwo, PinValue.High);
                                controller.Write(ledThree, PinValue.High);
                                Thread.Sleep(buttonSleep);
                            }

                            Console.WriteLine($"Sleep: {sleep}");
                            Thread.Sleep(sleep);                  // starts at 100ms
                            TimeEnvelope.AddTime(envelopes, 100); // always stays at 100
                        }
                    }
        }
コード例 #6
0
ファイル: Volume.cs プロジェクト: zheng1748/iot
 public static Volume EnableVolume(Seesaw seesawDevice) =>
 new Volume(seesawDevice);