/// <summary> /// Create a new ADXL337 sensor object. /// </summary> /// <param name="xPin">Analog pin connected to the X axis output from the ADXL337 sensor.</param> /// <param name="yPin">Analog pin connected to the Y axis output from the ADXL337 sensor.</param> /// <param name="zPin">Analog pin connected to the Z axis output from the ADXL337 sensor.</param> public Adxl337(string AnalogControllerName, int xPin, int yPin, int zPin) { var adc = AdcController.FromName(AnalogControllerName); _xPort = adc.OpenChannel(xPin); _yPort = adc.OpenChannel(yPin); _zPort = adc.OpenChannel(zPin); //_xPort = device.CreateAnalogInputPort(xPin); //_yPort = device.CreateAnalogInputPort(yPin); //_zPort = device.CreateAnalogInputPort(zPin); // // Now set the default calibration data. // XVoltsPerG = 0.325f; YVoltsPerG = 0.325f; ZVoltsPerG = 0.550f; SupplyVoltage = 3.3f; }
public double GetTemperatureOnBoard() { AdcController adc1 = AdcController.GetDefault(); adcTemp = adc1.OpenChannel(Pinout.AdcChannel.ADC1_IN13_TEMP); double tempInCent = 0; try { var maximumValue = 4095; var analogReference = 3300; double adcTempCalcValue = (analogReference * adcTemp.ReadValue()) / maximumValue; tempInCent = ((13.582f - Math.Sqrt(184.470724f + (0.01732f * (2230.8f - adcTempCalcValue)))) / (-0.00866f)) + 30; // double tempInF = ((9f / 5f) * tempInCent) + 32f; } catch { } return(tempInCent); }
public float GetMcuTemperature() { AdcController adc1 = AdcController.GetDefault(); adcTemp = adc1.OpenChannel(Pinout.AdcChannel.ADC_CHANNEL_SENSOR); return(adcTemp.ReadValue() / 100.00f); //https://www.st.com/resource/en/datasheet/stm32f769ni.pdf //https://electronics.stackexchange.com/questions/324321/reading-internal-temperature-sensor-stm32 //const int ADC_TEMP_3V3_30C = 0x1FF0F44C //0x1FFF7A2C; //const int ADC_TEMP_3V3_110C = 0x1FF0 F44E //0x1FFF7A2E; //const float CALIBRATION_REFERENCE_VOLTAGE = 3.3F; //const float REFERENCE_VOLTAGE = 3.0F; // supplied with Vref+ or VDDA // scale constants to current reference voltage //float adcCalTemp30C = getRegisterValue(ADC_TEMP_3V3_30C) * (REFERENCE_VOLTAGE / CALIBRATION_REFERENCE_VOLTAGE); //float adcCalTemp110C = getRegisterValue(ADC_TEMP_3V3_110C) * (REFERENCE_VOLTAGE / CALIBRATION_REFERENCE_VOLTAGE); // return (adcTemp.ReadValue() - adcCalTemp30C)/(adcCalTemp110C - adcCalTemp30C) *(110.0F - 30.0F) + 30.0F); }
static public void Run() { var ain = AdcController.FromName(SC20100.AdcChannel.Controller1.Id). OpenChannel(SC20100.AdcChannel.Controller1.PA4); var strobe = GpioController.GetDefault().OpenPin(SC20100.GpioPin.PA2); var reset = GpioController.GetDefault().OpenPin(SC20100.GpioPin.PC7); var msgeq7 = new Msgeq7(ain, strobe, reset); var spiController = SpiController.FromName(SC20100.SpiBus.Spi3); mLedStrip = new LPD8806(spiController, TOTAL_LEDS); while (true) { msgeq7.UpdateBands(); DrawEqualizer(msgeq7.Data); Thread.Sleep(10); } }
public DfRobotLcdShield(byte columns = 16, byte rows = 2) : base(new GpioLcdTransferProvider( FEZ.GpioPin.D8, FEZ.GpioPin.D9, FEZ.GpioPin.D4, FEZ.GpioPin.D5, FEZ.GpioPin.D6, FEZ.GpioPin.D7 )) { var adcController = AdcController.GetDefault(); analog = adcController.OpenChannel(FEZ.AdcChannel.A0); Begin(columns, rows); Clear(); var buttonReader = new Thread(ReadButtons); buttonReader.Start(); }
public static void Main() { Debug.WriteLine("devMobile.Longboard.ServoTest starting"); try { AdcController adc = AdcController.GetDefault(); AdcChannel adcChannel = adc.OpenChannel(0); #if POSITIONAL ServoMotor servo = new ServoMotor("TIM5", ServoMotor.ServoType.Positional, PinNumber('A', 0)); servo.ConfigurePulseParameters(0.1, 2.3); #endif #if CONTINUOUS ServoMotor servo = new ServoMotor("TIM5", ServoMotor.ServoType.Continuous, PinNumber('A', 0)); servo.ConfigurePulseParameters(0.1, 2.3); #endif while (true) { double value = adcChannel.ReadRatio(); #if POSITIONAL double position = Map(value, 0.0, 1.0, 0.0, 180); #endif #if CONTINUOUS double position = Map(value, 0.0, 1.0, -100.0, 100.0); #endif Debug.WriteLine($"Value: {value:F2} Position: {position:F1}"); servo.Set(position); Thread.Sleep(100); } } catch (Exception ex) { Debug.WriteLine(ex.Message); } }
//private AdcChannel adc420mA; /// <summary> /// Returns the value of the 12V battery voltage coming in the system /// </summary> /// <returns></returns> public double GetBatteryUnregulatedVoltage() { float voltage = 0; if (adcVBAT == null) { AdcController adc1 = AdcController.GetDefault(); adcVBAT = adc1.OpenChannel(Pinout.AdcChannel.ADC1_IN8_VBAT); } var average = 0; for (byte i = 0; i < 5; i++) { average += adcVBAT.ReadValue(); Thread.Sleep(50);//pause to stabilize } try { average /= 5; //maximumValue = 4095; //analogReference = 3300; //VBat = 0.25 x VIN adc count //float voltage = ((3300 * average) / 4096)* 4; voltage = ((3300 * average) / 4096) * 0.004f; voltage += 0.25f;//small offset calibration factor for board to even drop on measure } catch { } return(voltage); }
static void TestTinyBit() { var buzzerController = PwmController.FromName(FEZBit.PwmChannel.Controller3.Id); var buzzerChannel = buzzerController.OpenChannel(FEZBit.PwmChannel.Controller3.EdgeP0Channel); var lineDetectLeft = GpioController.GetDefault().OpenPin(FEZBit.GpioPin.EdgeP13); var lineDetectRight = GpioController.GetDefault().OpenPin(FEZBit.GpioPin.EdgeP14); var voiceSensor = AdcController.FromName(FEZBit.AdcChannel.Controller1.Id).OpenChannel(FEZBit.AdcChannel.Controller1.EdgeP1); var p2remove = GpioController.GetDefault().OpenPin(FEZBit.GpioPin.EdgeP1); var distanceTrigger = GpioController.GetDefault().OpenPin(FEZBit.GpioPin.EdgeP16); var distanceEcho = GpioController.GetDefault().OpenPin(FEZBit.GpioPin.EdgeP15); p2remove.SetDriveMode(GpioPinDriveMode.Input); var bot = new TinyBitController( I2cController.FromName(FEZBit.I2cBus.Edge), buzzerChannel, voiceSensor, lineDetectLeft, lineDetectRight, distanceTrigger, distanceEcho, FEZBit.GpioPin.EdgeP12 ); bot.SetHeadlight(30, 100, 100); bot.SetColorLeds(1, 200, 0, 0); bot.SetMotorSpeed(0.5, 0.5); bot.SetMotorSpeed(0.5, -0.5); bot.SetMotorSpeed(-0.5, 0.5); bot.SetMotorSpeed(0, 0); while (true) { var l = bot.ReadLineSensor(true); var r = bot.ReadLineSensor(false); var v = bot.ReadVoiceLevel(); Thread.Sleep(50); bot.Beep(); } }
public static void Main() { string devs = AdcController.GetDeviceSelector(); Console.WriteLine("devs=" + devs); AdcController adc1 = AdcController.GetDefault(); int max1 = adc1.MaxValue; int min1 = adc1.MinValue; Console.WriteLine("min1=" + min1.ToString() + " max1=" + max1.ToString()); AdcChannel ac0 = adc1.OpenChannel(0); // the following indexes are valid for STM32F769I-DISCO board AdcChannel vref = adc1.OpenChannel(0); AdcChannel vbat = adc1.OpenChannel(8); // VP //AdcChannel ac3 = adc1.OpenChannel(3); // VN while (true) { int value = ac0.ReadValue(); int valueVref = vref.ReadValue(); int valueVbat = vbat.ReadValue(); double percent = ac0.ReadRatio(); Console.WriteLine("value0=" + value.ToString() + " ratio=" + percent.ToString()); Console.WriteLine("verf" + valueVref.ToString() + " ratio=" + percent.ToString()); Console.WriteLine("vbat" + valueVbat.ToString() + " ratio=" + percent.ToString()); Thread.Sleep(1000); } }
public static void Main() { Debug.WriteLine("devMobile.Longboard.AdcTest starting"); Debug.WriteLine(AdcController.GetDeviceSelector()); try { AdcController adc = AdcController.GetDefault(); AdcChannel adcChannel = adc.OpenChannel(0); while (true) { double value = adcChannel.ReadRatio(); Debug.WriteLine($"Value: {value:F2}"); Thread.Sleep(100); } } catch (Exception ex) { Debug.WriteLine(ex.Message); } }
static void Main() { var adcController = AdcController.FromName(SC20100.AdcChannel.Controller1.Id); var adcChannel = adcController.OpenChannel(SC20100.AdcChannel.Controller1.PA0); var strobePin = GpioController.GetDefault().OpenPin(SC20100.GpioPin.PE1); var resetPin = GpioController.GetDefault().OpenPin(SC20100.GpioPin.PE0); var msgeq7 = new Msgeq7(adcChannel, strobePin, resetPin); InitializeSPIDisplay(); while (true) { msgeq7.UpdateBands(); DrawEqualizer(msgeq7.Data); GC.Collect(); GC.WaitForPendingFinalizers(); } }
public DfrobotSoilMoistureSensor(short adcChannel) { var adc1 = AdcController.GetDefault(); _adcChannel = adc1.OpenChannel(adcChannel); }
public RotaryAngleSensor(int AdcPinNumber) { Channel = AdcController.GetDefault().OpenChannel(AdcPinNumber); }
/// <summary> /// Ctor of module /// </summary> /// <param name="adcSocket">pin of adc channel (usually pin3 on A socket)</param> public LightSense(int adcSocket) { _adc = AdcController.GetDefault().OpenChannel(adcSocket); }
public RotaryAngleSensor(int ChannelNumber) { var AdcCtl = AdcController.GetDefault(); Channel = AdcCtl.OpenChannel(ChannelNumber); }
/// <summary> /// Initializes the Remote Arduino Provider and stores the handles to the 4 controllers. Only runs once. /// </summary> private static async Task InitAsync() { await semaphoreSlim.WaitAsync(); try { if (!initialized) { // Change this to true for Bluetooth and false for USB bool UseBluetooth = false; bool configurationFound = false; DeviceInformation connectedDeviceInformation = null; if (UseBluetooth) { // This assumes that there is only one BT SPP device on the computer. If there are multiple devices // the you will need to identify the device from the list returned from FindAllAsync() and use // that one as the device to pass to the arduino provider string spp_aqs = RfcommDeviceService.GetDeviceSelector(RfcommServiceId.SerialPort); DeviceInformationCollection deviceList = await DeviceInformation.FindAllAsync(spp_aqs); if (deviceList.Count > 0) { DeviceInformation device = deviceList[0]; // Remember to ensure that the Firmata Sketch has the baud rate set to the same default as the BT device ArduinoProviders.ArduinoProvider.Configuration = new ArduinoProviders.ArduinoConnectionConfiguration(device, 57600); configurationFound = true; } else { Debug.WriteLine("No bluetooth connected Arduino found"); } } else { Selector selector = new Selector(); IEnumerable <ArduinoDeviceListEntry> list = await selector.GetDeviceList(); if (list.Count() > 0) { var listArray = list.ToArray(); connectedDeviceInformation = listArray[0].DeviceInformation; ArduinoProviders.ArduinoProvider.Configuration = new ArduinoProviders.ArduinoConnectionConfiguration(connectedDeviceInformation, 57600); configurationFound = true; } else { Debug.WriteLine("No USB Connected Ardino found"); } } // we can't use a null check on Configuration as it will auto allocate and be in an invalid state if (configurationFound) { // Check our firmata and make sure we are good, if not we will flash the device with our required MakeCode specific firmata int retry = 2; bool FirmwareUploadRequired = false; while (retry-- > 0) { FirmwareUploadRequired = false; try { if (firmataProvider == null) { firmataProvider = new ArduinoProviders.ArduinoFirmataProvider(); } bool firmataInitOk = false; try { firmataInitOk = await firmataProvider.InitializeAsync(); } catch (Exception e) { Debug.WriteLine(e.Message); } if (firmataInitOk == true) { // there is a firmata version on the device now. Check if it is what we need. int MajorVersion = firmataProvider.FirmataInstance.getFirmwareVersionMajor(); int MinorVersion = firmataProvider.FirmataInstance.getFirmwareVersionMinor(); String FirmwareName = firmataProvider.FirmataInstance.getFirmwareName(); Debug.WriteLine($"Arduino with Firmata found Version {MajorVersion}.{MinorVersion} {FirmwareName}"); if (String.Compare(FirmwareName, "MakeCodeFirmata.ino", StringComparison.OrdinalIgnoreCase) != 0) { // Not the makecode firmware so need to upload it FirmwareUploadRequired = true; } else { // Makecode firmware, but is it the required version? // TODO: Version check } } else { // No firmata on the device FirmwareUploadRequired = true; } } catch (Exception ex) { Debug.WriteLine("Failed to get Firmata Instance: " + ex.Message); FirmwareUploadRequired = true; } if (FirmwareUploadRequired) { Debug.WriteLine("Firmata update required"); // Need to close our current connection if any if (firmataProvider != null) { firmataProvider.Dispose(); firmataProvider = null; ArduinoProvider.Close(); } Arduino arduino = Arduino.GetArduino(connectedDeviceInformation.Id); await arduino.Connect(); var programmer = arduino.GetProgrammer(); await programmer.Program("ms-appx:///BlockCode/MakeCodeFirmata/MakeCodeFirmata.ino.standard.hex", 28672); // Now let the arduino go so we can reopen it in non progamming mode. arduino.Dispose(); // And we will let it cycle again to verify Debug.WriteLine("Arduino Firmata updated "); return; } else { // Have a good firmware so store it and setup our callback uwpFirmata = firmataProvider.FirmataInstance; uwpFirmata.SysexMessageReceived += UwpFirmata_SysexMessageReceived; retry = 0; } } if (uwpFirmata == null) { // not going to be able to go on. Debug.WriteLine("Arduino Firmata Initalization failed"); return; } // Now that we have a good firmata we can do the other connections Windows.Devices.LowLevelDevicesController.DefaultProvider = new ArduinoProviders.ArduinoProvider(); gpioController = await GpioController.GetDefaultAsync(); pwmController = await PwmController.GetDefaultAsync(); adcController = await AdcController.GetDefaultAsync(); i2cController = await I2cController.GetDefaultAsync(); if ( (gpioController != null) && (pwmController != null) && (adcController != null) && (i2cController != null) && (uwpFirmata != null) ) { // We got good initialzation initialized = true; } } else { // Something went wrong with init Debug.WriteLine("Arduino Initalization failed"); } } else { // Duplicate initalization, we can just ignore this } } catch (Exception e) { Debug.WriteLine("Arduino Initalization failed: " + e.Message); } finally { // When the task is ready, release the semaphore. It is vital to ALWAYS release the semaphore when we are ready, // or else we will end up with a Semaphore that is forever locked. // This is why it is important to do the Release within a try...finally clause; // program execution may crash or take a different path, this way you are guaranteed execution semaphoreSlim.Release(); } }
public SparkFunWindVaneDriver(ushort adcChannel) { var adc = AdcController.GetDefault(); _adcChannel = adc.OpenChannel(adcChannel); }
static void Main() { rainAmount = 0; windSpeedCount = 0; //Rain gauge is connected to P2 (PA5 on FEZ Bit Rev A, PA0 on Rev B). var rainGauge = GpioController.GetDefault().OpenPin(SC20100.GpioPin.PA5); rainGauge.SetDriveMode(GpioPinDriveMode.InputPullUp); rainGauge.ValueChanged += RainGauge_ValueChanged; //Wind direction is connected to P1 (PA3). var windDirectionPin = SC20100.AdcChannel.Controller1.PA3; var windAdcController = AdcController.FromName(SC20100.AdcChannel.Controller1.Id); var windDirectionAdc = windAdcController.OpenChannel(windDirectionPin); var windDirectionDivisions = new double[] { 0.3715, 0.3845, 0.404, 0.444, 0.4935, 0.535, 0.5955, 0.658, 0.72, 0.7725, 0.802, 0.845, 0.8785, 0.904, 0.9325 }; var windDirectionText = new string[] { "ESE", "ENE", "E", "SSE", "SE", "SSW", "S", "NNE", "NE", "WSW", "SW", "NNW", "N", "WNW", "NW", "W" }; var windDirectionAdcCount = windDirectionAdc.ReadRatio(); var windDirectionIndex = 0; for (int i = 0; i < 15; i++) { if (windDirectionAdcCount > windDirectionDivisions[i]) { windDirectionIndex++; } } Debug.WriteLine("Wind is out of the: " + windDirectionText[windDirectionIndex]); //Wind speed sensor is connected to P8 (PE8). var windSpeed = GpioController.GetDefault().OpenPin(SC20100.GpioPin.PE8); var windSpeedMeasurementTime = 4; //In seconds. windSpeed.SetDriveMode(GpioPinDriveMode.InputPullUp); windSpeed.ValueChanged += WindSpeed_ValueChanged; windSpeedCount = 0; Thread.Sleep(windSpeedMeasurementTime * 1000); Debug.WriteLine("Wind speed: " + (windSpeedCount * 1.492 / 4 / windSpeedMeasurementTime).ToString("D1") + " MPH"); //Humidity/temp sensor is BME280. SDA connected to P20, SCL connected to P19. //I2C1 on FEZ Bit. //I2C address 0x76. //hum_lsb = 0xFE. //hum_msb = 0xFD. //temp_lsb = 0xFB. //temp_msb = 0xFA. //press_lsb = 0xF8. //press_msb = 0xF7. var settings = new I2cConnectionSettings(0x76, 400_000); //The slave's address and the bus speed. var controller = I2cController.FromName(SC20100.I2cBus.I2c1); var device = controller.GetDevice(settings); byte[] writeBuffer = new byte[] { 0xF2, 0x01 }; //must set osrs_h[2:0] to 001. Set humidity to 1x oversampling. byte[] readBuffer = new byte[1]; device.WriteRead(writeBuffer, readBuffer); writeBuffer[0] = 0xF4; //write 0x27 to 0xF4 (set mode to normal, oversampling for temperature and pressure set to 1X). writeBuffer[1] = 0x27; device.WriteRead(writeBuffer, readBuffer); byte[] writeBuffer2 = new byte[] { 0xF7 }; byte[] readBuffer2 = new byte[8]; device.WriteRead(writeBuffer2, readBuffer2); //Pressure, temperature and humidity are in readBuffer2 array, but must be corrected and calculated using trimming factors. var led = GpioController.GetDefault().OpenPin(SC20100.GpioPin.PB0); led.SetDriveMode(GpioPinDriveMode.Output); while (true) { led.Write(GpioPinValue.High); Thread.Sleep(100); led.Write(GpioPinValue.Low); Thread.Sleep(100); } }
private async Task Init() { controller = (await AdcController.GetControllersAsync(AdcMcp3008Provider.GetAdcProvider()))[0]; controller.ChannelMode = mode; }
public AmbientClick(Hardware.Socket socket) { _ambient = AdcController.FromName(socket.AdcController).OpenChannel(socket.AdcChannel); }
static void TestTpBot() { var buzzerController = PwmController.FromName(FEZBit.PwmChannel.Controller3.Id); var buzzerChannel = buzzerController.OpenChannel(FEZBit.PwmChannel.Controller3.EdgeP0Channel); var lineDetectLeft = GpioController.GetDefault().OpenPin(FEZBit.GpioPin.EdgeP13); var lineDetectRight = GpioController.GetDefault().OpenPin(FEZBit.GpioPin.EdgeP14); var voiceSensor = AdcController.FromName(FEZBit.Adc.Controller1.Id).OpenChannel(FEZBit.Adc.Controller1.EdgeP1); var p2remove = GpioController.GetDefault().OpenPin(FEZBit.GpioPin.EdgeP1); var distanceTrigger = GpioController.GetDefault().OpenPin(FEZBit.GpioPin.EdgeP16); var distanceEcho = GpioController.GetDefault().OpenPin(FEZBit.GpioPin.EdgeP15); p2remove.SetDriveMode(GpioPinDriveMode.Input); var bot = new TpBotController( I2cController.FromName(FEZBit.I2cBus.Edge), buzzerChannel, lineDetectLeft, lineDetectRight);//, distanceTrigger, distanceEcho); new Thread(() => { while (true) { bot.SetHeadlight(100, 0, 0); Thread.Sleep(200); bot.SetHeadlight(0, 0, 100); Thread.Sleep(300); } }).Start(); /*new Thread(() => { * while (true) { * bot.Beep(); * Thread.Sleep(2_000); * } * }).Start(); */ while (true) { bot.SetMotorSpeed(0.9, 0.9); var l = bot.ReadLineSensor(true); var r = bot.ReadLineSensor(false); //var v = bot.ReadVoiceLevel(); /*var d = bot.ReadDistance(); * if (d < 20) { * bot.SetMotorSpeed(-0.9, -0.9); * Thread.Sleep(200); * bot.SetMotorSpeed(-0.9, 0.9); * Thread.Sleep(200); * bot.SetMotorSpeed(0, 0); * Thread.Sleep(1000); * * * bot.Beep(); * Thread.Sleep(100); * bot.Beep(); * Thread.Sleep(100); * bot.Beep(); * Thread.Sleep(100); * }*/ Thread.Sleep(10); } }
public LightSensor(int AdcPinNumber) { Channel = AdcController.GetDefault().OpenChannel(AdcPinNumber); }
/// <summary> /// Constructor of Grove SoundSensor module /// </summary> /// <param name="adcPinNumber">Adc pin of board</param> public SoundSensor(int adcPinNumber) { _channel = AdcController.GetDefault().OpenChannel(adcPinNumber); }
/// <summary> /// Creates an instance. /// </summary> /// <param name="pin">The ADC input pin to be read by this object.</param> public AnalogAdcInput(AnalogInputPin pin) { _channel = AdcController.GetDefault().OpenChannel((int)pin); }
/// <summary> /// Gets the <see cref="AdcController"/> instances for each controller provider. /// </summary> /// <returns> /// An <see cref="IAsyncOperation{TResult}"/> that yields the list of controllers. /// </returns> public IAsyncOperation <IReadOnlyList <AdcController> > GetControllersAsync() { return(AdcController.GetControllersAsync(this)); }
/// <summary> /// Constructor of Grove TemperatureSensor module /// </summary> /// <param name="adcPinNumber">Adc pin of board</param> public TemperatureSensor(int adcPinNumber) { _channel = AdcController.GetDefault().OpenChannel(adcPinNumber); }
static void TestTinyBit() { var buzzerController = PwmController.FromName(FEZBit.Timer.Pwm.Controller3.Id); var buzzerChannel = buzzerController.OpenChannel(FEZBit.Timer.Pwm.Controller3.P0); var lineDetectLeft = GpioController.GetDefault().OpenPin(FEZBit.GpioPin.P13); var lineDetectRight = GpioController.GetDefault().OpenPin(FEZBit.GpioPin.P14); var voiceSensor = AdcController.FromName(FEZBit.Adc.Controller1.Id).OpenChannel(FEZBit.Adc.Controller1.P1); var p2remove = GpioController.GetDefault().OpenPin(FEZBit.GpioPin.P1); var distanceTrigger = GpioController.GetDefault().OpenPin(FEZBit.GpioPin.P16); var distanceEcho = GpioController.GetDefault().OpenPin(FEZBit.GpioPin.P15); p2remove.SetDriveMode(GpioPinDriveMode.Input); var bot = new TinyBitController( I2cController.FromName(FEZBit.I2cBus.Edge), buzzerChannel, voiceSensor, lineDetectLeft, lineDetectRight, distanceTrigger, distanceEcho, FEZBit.GpioPin.P12 ); new Thread(() => { while (true) { bot.SetHeadlight(100, 0, 0); Thread.Sleep(200); bot.SetHeadlight(0, 0, 100); Thread.Sleep(300); } }).Start(); /*new Thread(() => { * while (true) { * bot.Beep(); * Thread.Sleep(2_000); * } * }).Start(); */ while (true) { bot.SetMotorSpeed(0.5, 0.5); var l = bot.ReadLineSensor(true); var r = bot.ReadLineSensor(false); var v = bot.ReadVoiceLevel(); var d = bot.ReadDistance(); if (d < 20) { bot.SetMotorSpeed(-0.5, -0.5); Thread.Sleep(200); bot.SetMotorSpeed(-0.5, 0.5); Thread.Sleep(200); bot.SetMotorSpeed(0, 0); Thread.Sleep(1000); bot.Beep(); Thread.Sleep(100); bot.Beep(); Thread.Sleep(100); bot.Beep(); Thread.Sleep(100); } Thread.Sleep(10); } bot.SetHeadlight(30, 100, 100); bot.SetColorLeds(1, 200, 0, 0); bot.SetMotorSpeed(0.5, 0.5); bot.SetMotorSpeed(0.5, -0.5); bot.SetMotorSpeed(-0.5, 0.5); bot.SetMotorSpeed(0, 0); while (true) { var l = bot.ReadLineSensor(true); var r = bot.ReadLineSensor(false); var v = bot.ReadVoiceLevel(); Thread.Sleep(50); bot.Beep(); } }
//private readonly SpiDevice _myDevice; private Mcp3208SpiDevice() { _controller = AdcController.GetControllersAsync(new MCP3208()).AsTask().Result.First(); _tSource = new CancellationTokenSource(); ReadVals(_tSource.Token); }
/// <summary>Constructs a new instance.</summary> /// <param name="channelNumber">pin 3 of A socket</param> public Potentiometer(int channelNumber) { _input = AdcController.GetDefault().OpenChannel(channelNumber); }