public void Set(string presence) { redLed.SetDutyCycle(0); blueLed.SetDutyCycle(0); greenLed.SetDutyCycle(0); switch (presence) { case "DoNotDisturb": case "Busy": redLed.SetDutyCycle(100); return; case "TemporarilyAway": case "Away": redLed.SetDutyCycle(30); greenLed.SetDutyCycle(100); return; case "Free": greenLed.SetDutyCycle(100); return; default: return; } }
//UART static void receivedDataUsingCOMPort(object sender, SerialDataReceivedEventArgs e) { SecretLabs.NETMF.Hardware.PWM speaker = new SecretLabs.NETMF.Hardware.PWM(Pins.GPIO_PIN_D5); speaker.SetDutyCycle(50); uint duration1 = 5000, duration2 = 5000; try { if (spUART.BytesToRead > 0) { byte[] buffer = new byte[spUART.BytesToRead]; spUART.Read(buffer, 0, buffer.Length); char[] cReceived = System.Text.Encoding.UTF8.GetChars(buffer, 0, buffer.Length); string strReceived = new string(cReceived); Debug.Print("command string received " + strReceived); if (cReceived[0] == 'N') { led.Write(true); } else if (cReceived[0] == 'F') { led.Write(false); } //MOTION SENSOR - PIEZO BUZZER TURN ON else if (cReceived[0] == 'A') { Debug.Print("Alarm sounding"); for (int i = 0; i < 3; i++) { speaker.SetPulse(duration1 * 2, duration1); Thread.Sleep(300); speaker.SetPulse(duration2 * 2, duration2); Thread.Sleep(300); speaker.SetDutyCycle(0); } } //PIEZO BUZZER TURN OFF else if (cReceived[0] == 'B') { Debug.Print("Turned off alarm"); speaker.SetDutyCycle(0); } } } catch (Exception ex) { Debug.Print("exception " + ex.Message.ToString()); } }
public static void Main() { int tempInput = 0; while (true) { tempInput = tempSensor.Read(); float volts = ((float)tempInput / 1024.0f) * 3.3f; float temp_celcius = (volts * 100); float temp_fahrenheit = (temp_celcius * 9) / 5 + 32; if (temp_celcius > 24.0f) { speaker.SetPulse((uint)(1000000 / 2217.46f), (uint)(1000000 / 2217.46f) / 2); } else { speaker.SetDutyCycle(0); } Debug.Print("Celcius: " + temp_celcius.ToString() + " - " + "Fahrenheit: " + temp_fahrenheit.ToString()); Thread.Sleep(1000); } }
//===========================MOTION SENSOR========================= static void motion_OnInterrupt(uint data1, uint data2, DateTime time) { try { //port.EnableInterrupt(); port.DisableInterrupt(); DateTime startTime = DateTime.Now; // Some execution process DateTime endTime = DateTime.Now; TimeSpan totalTimeTaken = endTime.Subtract(startTime); Debug.Print("Motion detected"); speaker.SetDutyCycle(50); uint duration1 = 1000, duration2 = 800; 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("MOTION=" + "MOTION DETECTED FOR " + totalTimeTaken + "s "); //spUART.Flush(); //Thread.Sleep(5000); //uint duration1 = 1000, duration2 = 1000; //speaker.SetPulse(duration1 * 2, duration1); //speaker.SetPulse(duration2 * 2, duration2); //Thread.Sleep(250); //speaker.SetDutyCycle(0); MovementDetected = true; //OutputPort redLED = new OutputPort(Pins.GPIO_PIN_D9, false); //for (int i = 0; i < 3; i++) // { // redLED.Write(true); // Thread.Sleep(300); // redLED.Write(false); //} Thread.Sleep(5000); port.EnableInterrupt(); } catch (Exception ex) { Debug.Print(ex.Message); } }
public void SetSpeed(uint speed) { if (speed > 100) { speed = 100; } _pwm.SetDutyCycle(speed); }
public static void Main() { // SecretLabs.NETMF.Hardware.PWM led = new SecretLabs.NETMF.Hardware.PWM(Pins.GPIO_PIN_D5); AnalogInput pot = new AnalogInput(Pins.GPIO_PIN_A0); pot.SetRange(0, 100); int potValue = 0; while (true) { //read potentiometer value potValue = pot.Read(); //change LED intensity based on potentiometer value led.SetDutyCycle((uint)potValue); } }
public void SetPins(Cpu.Pin _redpin, Cpu.Pin _greenpin, Cpu.Pin _bluepin) { if (RedPWM != null) { RedPWM.Dispose(); } RedPWM = new PWM(_redpin); RedPWM.SetDutyCycle(0); if (GreenPWM != null) { GreenPWM.Dispose(); } GreenPWM = new PWM(_greenpin); GreenPWM.SetDutyCycle(0); if (BluePWM != null) { BluePWM.Dispose(); } BluePWM = new PWM(_bluepin); BluePWM.SetDutyCycle(0); }