public static void Main() { // mind to set a pin that exists on the board being tested // PJ5 is LD2 in STM32F769I_DISCO GpioPin led = GpioController.GetDefault().OpenPin(Boards.Netduino3.GpioPin.Led); // PD15 is LED6 in DISCOVERY4 //GpioPin led = GpioController.GetDefault().OpenPin(PinNumber('D', 15)); // PG14 is LEDLD4 in F429I_DISCO //GpioPin led = GpioController.GetDefault().OpenPin(PinNumber('G', 14)); // PE15 is LED1 in QUAIL //GpioPin led = GpioController.GetDefault().OpenPin(PinNumber('E', 15)); // PB75 is LED2 in STM32F746_NUCLEO //GpioPin led = GpioController.GetDefault().OpenPin(PinNumber('B', 7)); // 4 is a valid GPIO pin in ESP32 DevKit //GpioPin led = GpioController.GetDefault().OpenPin(Boards.Espectro32.GpioPin.BoardLed); // PA5 is LED_GREEN in STM32F091RC //GpioPin led = GpioController.GetDefault().OpenPin(PinNumber('A', 5)); // PA5 is LD2 in STM32L072Z_LRWAN1 //GpioPin led = GpioController.GetDefault().OpenPin(PinNumber('A', 5)); RotaryAngleSensor rotary = new RotaryAngleSensor(1); led.SetDriveMode(GpioPinDriveMode.Output); Button btn = new Button(Boards.Netduino3.GpioPin.D4); btn.ButtonReleased += Btn_ButtonReleased; while (true) { if (btn.IsPressed()) { Console.WriteLine("button di tekan"); } else { Console.WriteLine("button di lepas"); } var angle = rotary.GetAngle(); Console.WriteLine("angle :" + angle); led.Write(GpioPinValue.High); Thread.Sleep(125); led.Toggle(); Thread.Sleep(125); led.Toggle(); Thread.Sleep(125); led.Toggle(); Thread.Sleep(525); Console.WriteLine("Hello from nanoFramework!"); } }
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; * }*/ } }