private void ThreadTest() { this.isRunning = true; var adc1 = AdcController.FromName(SC20100.Adc.Controller1.Id); var pin = adc1.OpenChannel(SC20260.Adc.Controller1.PC0); var str = string.Empty; while (this.isRunning) { var v = pin.ReadValue() * 3.3 / 0xFFFF; var s = v.ToString("N2"); if (s.CompareTo(str) != 0) { this.UpdateStatusText("Adc reading value: " + s, true); str = s; } Thread.Sleep(500); } pin.Dispose(); this.isRunning = false; return; }
/// <summary> /// Create a new light sensor object using a static reference voltage. /// </summary> /// <param name="pin">AnalogChannel connected to the sensor.</param> public Temt6000(string AnalogControllerName, int pin) { var adc = AdcController.FromName(AnalogControllerName); sensor = adc.OpenChannel(pin); //sensor = device.CreateAnalogInputPort(pin); }
static void InitBot() { var chip = new GHIElectronics.TinyCLR.Drivers.Nxp.PCA9685.PCA9685Controller( I2cController.FromName(FEZBit.I2cBus.Edge)); var gpioController = GpioController.GetDefault(); var buzzerController = PwmController.FromName(FEZBit.PwmChannel.Controller3.Id); var buzzerChannel = buzzerController.OpenChannel(FEZBit.PwmChannel.Controller3.EdgeP0Channel); var frontsensorenable = gpioController.OpenPin(FEZBit.GpioPin.EdgeP9); var frontsensorvaluecontroller = AdcController.FromName(FEZBit.AdcChannel.Controller1.Id); var frontvalue = frontsensorvaluecontroller.OpenChannel(FEZBit.AdcChannel.Controller1.EdgeP3); var lineDetectLeft = AdcController.FromName(FEZBit.AdcChannel.Controller1.Id).OpenChannel(FEZBit.AdcChannel.Controller1.EdgeP2); var lineDetectRight = AdcController.FromName(FEZBit.AdcChannel.Controller1.Id).OpenChannel(FEZBit.AdcChannel.Controller1.EdgeP1); var p2remove = GpioController.GetDefault().OpenPin(FEZBit.GpioPin.EdgeP1); p2remove.SetDriveMode(GpioPinDriveMode.Input); bot = new BitBotController( chip, buzzerChannel, lineDetectLeft, lineDetectRight, gpioController.OpenPin(FEZBit.GpioPin.EdgeP14), gpioController.OpenPin(FEZBit.GpioPin.EdgeP15), frontsensorenable, frontvalue, gpioController.OpenPin(FEZBit.GpioPin.EdgeP16)); bot.SetHeadlight(200, 50, 0); bot.SetStatusLeds(false, true, false); bot.SetColorLeds(0, 0xff, 0, 0); bot.SetColorLeds(1, 0, 0xff, 0); bot.SetColorLeds(2, 0, 0, 0xff); bot.Beep(); }
public Gp2D12(string AnalogControllerName, int analogInputPin) { var adc = AdcController.FromName(AnalogControllerName); analogInputPort = adc.OpenChannel(analogInputPin); //analogInputPort = device.CreateAnalogInputPort(analogInputPin); Thread task1 = new Thread(new ThreadStart(ReadLoop)); task1.Start(); }
public AnalogJoystick(string AdcControllerName, int horizontalPin, int verticalPin, JoystickCalibration calibration = null, bool isInverted = false) { // this(device.CreateAnalogInputPort(horizontalPin), device.CreateAnalogInputPort(verticalPin), calibration, isInverted) var adc = AdcController.FromName(AdcControllerName); var horizonAnalog = adc.OpenChannel(horizontalPin); var verticalAnalog = adc.OpenChannel(verticalPin); SetAnalogPort(horizonAnalog, verticalAnalog, calibration, isInverted); }
public Ky038(string AnalogControllerName, int A0, int D0) { var adc = AdcController.FromName(AnalogControllerName); var analog = adc.OpenChannel(A0); var gpio = GpioController.GetDefault(); var d1 = gpio.OpenPin(D0); d1.SetDriveMode(GpioPinDriveMode.Input); Setup(analog, d1); //this (device.CreateAnalogInputPort(A0), device.CreateDigitalInputPort(D0)) }
/// <summary> /// Creates a Capacitive soil moisture sensor object with the specified analog pin and a IO device. /// </summary> /// <param name="device"></param> /// <param name="analogPin"></param> public Capacitive( string AnalogControllerName, int analogPin, float minimumVoltageCalibration = 0f, float maximumVoltageCalibration = 3.3f) { var adc = AdcController.FromName(AnalogControllerName); var analog = adc.OpenChannel(analogPin); Setup(analog, minimumVoltageCalibration, maximumVoltageCalibration); }
/// <summary> /// New instance of the AnalogTemperatureSensor class. /// </summary> /// <param name="analogPin">Analog pin the temperature sensor is connected to.</param> /// <param name="sensorType">Type of sensor attached to the analog port.</param> /// <param name="calibration">Calibration for the analog temperature sensor. Only used if sensorType is set to Custom.</param> public AnalogTemperature( string AdcControllerName, int analogPin, KnownSensorType sensorType, Calibration calibration = null ) { samplingSetting = new AnalogSamplingSetting(); // : this(device.CreateAnalogInputPort(analogPin), sensorType, calibration) var adc = AdcController.FromName(AdcControllerName); var analog = adc.OpenChannel(analogPin); SetAnalogPort(analog, sensorType, calibration); }
static void Main() { ////////// Set these to match your board ////////////// var adcChannel = SC20100.AdcChannel.Controller1.PC0; var adcController = SC20100.AdcChannel.Controller1.Id; /////////////////////////////////////////////////////// var sensor = new AlcoholClick(AdcController.FromName(adcController).OpenChannel(adcChannel)); while (true) { Debug.WriteLine(sensor.Read().ToString()); } }
static void Main() { ////////// Set these to match your board ////////////// var adcChannel = SC20100.AdcChannel.Controller1.PC0; var adcController = SC20100.AdcChannel.Controller1.Id; /////////////////////////////////////////////////////// var mic = new MicClick(AdcController.FromName(adcController).OpenChannel(adcChannel)); //TestWithSimpleDebug(mic); TestWithGraph(mic); //never get here! Thread.Sleep(Timeout.Infinite); }
/// <summary> /// Create a new ADXL335 sensor object. /// </summary> /// <param name="xPin">Analog pin connected to the X axis output from the ADXL335 sensor.</param> /// <param name="yPin">Analog pin connected to the Y axis output from the ADXL335 sensor.</param> /// <param name="zPin">Analog pin connected to the Z axis output from the ADXL335 sensor.</param> public Adxl335(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); // // Now set the default calibration data. // XVoltsPerG = 0.325f; YVoltsPerG = 0.325f; ZVoltsPerG = 0.550f; SupplyVoltage = 3.3f; }
public LcdKeypadShield() { var gpio = GpioController.GetDefault(); var d4 = new GpioPin[4] { gpio.OpenPin(SC20100.GpioPin.PA2), gpio.OpenPin(SC20100.GpioPin.PC7), gpio.OpenPin(SC20100.GpioPin.PC6), gpio.OpenPin(SC20100.GpioPin.PC4) }; var e = gpio.OpenPin(SC20100.GpioPin.PA15); var rs = gpio.OpenPin(SC20100.GpioPin.PC5); this.lcd = new DisplayHD44780(d4, e, rs); this.a0 = AdcController.FromName(SC20100.AdcChannel.Controller1.Id) .OpenChannel(SC20100.AdcChannel.Controller1.PA4); this.lcd.Clear(); }
/// <summary> /// Create a new ADXL337 sensor object. /// </summary> /// <param name="xPin">Analog pin connected to the X axis output from the ADXL335 sensor.</param> /// <param name="yPin">Analog pin connected to the Y axis output from the ADXL335 sensor.</param> /// <param name="zPin">Analog pin connected to the Z axis output from the ADXL335 sensor.</param> public Adxl377(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.00825f; YVoltsPerG = 0.00825f; ZVoltsPerG = 0.00825f; SupplyVoltage = 3.3f; }
/// <summary> /// Creates a FC28 soil moisture sensor object with the especified analog pin, digital pin and IO device. /// </summary> /// <param name="analogPort"></param> /// <param name="digitalPort"></param> public Fc28( string AnalogControllerName, int analogPin, int digitalPin, float minimumVoltageCalibration = 0f, float maximumVoltageCalibration = 3.3f) { var adc = AdcController.FromName(AnalogControllerName); var analog = adc.OpenChannel(analogPin); var gpio = GpioController.GetDefault(); var dPin = gpio.OpenPin(digitalPin); dPin.SetDriveMode(GpioPinDriveMode.Output); //this(device.CreateAnalogInputPort(analogPin), device.CreateDigitalOutputPort(digitalPin), minimumVoltageCalibration, maximumVoltageCalibration) Setup(analog, dPin, minimumVoltageCalibration, maximumVoltageCalibration); }
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); } }
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(); } }
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(); } }
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(); } }
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 AmbientClick(Hardware.Socket socket) { _ambient = AdcController.FromName(socket.AdcController).OpenChannel(socket.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); } }