public static void Main() { SLH.AnalogInput pot = new SLH.AnalogInput(Pins.GPIO_PIN_A1); PWM redLed = new PWM(PWMChannels.PWM_PIN_D11, 100, 0, false); PWM greenLed = new PWM(PWMChannels.PWM_PIN_D10, 100, 0, false); PWM blueLed = new PWM(PWMChannels.PWM_PIN_D9, 100, 0, false); double dutyCycleMax = .3; // RGB Led doesn't seem to get much brighter than at 30% int hue = 0; // set our range to be the range of possible hues pot.SetRange(0, 360); redLed.Start(); greenLed.Start(); blueLed.Start(); while (true) { double r, g, b; hue = pot.Read(); Debug.Print("Hue: " + hue.ToString()); HsvToRgb(hue, 1, 1, out r, out g, out b); redLed.DutyCycle = (r * dutyCycleMax); greenLed.DutyCycle = (g * dutyCycleMax); blueLed.DutyCycle = (b * dutyCycleMax); } }
public static void Main() { // write your code here int anaIn = 250; // ADC is 12-bit Resolution //SecretLabs.NETMF.Hardware.AnalogInput pinA4 = new Microsoft.NETMF.Hardware.AnalogInput(Cpu.AnalogChannel.ANALOG_4); SecretLabs.NETMF.Hardware.AnalogInput pinA4 = new SecretLabs.NETMF.Hardware.AnalogInput(Pins.GPIO_PIN_A4); OutputPort led = new OutputPort(Pins.ONBOARD_LED, false); //PWM led2 = new PWM(Cpu.PWMChannel.PWM_0, 100, 100, 0); PWM servo = new PWM(Cpu.PWMChannel.PWM_0,20000,1500,PWM.ScaleFactor.Microseconds, false); servo.Start(); servo.DutyCycle = 0; servo.Duration = (uint)1500; while (true) { double anaRead = pinA4.Read(); anaIn = (int)anaRead; //LED stuff //led.Write(true); // turn on the LED //Thread.Sleep(anaIn); // sleep for 250ms //led.Write(false); // turn off the LED //Thread.Sleep(anaIn); // sleep for 250ms servo.Duration = (uint)((1000+anaRead)); } }
/// <summary> /// Frees the resources allocated for reading values from the analog joystick /// </summary> public void Dispose() { Xinput.Dispose(); Xinput = null; Yinput.Dispose(); Yinput = null; }
private static void ManageBackLight(SecretLabs.NETMF.Hardware.AnalogInput lightPort) { using (var lcd = new KanaLCD(0x38, 2, 40)) { // 暗かったらバックライトを自動で消す lcd.BackLight = lightPort.Read() < 900 || backLightCount-- > 0; } }
public static void Main() { using (var lcd = new KanaLCD(0x38, 2, 40)) { lcd.Initialize(); lcd.BackLight = true; lcd.Write("Initializing..."); } using (var clock = new RX8025NB()) { clock.Initialize(); clock.CurrentTime = GetTimeViaHttp(9); clock.Interrupt = RX8025NB.InterruptMode.Pulse1Hz; } using (var thermometer = new ADT7410(ADT7410.MeasurementMode.OneSamplePerSecond)) { thermometer.Initialize(); } var interruptPort = new InterruptPort(Pins.GPIO_PIN_D12, true, Port.ResistorMode.Disabled, Port.InterruptMode.InterruptEdgeLow); var lightPort = new SecretLabs.NETMF.Hardware.AnalogInput(Pins.GPIO_PIN_A0); // RTCモジュールによる割り込み処理 interruptPort.OnInterrupt += (_, __, ___) => { // 割り込みから秒カウンタの書き換えまで92μsかかる Thread.Sleep(1); DateTime currentTime; using (var clock = new RX8025NB()) { currentTime = clock.CurrentTime; } StartCounters(); if (anotherDisplayCount <= 0) { ShowMainDisplay(currentTime); } else { ShowAnotherDisplay(currentTime); } ManageBackLight(lightPort); }; while (true) { // メインスレッドは特になにもしない Thread.Sleep(1000); } }
/// <summary> /// Expects two analog pins connected to the x & y axis of the joystick. /// </summary> /// <param name="xAxisPin">Analog pin for the x axis</param> /// <param name="yAxisPin">Analog pin for the y axis</param> /// <param name="minRange"></param> /// <param name="maxRange"></param> /// <param name="centerDeadZoneRadius"></param> public AnalogJoystick(Cpu.Pin xAxisPin, Cpu.Pin yAxisPin, int minXRange = 0, int maxXRange = 1023, int minYRange = 0, int maxYRange = 1023, int centerDeadZoneRadius = 25) { Xinput = new SecretLabs.NETMF.Hardware.AnalogInput(xAxisPin); Xinput.SetRange(minXRange, maxXRange); Yinput = new SecretLabs.NETMF.Hardware.AnalogInput(yAxisPin); Yinput.SetRange(minYRange, maxYRange); _xRangeFlipped = (minXRange > maxXRange) ? true : false; _yRangeFlipped = (minYRange > maxYRange) ? true : false; AutoCalibrateCenter(centerDeadZoneRadius); }
/// <summary> /// Create a new base instance of the temperature sensor. /// </summary> /// <param name="pin">Pin the sensor's vout is connected to. public Thermistor(Cpu.Pin pin) { // http://www.analog.com/en/temperature-sensing-and-thermal-management/digital-temperature-sensors/tmp36/products/product.html MaximumTemperatureCapability = 125; MinimumTemperatureCapability = -40; RequiredVoltage = 2.7f; sensor = new SecretLabs.NETMF.Hardware.AnalogInput(pin); sensor.SetRange(0, 3300); }
public SharpGP2Y0A21YK0F(Cpu.Pin[] analogPins) { var sensorId = 0; DistanceSensors = new SecretLabs.NETMF.Hardware.AnalogInput[analogPins.Length]; foreach (var analogPin in analogPins) { DistanceSensors[sensorId] = new SecretLabs.NETMF.Hardware.AnalogInput(analogPin); DistanceSensors[sensorId].SetRange(70, 970); sensorId++; } }
protected int ReadAverageDistance(SecretLabs.NETMF.Hardware.AnalogInput analogInput) { var count = AverageMeasurementCount; var total = 0; while (--count >= 0) { total += analogInput.Read(); } return(total / AverageMeasurementCount); }
public static void Main() { float Voltage = 0; SecretLabs.NETMF.Hardware.AnalogInput ADC1 = new SecretLabs.NETMF.Hardware.AnalogInput(Pins.GPIO_PIN_A0); while(true) { Voltage = (float)(3.3 * ADC1.Read() / 1024); Debug.Print("voltage is "+Voltage.ToString()+"V"); Thread.Sleep(100); }// write your code here }
public Sensor(ShotModel model, Cpu.Pin analogInputPin, Cpu.Pin powerPin) { this.model = model; //isTriggered = false; currentValue = 0; //isPaused = true; //threshold = 550; //triggerType = TriggerType.Above; analogInput = new SecretLabs.NETMF.Hardware.AnalogInput(analogInputPin); power = new OutputPort(powerPin, true); // power up the sensor power.Write(false); thread = new Thread(new ThreadStart(ContinuousRead)); thread.Start(); }
/// <summary> /// Releases the pin /// </summary> public void ReleasePin() { if (this.Type == PortType.AnalogIn) { this._Adc.Dispose(); this._Adc = null; } if (this.Type == PortType.Input) { this._In.Dispose(); this._In = null; } if (this.Type == PortType.Output) { this._Out.Dispose(); this._Out = null; } if (this.Type == PortType.PWM) { this._Pwm.Dispose(); this._Pwm = null; } this.Type = PortType.None; }
public static void Main() { // write your code here int anaIn = 250; // ADC is 12-bit Resolution //SecretLabs.NETMF.Hardware.AnalogInput pinA4 = new Microsoft.NETMF.Hardware.AnalogInput(Cpu.AnalogChannel.ANALOG_4); SecretLabs.NETMF.Hardware.AnalogInput pinA4 = new SecretLabs.NETMF.Hardware.AnalogInput(Pins.GPIO_PIN_A4); OutputPort led = new OutputPort(Pins.ONBOARD_LED, false); //PWM led2 = new PWM(Cpu.PWMChannel.PWM_0, 100, 100, 0); PWM servo = new PWM(Cpu.PWMChannel.PWM_0, 20000, 1500, PWM.ScaleFactor.Microseconds, false); servo.Start(); servo.DutyCycle = 0; servo.Duration = (uint)1500; while (true) { double anaRead = pinA4.Read(); anaIn = (int)anaRead; //LED stuff //led.Write(true); // turn on the LED //Thread.Sleep(anaIn); // sleep for 250ms //led.Write(false); // turn off the LED //Thread.Sleep(anaIn); // sleep for 250ms servo.Duration = (uint)((1000 + anaRead)); } }
public static void Main() { // Toggle light when shield button is pressed. /*OutputPort led = new OutputPort(Pins.GPIO_PIN_D0, false); * InputPort button = new InputPort(Pins.GPIO_PIN_D1, false, Port.ResistorMode.PullUp); * bool buttonState = false; * * while (true) * { * buttonState = !button.Read(); * led.Write(buttonState); * }*/ // Measure voltage from potentiometer OutputPort led = new OutputPort(Pins.GPIO_PIN_D0, false); var pot = new SecretLabs.NETMF.Hardware.AnalogInput(Pins.GPIO_PIN_A0); //need to inport SecretLabs.NETMF.Hardware.AnalogInput reference. int potValue = 0; while (true) { //read the potentiometer value potValue = pot.Read(); Debug.Print(potValue.ToString()); //limit the range of the potentiometer pot.SetRange(100, 250); //blink value based on value (0-1023 ms) led.Write(true); Thread.Sleep(potValue); led.Write(false); Thread.Sleep(potValue); } }
/// <summary>Defines a Netduino ADC pin</summary> /// <param name="Pin">The Netduino pin</param> public ADC(Cpu.Pin Pin) { this._port = new SL.AnalogInput(Pin); this._port.SetRange(0, 1024); }
public void Dispose() { sensor.Dispose(); sensor = null; }
public static void Main() { //InputPort button = new InputPort(Pins.ONBOARD_SW1, false, Port.ResistorMode.Disabled); //bool ButtonState = false; //MOTION SENSOR //port.OnInterrupt += new NativeEventHandler(motion_OnInterrupt); //port.EnableInterrupt(); //UART spUART.DataReceived += new SerialDataReceivedEventHandler(receivedDataUsingCOMPort); spUART.Open(); //RFID StartRFID(); //TEMPERATURE SENSOR SecretLabs.NETMF.Hardware.AnalogInput temp = new SecretLabs.NETMF.Hardware.AnalogInput(Pins.GPIO_PIN_A0); const double EFSR = 3.3; const int N = 1023; int adcValue = 0; double Q = 0.0; double sensorVoltage = 0.0, tempC = 0.0; //ULTRASONIC SENSOR double distanceInCm = 0.0; double Kelvin; double Fahrenheit; double Newton; while (true) { //MOTION SENSOR //if (MovementDetected == true) //{ // Debug.Print("Motion detected! Alarm sounding"); // sendDataUsingCOMPort("MOTION STATUS=" + "MOTION DETECTED!"); // Thread.Sleep(5000); //} adcValue = temp.Read(); Q = EFSR / N; sensorVoltage = adcValue * Q; tempC = (100 * (sensorVoltage - 0.5)) + 20; Kelvin = tempC + 273; Fahrenheit = tempC * 18 / 10 + 32; Newton = tempC * 33 / 100; Debug.Print("Temperature: " + tempC.ToString("N2")); //ButtonState = button.Read(); //if (ButtonState == true) //{ // sendDataUsingCOMPort("PUSH BUTTON STATUS=" + "Push button pressed, activating Camera"); //} string Status; if (tempC > 30) { Status = "Hot, on air conditioner"; } else if (tempC > 28) { Status = "Warm, on fan at high speed"; } else if (tempC > 26) { Status = "Cool, set fan to low speed or turn off"; } else { Status = "Very cool, turn off additional cooling"; } Debug.Print("Temp in C is: " + tempC.ToString("N2")); Debug.Print(Status); sendDataUsingCOMPort("°C=" + tempC.ToString("N2") + "\n" + "Status = " + Status + "\n" + "°K=" + Kelvin.ToString("N2") + "\n" + "°N=" + Fahrenheit.ToString("N2") + "\n" + "°N=" + Newton.ToString("N2") + "\n" + "--------------------------------------------------------------------------------"); //sendDataUsingCOMPort("DISTANCE=" + distanceInCm.ToString("N2") + "\n" + "Status = " + UltrasonicStatus + "\n"); Thread.Sleep(5000); } }
static void ReadVoltageWithRange() { var analogInput = new SecretLabs.NETMF.Hardware.AnalogInput(Pins.GPIO_PIN_A0); analogInput.SetRange(0, 3300); while (true) { int reading = analogInput.Read(); double voltage = (double)reading / 1000; Debug.Print("Current reading = " + voltage); Thread.Sleep(1000); } }
public Capacitive(Cpu.Pin analogPort) { _analogPort = new S.AnalogInput(analogPort); }
public static void Main() { InputPort button = new InputPort(Pins.ONBOARD_SW1, false, Port.ResistorMode.Disabled); bool ButtonState = false; //UART spUART.DataReceived += new SerialDataReceivedEventHandler(receivedDataUsingCOMPort); spUART.Open(); //RFID StartRFID(); //MOTION SENSOR port.OnInterrupt += new NativeEventHandler(motion_OnInterrupt); port.EnableInterrupt(); //TEMPERATURE SENSOR SecretLabs.NETMF.Hardware.AnalogInput temp = new SecretLabs.NETMF.Hardware.AnalogInput(Pins.GPIO_PIN_A0); const double EFSR = 3.3; const int N = 1023; int adcValue = 0; int adcValueUltrasonic = 0; double Q = 0.0; double sensorVoltage = 0.0, tempC = 0.0; double distanceInCm = 0.0; double Kelvin = 0.0; double Fahrenheit = 0.0; double Newton = 0.0; string UltrasonicStatus = ""; string Status; while (true) { //MOTION SENSOR if (MovementDetected) { MovementDetected = false; } // Debug.Print("Motion detected! Alarm sounding"); // sendDataUsingCOMPort("MOTION STATUS=" + "MOTION DETECTED!"); // Thread.Sleep(5000); //} adcValueUltrasonic = sensor.Read(); adcValue = temp.Read(); Q = EFSR / N; distanceInCm = adcValue * 0.5 * 2.5; sensorVoltage = adcValueUltrasonic * Q; tempC = System.Math.Abs(100 * (sensorVoltage - 0.5)); Kelvin = System.Math.Abs(tempC + 273); Fahrenheit = System.Math.Abs(tempC * 18 / 10 + 32); Newton = System.Math.Abs(tempC * 33 / 100); Debug.Print("Distance: " + distanceInCm.ToString("N2")); Debug.Print("Temperature: " + tempC.ToString("N2")); ButtonState = button.Read(); if (ButtonState == true) { speaker.SetDutyCycle(50); uint duration1 = 3000, duration2 = 2000; Debug.Print("Alarm sounding"); for (int i = 0; i < 2; i++) { speaker.SetPulse(duration1 * 2, duration1); Thread.Sleep(200); speaker.SetPulse(duration2 * 2, duration2); Thread.Sleep(200); speaker.SetDutyCycle(0); } sendDataUsingCOMPort("DOORBELL=" + "Push button pressed, activating Camera"); } UltrasonicStatus = ""; if (distanceInCm < 30) { UltrasonicStatus = "You turned the lights and switches ON"; } if (distanceInCm > 30 && distanceInCm < 50) { UltrasonicStatus = "Move your hand a little closer to turn lights and switches ON"; } if (distanceInCm > 51) { UltrasonicStatus = "Unreachable distance, lights and switches OFF"; } if (tempC > 30) { Status = "Hot, on air conditioner"; //Status = "> } if (tempC > 28) { Status = "Warm, on fan at high speed"; } if (tempC > 26) { Status = "Cool, set fan to low speed or turn off"; } else { Status = "Very cool, turn off additional cooling"; } Debug.Print("Temp in C is: " + tempC.ToString("N2")); Debug.Print(Status); sendDataUsingCOMPort("°C=" + tempC.ToString("N2") + "\n" + "STATUS=" + Status + "\n" + "°K=" + Kelvin.ToString("N2") + "\n" + "°F=" + Fahrenheit.ToString("N2") + "\n" + "°N=" + Newton.ToString("N2") + "\n"); sendDataUsingCOMPort("DIST CM=" + distanceInCm.ToString("N2") + "\n" + "STATUS=" + UltrasonicStatus + "\n"); Thread.Sleep(5000); } }
public KeyPad(Cpu.Pin pin) { currentKey = Key.None; keyPadInput = new SecretLabs.NETMF.Hardware.AnalogInput(pin); timer = new Timer(new TimerCallback(TimerCallback), null, 100, 100); }
public HIH4000Sensor(Cpu.Pin pin) { analogInput = new SecretLabs.NETMF.Hardware.AnalogInput(pin); }
static void ReadVoltage() { var analogInput = new SecretLabs.NETMF.Hardware.AnalogInput(Pins.GPIO_PIN_A0); while (true) { // this will give us a reading of a percentage of 3.3 v (0 - 1023 since 10 bit ADC) int reading = analogInput.Read(); double voltage = (3.3 / 1023) * (double)reading; Debug.Print("Current reading = " + voltage); Thread.Sleep(1000); } }
/// <summary> /// Configures the pin as analog input /// </summary> public void ConfigureAnalogIn() { this.ReleasePin(); this._Adc = new SecretLabs.NETMF.Hardware.AnalogInput(this.Pin); this.Type = PortType.AnalogIn; }
public HumiditySensorController(MSH.Cpu.Pin analogPort, MSH.Cpu.Pin digitalPort) { _analogPort = new SLH.AnalogInput(analogPort); _digitalPort = new MSH.OutputPort(digitalPort, false); }
public FC28(Cpu.Pin analogPort, Cpu.Pin digitalPort) { _analogPort = new S.AnalogInput(analogPort); _digitalPort = new OutputPort(digitalPort, false); }
public SimpleVoltageSensor(Cpu.Pin pin) { analogInput = new SecretLabs.NETMF.Hardware.AnalogInput(pin); }
public static void Main() { //Init MyRoom = new Room(); var Beep = false; // write your code here var Led = new OutputPort(Pins.GPIO_PIN_D3, false); var lightSensor = new LightSensor(Pins.GPIO_PIN_A0); var TempSensor = new Dht11Sensor(Pins.GPIO_PIN_D0, Pins.GPIO_PIN_D1, PullUpResistor.Internal); var SoundSensor = new SecretLabs.NETMF.Hardware.AnalogInput(Pins.GPIO_PIN_A1); //SoundSensor.SetRange(0, 100); var GasSensor = new SecretLabs.NETMF.Hardware.AnalogInput(Pins.GPIO_PIN_A2); //GasSensor.SetRange(0, 100); var PirSensor = new InputPort(Pins.GPIO_PIN_D2, false, Port.ResistorMode.PullUp); var PirState = false; //waiting till connect... if (!Microsoft.SPOT.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces()[0].IsDhcpEnabled) { // using static IP while (!System.Net.NetworkInformation.NetworkInterface.GetIsNetworkAvailable()) ; // wait for network connectivity } else { // using DHCP while (IPAddress.GetDefaultLocalAddress() == IPAddress.Any) ; // wait for DHCP-allocated IP address } //Debug print our IP address Debug.Print("Device IP: " + Microsoft.SPOT.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces()[0].IPAddress); //setup mqtt client client = new MqttClient(IPAddress.Parse(MQTT_BROKER_ADDRESS)); string clientId = Guid.NewGuid().ToString(); client.Connect(clientId); SubscribeMessage(); while (true) { Beep = !Beep; MyRoom.Light = lightSensor.ReadLightSensor(); if (TempSensor.Read()) { MyRoom.Temperature = TempSensor.Temperature; MyRoom.Humidity = TempSensor.Humidity; Debug.Print("DHT sensor Read() ok, RH = " + MyRoom.Humidity.ToString("F1") + "%, Temp = " + MyRoom.Temperature.ToString("F1") + "°C " + (MyRoom.Temperature * 1.8 + 32).ToString("F1") + "°F"); } MyRoom.Sound = SoundSensor.Read(); Debug.Print("Suara : " + MyRoom.Sound); MyRoom.Gas = GasSensor.Read(); Debug.Print("Gas Lpg : " + MyRoom.Gas); var Pir = PirSensor.Read(); if (Pir) { if (PirState == false) { Debug.Print("Ada gerakan."); PirState = true; MyRoom.Movement = true; } } else { if (PirState) { Debug.Print("Gerakan berhenti."); PirState = false; MyRoom.Movement = false; } } Thread.Sleep(1000); //Buzzer.Write(Beep); Led.Write(Beep); //update status PublishMessage("/home/status", JsonSerializer.SerializeObject(MyRoom)); } }
public GUVAS12SD(MSH.Cpu.Pin analogPort, double powerVoltage = 5.0) { _analogPort = new SLH.AnalogInput(analogPort); _powerVoltage = powerVoltage; }