private void RotateExample() { try { //The servoMin/servoMax values are dependant on the hardware you are using. //The values below are for my SR-4303R continuous rotating servos. //If you are working with a non-continous rotatng server, it will have an explicit //minimum and maximum range; crossing that range can cause the servo to attempt to //spin beyond its capability, possibly damaging the gears. const int servoMin = 300; // Min pulse length out of 4095 const int servoMax = 480; // Max pulse length out of 4095 using (var hat = new Adafruit.Pwm.PwmController()) { DateTime timeout = DateTime.Now.AddSeconds(10); hat.SetDesiredFrequency(60); while (timeout >= DateTime.Now) { hat.SetPulseParameters(0, servoMin, false); Task.Delay(TimeSpan.FromSeconds(1)).Wait(); hat.SetPulseParameters(0, servoMax, false); Task.Delay(TimeSpan.FromSeconds(1)).Wait(); } } } /* If the write fails display the error and stop running */ catch (Exception ex) { Text_Status.Text = "Failed to communicate with device: " + ex.Message; return; } }
private void RotateExample() { try { //The servoMin/servoMax values are dependant on the hardware you are using. //The values below are for my SR-4303R continuous rotating servos. //If you are working with a non-continous rotatng server, it will have an explicit //minimum and maximum range; crossing that range can cause the servo to attempt to //spin beyond its capability, possibly damaging the gears. const int servoMin = 300; // Min pulse length out of 4095 const int servoMax = 480; // Max pulse length out of 4095 using (var hat = new Adafruit.Pwm.PwmController()) { DateTime timeout = DateTime.Now.AddSeconds(10); hat.SetDesiredFrequency(60); while (timeout >= DateTime.Now) { hat.SetPulseParameters(0, servoMin, false); Task.Delay(TimeSpan.FromSeconds(1)).Wait(); hat.SetPulseParameters(0, servoMax, false); Task.Delay(TimeSpan.FromSeconds(1)).Wait(); } } } /* If the write fails display the error and stop running */ catch (Exception ex) { Text_Status.Text = "Failed to communicate with device: " + ex.Message; return; } }
public void ReadADC() { byte[] readBuffer = new byte[3]; /* Buffer to hold read data*/ byte[] writeBuffer = new byte[3] { 0x00, 0x00, 0x00 }; /* Setup the appropriate ADC configuration byte */ switch (ADC_DEVICE) { case AdcDevice.MCP3002: writeBuffer[0] = MCP3002_CONFIG; break; case AdcDevice.MCP3208: writeBuffer[0] = MCP3208_CONFIG; break; case AdcDevice.MCP3008: writeBuffer[0] = MCP3008_CONFIG[0]; writeBuffer[1] = MCP3008_CONFIG[1]; break; } SpiADC.TransferFullDuplex(writeBuffer, readBuffer); /* Read data from the ADC */ adcValue = convertToInt(readBuffer); /* Convert the returned bytes into an integer value */ /* UI updates must be invoked on the UI thread */ var task = this.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => { proximityStatus.Text = adcValue.ToString(); /* Display the value on screen */ if (adcValue > 500) //&& lastAdcValue > 500 { if (!servoTriggered) { proximityRect.Fill = redBrush; proximityStatus.Text = "TRIGGERED"; //turn on LEDs ledPin.Write(GpioPinValue.High); ledPin2.Write(GpioPinValue.High); using (var hat = new Adafruit.Pwm.PwmController()) { //pull servo linear actuator hat.SetPulseParameters(15, servoMin, false); Task.Delay(TimeSpan.FromSeconds(4)).Wait(); //return servo to start position hat.SetPulseParameters(15, servoMax, false); Task.Delay(TimeSpan.FromSeconds(1)).Wait(); //Trigger arduino to scroll text on sign signPin.Write(GpioPinValue.High); } servoTriggered = true; } } //lastAdcValue = adcValue; }); }