public static void Main() { strip = new NeoPixelStrip(50, "LaughOMeter"); analogPin = new AnalogInput(Cpu.AnalogChannel.ANALOG_3); while (true) { try { Debug.Print(analogPin.Read().ToString()); strip.SetLevel(((ushort)(analogPin.Read() * 100 / maxVal)), palette); } catch { } Thread.Sleep(500); } }
public static void Main() { const string ApiKey = "FHowwfdHmgYTCvyfYMilfzIN52OwdkGc1ZmcUPfyfKjbMElQ"; const string FeedId = "620930332"; const int SamplingPeriod = 20000; const double MaxVoltage = 3.3; const int MaxAdcValue = 1023; var voltagePort = new AnalogInput(new Cpu.AnalogChannel()); try { var lowPort = new OutputPort(Pins.GPIO_PIN_A0, false); var highPort = new OutputPort(Pins.GPIO_PIN_A2, true); } catch (Exception exception) { Debug.Print(exception.ToString()); } while (true) { WaitUntilNextPeriod(SamplingPeriod); double rawValue = voltagePort.Read(); double value = (rawValue * MaxVoltage) / MaxAdcValue; string sample = "{ \"voltage\":\"" + value.ToString("f") + "\"}"; Debug.Print("new message: " + sample); XivleyClient.Send("FHowwfdHmgYTCvyfYMilfzIN52OwdkGc1ZmcUPfyfKjbMElQ", "620930332", sample); } }
public void Run() { AnalogInput probe = new AnalogInput(Cpu.AnalogChannel.ANALOG_4); Boolean plateState = false; OutputPort HotPlate = new OutputPort(Pins.GPIO_PIN_D0, plateState); OutputPort LED = new OutputPort(Pins.ONBOARD_LED, plateState); while (true) { plateState = probe.Read() <= .95; HotPlate.Write(plateState); LED.Write(plateState); Debug.Print(probe.ReadRaw().ToString() + "\t" + probe.Read().ToString() + "\t" + plateState); System.Threading.Thread.Sleep(1000); } }
public static void Main() { // create an analog input for our photo resistor // we will use analog pin 0 on our Netduino // note: place a 10k ohm resistor between the photo resistor and ground. AnalogInput photo = new AnalogInput(SecretLabs.NETMF.Hardware.Netduino.AnalogChannels.ANALOG_PIN_A0); // create a new outpot port for our LED and write to digital port 13 OutputPort led = new OutputPort(Pins.GPIO_PIN_D13, false); while (true) { // create a new var for our photo resistor data // multiply * 100 for a value that's easier to work with double photoSense = photo.Read() * 100; // if our values are over 1, then it's dark and we... if (photoSense > 0.5) { // turn on the LED led.Write(true); } else { // otherwise, turn off the LED led.Write(false); } // sleep every 10 ms for faster light response Thread.Sleep(10); } }
public static void Main() { var currentState = GetCurrentState(); Debug.Print(currentState); AnalogInput analogInput = new AnalogInput(AnalogChannels.ANALOG_PIN_A0); var data = analogInput.Read()*10D; try { var setStateResult = SetCurrentState((int) data); Debug.Print(setStateResult); } catch(WebException wex) { //I expect this to time out - the gateway blocks the call and my netduino is going to //give up before completing. Debug.Print("Call did not return, check state manually"); } while (true) { currentState = GetCurrentState(); Debug.Print(currentState); Thread.Sleep(5000); } }
protected int ReadAverageDistance(AnalogInput analogInput) { var count = AverageMeasurementCount; var total = 0; while (--count >= 0) { total += analogInput.Read(); } return total / AverageMeasurementCount; }
public AnalogInputPin (Cpu.AnalogChannel pin, double updateFrequency = DefaultUpdateFrequency) : base (updateFrequency) { input = new AnalogInput (pin, -1); var initialValue = input.Read (); Analog = AddPort ("Analog", Units.Ratio, initialValue); }
public static void Main() { //tidy up File.Delete("\\SD\\Data.csv"); try { //retrive and set device time via NTP var networkTime = NtpClient.GetNetworkTime(); Utility.SetLocalTime(networkTime); _macAddress = GetMAC(); _blobClient = new BlobClient(AccountName, AccountKey); _tableClient = new TableClient(AccountName, AccountKey); _tableClient.CreateTable("netmfdata"); _onBoardButton = new InterruptPort(Pins.ONBOARD_SW1, true, Port.ResistorMode.Disabled, Port.InterruptMode.InterruptEdgeHigh); _onBoardButton.OnInterrupt += onBoardButton_OnInterrupt; _analogInput = new AnalogInput(AnalogChannels.ANALOG_PIN_A0); } catch(Exception ex) { Debug.Print("Error setting up Device: " + ex.ToString()); } int counter = 0; while (true) { counter++; var data = _analogInput.Read() * 40D; _tableClient.AddTableEntityForTemperature("netmfdata", _macAddress, counter.ToString(), DateTime.Now, data, "UK"); lock (Padlock) { using (FileStream fs = File.Open("\\SD\\Data.csv", FileMode.Append, FileAccess.Write)) { Debug.Print(data.ToString()); var dataBytes = Encoding.UTF8.GetBytes( StringUtility.Format("{0}, {1}, {2}\r\n", _macAddress, DateTime.Now.ToString(), data) ); fs.Write(dataBytes, 0, dataBytes.Length); fs.Flush(); } } Thread.Sleep(1000); Debug.Print("Working"); } }
public static void Main() { AnalogInput pot = new AnalogInput(Cpu.AnalogChannel.ANALOG_0); while (true) { Debug.Print(pot.Read().ToString()); Thread.Sleep(200); } }
static Int32 tsPort = 80; // Port Number for ThingSpeak #endregion Fields #region Methods public static void Main() { AnalogInput A0 = new AnalogInput(Pins.GPIO_PIN_A1); A0.SetRange(0, 9999); // Set up analogue range button.OnInterrupt += new NativeEventHandler(button_OnInterrupt); while (true) { delayLoop(updateInterval); // Check analog input on Pin A0 analogReading = A0.Read(); updateThingSpeak("field1=" + analogReading.ToString()); } }
public static void Main() { float Voltage = 0; AnalogInput ADC1 = new AnalogInput(Cpu.AnalogChannel.ANALOG_0); ADC1.Scale = 3.3; while(true) { Voltage = (float)(ADC1.Read()); Debug.Print("voltage is "+Voltage.ToString("f")+"V"); Thread.Sleep(100); }// write your code here }
public static void Main() { // write your code here PWM led = new PWM(Pins.GPIO_PIN_D5); AnalogInput pot = new AnalogInput(Pins.GPIO_PIN_A0); pot.SetRange(0, 100); int potValue = 0; while (true) { potValue = pot.Read(); led.SetDutyCycle((unit)potValue); } }
static void Main() { var voltagePort = new AnalogInput(Parameters.AnalogPin); var lowPort = new OutputPort(Parameters.LowPin, false); var highPort = new OutputPort(Parameters.HighPin, true); voltagePort.Scale = 3.3; // convert to Volt while (true) { double value = voltagePort.Read(); Debug.Print(value.ToString("f")); // fixed-point format Thread.Sleep(3000); // 3 seconds } }
/// <summary> /// Get temperature /// </summary> /// <param name="Celsius">Is degree Celcius</param> /// <param name="tempSensor">Temperature sensor signal pin.</param> /// <returns></returns> public static string GetTemperature(bool Celsius, Microsoft.SPOT.Hardware.AnalogInput tempSensor) { //Microsoft.SPOT.Hardware.AnalogInput tempSensor = new Microsoft.SPOT.Hardware.AnalogInput(SecretLabs.NETMF.Hardware.NetduinoPlus.AnalogChannels.ANALOG_PIN_A5); string temperature = string.Empty; float volts = 0; int i = 1; #if MF_FRAMEWORK_VERSION_V4_1 int vInput = tempSensor.Read(); //float volts = ((float)vInput / 1024.0f) * 3.3f; while(i<=SAMPLES) { volts += ((float)vInput / 1024.0f) * 3.3f; i++;
public static void Main() { const double maxVoltage = 3.3; const int maxAdcValue = 1023; var voltagePort = new AnalogInput(Pins.GPIO_PIN_A1); var lowPort = new OutputPort(Pins.GPIO_PIN_A0, false); var highPort = new OutputPort(Pins.GPIO_PIN_A2, true); while (true) { int rawValue = voltagePort.Read(); double value = (rawValue * maxVoltage) / maxAdcValue; Debug.Print(rawValue + " " + value.ToString("f")); } }
static void Main() { const int samplingPeriod = 6000; // 6 seconds var voltagePort = new AnalogInput(Parameters.AnalogPin); var lowPort = new OutputPort(Parameters.LowPin, false); var highPort = new OutputPort(Parameters.HighPin, true); voltagePort.Scale = 3.3; // convert to Volt Socket connection = null; while (true) // main loop { WaitUntilNextPeriod(samplingPeriod); if (connection == null) // create connection { try { connection = Connect("api.xively.com", samplingPeriod / 2); } catch { Debug.Print("connection error"); } } if (connection != null) { try { double value = voltagePort.Read(); string sample = "HelloXivelySockets," + Debug.GC(true); // string sample = "voltage," + value.ToString("f"); SendRequest(connection, Parameters.ApiKey, Parameters.FeedId, sample); } catch (SocketException) { connection.Close(); connection = null; } } } }
public static void Main() { // create an analog input for our potentiometer // we will use analog pin 0 on our Netduino AnalogInput potentiometer = new AnalogInput(SecretLabs.NETMF.Hardware.Netduino.AnalogChannels.ANALOG_PIN_A0); while (true) { // this will print the potentiometer values in your // output/console window for debugging... // you can now apply 'potentiometer.Read()' to control LEDs etc. Debug.Print("potentiometer: " + potentiometer.Read()); // sleep every 30 ms Thread.Sleep(30); } }
public static void Main() { const string apiKey = "<insert your API key here>"; const string feedId = "<insert your feed ID here>"; const int samplingPeriod = 20000; // 20 seconds var voltagePort = new AnalogInput(AnalogChannel.ANALOG_Socket6_Pin3); voltagePort.Scale = 3.3; // convert to Volt while (true) { WaitUntilNextPeriod(samplingPeriod); double value = voltagePort.Read(); string sample = "voltage," + value.ToString("f"); Debug.Print("new message: " + sample); CosmClient.Send(apiKey, feedId, sample); } }
public static void Main() { // write your code here AnalogInput pot = new AnalogInput(Cpu.AnalogChannel.ANALOG_0); PWM pwm = new PWM(PWMChannels.PWM_PIN_D5, 1000.0, 0.1, false); pot.Offset = 0; pot.Scale = 100; double potValue = 0.0; while (true) { potValue = pot.Read(); pwm.DutyCycle = potValue; pwm.Start(); Thread.Sleep(10); } }
static void Main() { const int samplingPeriod = 6000; // 6 seconds var voltagePort = new AnalogInput(Parameters.AnalogPin); var lowPort = new OutputPort(Parameters.LowPin, false); var highPort = new OutputPort(Parameters.HighPin, true); voltagePort.Scale = 3.3; // convert to Volt while (true) { WaitUntilNextPeriod(samplingPeriod); double value = voltagePort.Read(); string sample = "voltage," + value.ToString("f"); Debug.Print("new message: " + sample); XivelyClient.Send(Parameters.ApiKey, Parameters.FeedId, sample); } }
public static void Main() { var pwm0 = new PWM(Cpu.PWMChannel.PWM_0, 300, 0, false); pwm0.Start(); var pwm1 = new PWM(Cpu.PWMChannel.PWM_1, 300, 0, false); pwm1.Start(); var pwm2 = new PWM(Cpu.PWMChannel.PWM_2, 300, 0, false); pwm2.Start(); var pwm3 = new PWM(Cpu.PWMChannel.PWM_3, 300, 0, false); pwm3.Start(); using (var analogInput = new AnalogInput(Cpu.AnalogChannel.ANALOG_0)) { analogInput.Scale = 100; analogInput.Offset = 0; double prevVal = Double.MinValue; for (;;) { double currentVal = analogInput.Read(); //int raw = analogInput.ReadRaw(); //Debug.Print("Sample: " + val + " (" + raw + ")"); if (Math.Abs(currentVal - prevVal) >= 1) { pwm0.DutyCycle = pwm1.DutyCycle = pwm2.DutyCycle = pwm3.DutyCycle = ToDutyCycle(currentVal); //int volume = ToVolume(currentVal); //SendXbmcVolume(volume); prevVal = currentVal; } } } }
public static void Main() { AnalogInput pot = new AnalogInput(Cpu.AnalogChannel.ANALOG_0); OutputPort led = new OutputPort(Pins.GPIO_PIN_D0, false); pot.Offset = 0; pot.Scale = 100000; double potValue = 0.0; int sleepValue = 0; while (true) { potValue = pot.Read(); sleepValue = (int)(potValue); Debug.Print(potValue + " " + sleepValue); led.Write(true); Thread.Sleep(sleepValue); led.Write(false); Thread.Sleep(sleepValue); } }
public static void Main() { // Create servo object PWM servo = new PWM(Pins.GPIO_PIN_D9); // Create an input variable that represents the potentiometer AnalogInput pot = new AnalogInput(Pins.GPIO_PIN_A0); // Set range to fit the pulse width range for position pot.SetRange(750, 2250); while (true) { // Update position reading int position = pot.Read(); // Set position based on reading servo.SetPulse(20000, (uint)position); // Wait to get to the position Thread.Sleep(25); } }
public static void Run () { // initialize the serial port for COM1 (using D0 & D1) // initialize the serial port for COM3 (using D7 & D8) var serialPort = new SerialPort (SerialPorts.COM3, 57600, Parity.None, 8, StopBits.One); serialPort.Open (); var server = new ControlServer (serialPort); var led = new Microsoft.SPOT.Hardware.OutputPort (Pins.ONBOARD_LED, false); var lv = false; var a0 = new AnalogInput (AnalogChannels.ANALOG_PIN_A0, -1); var a1 = new AnalogInput (AnalogChannels.ANALOG_PIN_A1, -1); var uptimeVar = server.RegisterVariable ("Uptime (s)", 0); server.RegisterVariable ("Speed", 0, v => { }); server.RegisterVariable ("Turn", 0, v => { }); var a0Var = server.RegisterVariable ("Analog 0", 0); var a1Var = server.RegisterVariable ("Analog 1", 0); var magicCmd = server.RegisterCommand ("Magic", () => { Debug.Print ("MAAAGIIICC"); return 42; }); for (var i = 0; true; i++) { uptimeVar.Value = i; a0Var.Value = a0.Read (); a1Var.Value = a1.Read (); led.Write (lv); lv = !lv; Thread.Sleep (1000); } }
/// <summary> /// This program shows how to use a MaxBotix LV-MaxSonar sensor /// </summary> public static void Main() { // Default the rx pin to low to keep the sensor off OutputPort rx = new OutputPort(Pins.GPIO_PIN_D0, false); AnalogInput an = new AnalogInput(Pins.GPIO_PIN_A5); int range; // Wait at least 250 milliseconds for the sensor to power up Thread.Sleep(250); // Turn on the sensor rx.Write(true); // Wait 100 Milliseconds for the calibration cycle to complete Thread.Sleep(100); // Turn off the sensor rx.Write(false); while (true) { // Turn on the sensor rx.Write(true); // Wait 50 Milliseconds Thread.Sleep(50); // Turn off the sensor rx.Write(false); // Read the result range = an.Read(); // Print the result Debug.Print(range.ToString()); } }
//This loop polls the aio value set by the trimpot to determine the duty cycle which // determines the amplitude on the sin curve of a given itteration. private void SinLEDLoop(AnalogInput pot, PWM led, OutputPort relay, LCD_Display display ) { double startValue = 0; bool laststate = false; double potValue = 0.0; TimeSpan lastPeak = Utility.GetMachineTime(); while (true) { potValue = pot.Read(); startValue += .5 * potValue; if (startValue > 2 * System.Math.PI) { startValue = 0; laststate = !laststate; //relay.Write(laststate); if (display != null) display.writeValue("Frequency: " + getFreq(lastPeak) + " Hz"); lastPeak = Utility.GetMachineTime(); } Thread.Sleep(5); led.DutyCycle = System.Math.Max(0, System.Math.Sin(startValue)); } }
public static void Main() { AnalogInput potentiometer = new AnalogInput(Cpu.AnalogChannel.ANALOG_0); // AnalogInput potentiometer = new AnalogInput(Pins.GPIO_PIN_A0); InputPort button1 = new InputPort(Pins.GPIO_PIN_D0, false, Port.ResistorMode.Disabled); PWM redLED = new PWM(PWMChannels.PWM_PIN_D6, 100, .5, false); PWM greenLED = new PWM(PWMChannels.PWM_PIN_D5, 100, .5, false); PWM blueLED = new PWM(PWMChannels.PWM_PIN_D9, 100, .5, false); /* uint R = 0; uint G = 0; uint B = 0; */ double Rdty = .5; double Gdty = .5; double Bdty = .5; uint Frequency_hz = 400; redLED.Frequency = Frequency_hz; redLED.DutyCycle = .5; redLED.Start(); greenLED.Frequency = Frequency_hz; greenLED.DutyCycle = .5; greenLED.Start(); blueLED.Frequency = Frequency_hz; blueLED.DutyCycle = .5; blueLED.Start(); bool LEDState = false; while (true) { if (button1.Read()) { if (LEDState == true) { LEDState = false; } else { LEDState = true; } } double sensorValue = 0; sensorValue = potentiometer.Read(); double brightness = sensorValue; // string sSensorValue = sensorValue.ToString; // Debug.Print(sensorValue.ToString("F1")); if (LEDState == true) { redLED.DutyCycle = sensorValue; greenLED.DutyCycle = sensorValue; blueLED.DutyCycle = sensorValue; redLED.Frequency = Frequency_hz; greenLED.Frequency = Frequency_hz; blueLED.Frequency = Frequency_hz; } else { redLED.DutyCycle = 0; greenLED.DutyCycle = 0; blueLED.DutyCycle = 0; redLED.Frequency = 0; greenLED.Frequency = 0; blueLED.Frequency = 0; } Thread.Sleep(10); } }
public static void Main() { //Input Sensors Microsoft.SPOT.Hardware.AnalogInput WaterLevel = new Microsoft.SPOT.Hardware.AnalogInput(Cpu.AnalogChannel.ANALOG_0); Microsoft.SPOT.Hardware.AnalogInput LDR = new Microsoft.SPOT.Hardware.AnalogInput(Cpu.AnalogChannel.ANALOG_1); Microsoft.SPOT.Hardware.AnalogInput MotionDetection = new Microsoft.SPOT.Hardware.AnalogInput(Cpu.AnalogChannel.ANALOG_2); //Output Ports for Relays relay01 = new OutputPort(Pins.GPIO_PIN_D5, true); relay02 = new OutputPort(Pins.GPIO_PIN_D6, true); relay03 = new OutputPort(Pins.GPIO_PIN_D7, true); relay04 = new OutputPort(Pins.GPIO_PIN_D8, true); relay05 = new OutputPort(Pins.GPIO_PIN_D9, true); relay06 = new OutputPort(Pins.GPIO_PIN_D10, true); relay07 = new OutputPort(Pins.GPIO_PIN_D11, true); relay08 = new OutputPort(Pins.GPIO_PIN_D12, true); //DS3231 definition DS3231 rtc = new DS3231(0x68, 100, Pins.GPIO_PIN_D3); while (true) { //Getting current time from DS3231 int year = (int)rtc.CurrentDateTime.Year; int month = (int)rtc.CurrentDateTime.Month; int day = (int)rtc.CurrentDateTime.Day; int hour = (int)rtc.CurrentDateTime.Hour; int minute = (int)rtc.CurrentDateTime.Minute; int second = (int)rtc.CurrentDateTime.Second; int dayOfWeek = (int)rtc.CurrentDateTime.DayOfWeek; //If year is wrong if (year < 2000) { year += 100; } //Looking sensor values to decide relay states sensorTest(WaterLevel, LDR, MotionDetection); //Relay states are going to be decided by Time Program if (timeMode == true) { //SD Card Read Mode On if (SDCardRead(1) != "") { //Reading every relays' programs and activate them for (int i = 1; i <= 8; i++) { string[] relayAll = StringSplitter(SDCardRead(i)); TimeToAct(i, hour, minute, DayOfWeekToString(dayOfWeek), int.Parse(relayAll[1]), int.Parse(relayAll[2]), int.Parse(relayAll[3]), int.Parse(relayAll[4]), DetectDay(int.Parse(relayAll[5]))); } //Write it from VS } else { // Relay no:1 14:10 - 14:59 Only Monday TimeToAct(1, hour, minute, DayOfWeekToString(dayOfWeek), 14, 10, 14, 59, DetectDay(2)); SDCardWrite(1, 14, 10, 14, 59, 2); //It is a writing example // Relay no:2 12:10 - 16:27 Only Tuesday TimeToAct(2, hour, minute, DayOfWeekToString(dayOfWeek), 12, 10, 16, 27, DetectDay(3)); // Relay no:3 13:06 - 13:09 Only Thursday TimeToAct(3, hour, minute, DayOfWeekToString(dayOfWeek), 13, 06, 13, 18, DetectDay(7)); // Relay no:4 09:25 - 18:17 Only Friday TimeToAct(4, hour, minute, DayOfWeekToString(dayOfWeek), 09, 25, 18, 17, DetectDay(11)); // Relay no:5 10:00 - 12:00 Everyday TimeToAct(5, hour, minute, DayOfWeekToString(dayOfWeek), 10, 00, 12, 00, DetectDay(510510)); // Relay no:6 04:35 - 14:40 Weekend (Saturday & Sunday) TimeToAct(6, hour, minute, DayOfWeekToString(dayOfWeek), 04, 35, 14, 40, DetectDay(221)); // Relay no:7 12:15 - 12:46 Weekdays (Monday & Tuesday & Wednesday & Thursday & Friday) TimeToAct(7, hour, minute, DayOfWeekToString(dayOfWeek), 12, 15, 12, 46, DetectDay(2310)); // Relay no:8 02:00 - 02:02 Monday & Wednesday & Friday & Sunday TimeToAct(8, hour, minute, DayOfWeekToString(dayOfWeek), 02, 00, 02, 02, DetectDay(1870)); } } //Printing Current Time Debug.Print("Current Date: " + day + "/" + month + "/" + year); Debug.Print("Current Hour: " + hour + ":" + minute + "." + second); Debug.Print("Current Day of Week: " + DayOfWeekToString(dayOfWeek)); //Printing Sensor Values Debug.Print("Water Level Sensor: " + (int)(WaterLevel.Read() * 100)); Debug.Print("LDR Level Sensor: " + (int)(LDR.Read() * 100)); Debug.Print("Motion Detection Sensor: " + (int)(MotionDetection.Read() * 100)); Thread.Sleep(1000); } Thread.Sleep(Timeout.Infinite); }
private static void UploadData(AnalogInput input) { while (_active) { delayLoop(updateInterval); // Check analog input on Pin A0 double analogReading = input.Read(); // Update the ThingSpeak Field with the value and if the light sensor value is above 500 also update your channel status if (analogReading >= 500) { updateThingSpeak("field1=" + analogReading.ToString() + "&status=Someone is in your room!!!"); } else { updateThingSpeak("field1=" + analogReading.ToString()); } } }
/// <summary> /// Reads the current analog input value as a voltage between 0 and 3.3V. /// </summary> /// <returns>The current analog value in volts.</returns> public double ReadVoltage() { Active = true; return(ain.Read()); }
/// <summary> /// Calculate Temperature value /// </summary> /// <returns>Float value of current Temperature reading</returns> /// <remarks>Assuming AREF of 3.3v, the default for Rev. B Netduino Plus boards. /// It's an internal value, no feed to AREF required. /// Using code tutorial from adafruit http://www.ladyada.net/learn/sensors/thermistor.html </remarks> private float CalculateTemperature() { AnalogInput ain = new AnalogInput(AnalogChannels.ANALOG_PIN_A0); // take 10 readings to even out the noise float average = 0.0F; for (int i = 0; i < 10; i++) { average += (int)ain.Read(); } average /= 10; if (average == 0) return 10.0F; // convert to a resistance average = 1023 / average - 1; average = SeriesResistor / average; // apply steinhart float tempValue = average / ThermistorNominal; tempValue = Extensions.Math.Log(tempValue); tempValue /= BetaCoefficient; tempValue += 1.0F / (TemperatureNominal + 273.15F); tempValue = 1.0F / tempValue; tempValue -= 273.15F; ain.Dispose(); return tempValue; }
public override double ReadVoltage() { IsActive = true; return(_port.Read()); }
private void PollAndWriteLoop(AnalogInput pot, PWM led, OutputPort relay ) { double startValue = 0; bool laststate = false; while (true) { double potValue = 0.0; potValue = pot.Read(); startValue += .5 * potValue; if (startValue > 2 * System.Math.PI) { startValue = 0; laststate = !laststate; //relay.Write(laststate); } Thread.Sleep(5); led.DutyCycle = System.Math.Max(0, System.Math.Sin(startValue)); } }