コード例 #1
0
        public static void Main()
        {
            try
            {
                //var light = new LightSensor(Boards.Espectro32.GpioPin.ESPECTRO32_PHOTO_TR_ANALOG_CHANNEL);
                //var lcd = new LcdRgbBacklight();
                //var rgb = new RgbLed(Boards.Espectro32.GpioPin.ESPECTRO32_RGBLED_GPIO);
                //rgb.Demo();
                buzz = new Buzzer(Boards.Espectro32.GpioPin.D14);
                Led  = new LedSocket(Boards.Espectro32.GpioPin.BoardLed);
                var btn = new Button(Boards.Espectro32.GpioPin.ESPECTRO32_BUTTON_A_PIN);
                btn.ButtonPressed  += Btn_ButtonPressed;
                btn.ButtonReleased += Btn_ButtonReleased;
                //int counter = 0;
                // User code goes here

                /*
                 *
                 * lcd.EnableDisplay(true);
                 */
                //var light = new LightSensor(Boards.Espectro32.AdcChannel.A0);
                while (true)
                {
                    //lcd.Clear();
                    //lcd.SetCursor(0, 0);
                    //lcd.Write("Hello : "+counter++);
                    //var lightVal = light.ReadLightLevel();
                    //Console.WriteLine(lightVal.ToString());
                    //Console.WriteLine("counter : "+counter++);
                    //var valRot = light.ReadLightLevel();
                    Led.TurnOn();
                    Thread.Sleep(1000);
                    Led.TurnOff();
                    Thread.Sleep(1000);
                }
            }
            catch (Exception ex)
            {
                // Do whatever please you with the exception caught
            }
        }
コード例 #2
0
        static void Main()
        {
            var distance = new DistanceSensor(Netduino3.GpioPin.D8);
            //SoundSensor sound = new SoundSensor(Netduino3.AdcChannel.A0);
            LightSensor       light  = new LightSensor(Netduino3.AdcChannel.A1);
            RotaryAngleSensor rotary = new RotaryAngleSensor(Netduino3.AdcChannel.A2);
            TemperatureSensor temp   = new TemperatureSensor(Netduino3.AdcChannel.A3);
            TouchSensor       touch  = new TouchSensor(Netduino3.GpioPin.D2);
            LedSocket         led    = new LedSocket(Netduino3.GpioPin.D3);
            Button            btn    = new Button(Netduino3.GpioPin.D5);
            Relay             rly    = new Relay(Netduino3.GpioPin.D6);
            Buzzer            buzz   = new Buzzer(Netduino3.GpioPin.D7);
            //var rgb = new LcdRgbBacklight();
            //rgb.EnableDisplay(true);
            Random rnd     = new Random();
            int    counter = 0;
            bool   Touched = false;

            while (true)
            {
                counter++;
                Thread.Sleep(100);
                //rgb.GoHome();
                //rgb.SetCursor(0, 0);
                //rgb.Clear();
                //Debug.WriteLine("sound:"+sound.ReadLevel());
                Debug.WriteLine("light:" + light.ReadLightLevel());
                Debug.WriteLine("rotary:" + rotary.GetAngle());
                Debug.WriteLine("temp:" + temp.ReadTemperature());
                Debug.WriteLine("distance:" + distance.MeasureInCentimeters() + "cm");
                if (touch.IsTouched() && !Touched)
                {
                    Touched = true;
                    //rgb.Write("turn on light");
                    led.TurnOn();
                }
                else if (!touch.IsTouched() && Touched)
                {
                    Touched = false;
                    //rgb.Write("turn off light");
                    led.TurnOff();
                }
                if (btn.IsPressed())
                {
                    rly.TurnOn();
                    buzz.TurnOn();
                }
                else
                {
                    buzz.TurnOff();
                    rly.TurnOff();
                }

                /*
                 * if (counter > 50)
                 * {
                 *  rgb.SetBacklightRGB((byte)rnd.Next(255), (byte)rnd.Next(255), (byte)rnd.Next(255));
                 *  counter = 0;
                 * }*/
            }
        }