private short senseResistor; // in mOhms #endregion Fields #region Constructors public Booster( bool ledToVcc, Cpu.Pin pinEnable, Cpu.Pin pinEnableLED, Cpu.AnalogChannel pinSense, Cpu.Pin pinOverloadLED, short senseResistor, int currentThreshould, Cpu.Pin pinGenerator, uint[] idleTimings ) { portEnable = new OutputPort(pinEnable, false); portEnableLED = new OutputPort(pinEnableLED, ledToVcc); this.ledToVcc = ledToVcc; portOverloadLED = new OutputPort(pinOverloadLED, ledToVcc); portSense = new AnalogInput(pinSense); portSense.Scale = 3300; this.senseResistor = senseResistor; this.currentThreshould = currentThreshould; new Timer(TimerCurrent_Tick, null, 0, checkOverloadPeriod); portGenerator = new SignalGenerator((Cpu.Pin)pinGenerator, false, MaxTimingsCount); this.idleTimings = idleTimings; //new Thread(GeneratorWork) { Priority = ThreadPriority.AboveNormal }.Start(); new Timer(TimerGenerator, null, 0, 2); }
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); } }
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() { 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 static void Main() { // write your code here OutputPort led = new OutputPort(Pins.GPIO_PIN_D0, false); InputPort button = new InputPort(Pins.GPIO_PIN_D1, false, Port.ResistorMode.PullUp); OutputPort ledLight = new OutputPort(Pins.GPIO_PIN_D2, false); InputPort buttonLight = new InputPort(Pins.GPIO_PIN_D3, false, Port.ResistorMode.PullUp); AnalogInput pot = new AnalogInput(Pins.GPIO_PIN_A0); bool buttonState = false; bool isDark = false; int potValue = 0; while (true) { buttonState = !button.Read(); isDark = buttonLight.Read() || buttonState; ledLight.Write(isDark); led.Write(buttonState); if (buttonState) { //while (buttonState) //{ // potValue = pot.Read(); // led.Write(true); // Thread.Sleep(potValue*10); // led.Write(false); // Thread.Sleep(potValue*10); // buttonState = !button.Read(); //} } } }
public KeyPad(Cpu.AnalogChannel pin) { if (pin != Cpu.AnalogChannel.ANALOG_NONE) // (select key are optional) { _keyPort = new AnalogInput(pin) {Scale = 1000}; } }
/// <summary> /// Constructor. /// </summary> /// <param name="xAccelPin"></param> /// <param name="yAccelPin"></param> /// <param name="zAccelPin"></param> /// <param name="xGyroPin"></param> /// <param name="yGyroPin"></param> public Analog5DOF(Cpu.Pin xAccelPin = Cpu.Pin.GPIO_NONE, Cpu.Pin yAccelPin = Cpu.Pin.GPIO_NONE, Cpu.Pin zAccelPin = Cpu.Pin.GPIO_NONE, Cpu.Pin xGyroPin = Cpu.Pin.GPIO_NONE, Cpu.Pin yGyroPin = Cpu.Pin.GPIO_NONE) { this.Acceleration = new Vector(0, 0, 0); this.RotationRate = new Vector(0, 0, 0); if (xAccelPin != Cpu.Pin.GPIO_NONE) { _xAccelInput = new AnalogInput(xAccelPin); } if (yAccelPin != Cpu.Pin.GPIO_NONE) { _yAccelInput = new AnalogInput(yAccelPin); } if (zAccelPin != Cpu.Pin.GPIO_NONE) { _zAccelInput = new AnalogInput(zAccelPin); } if (xGyroPin != Cpu.Pin.GPIO_NONE) { _xGyroInput = new AnalogInput(xGyroPin); } if (yGyroPin != Cpu.Pin.GPIO_NONE) { _yGyroInput = new AnalogInput(yGyroPin); } }
public PWM_AIO_Demo_Main() { //AIO pin connected to arbitrary range potentiometer. AnalogInput pot = new AnalogInput(AnalogChannels.ANALOG_PIN_A0); pot.Scale = 1; //sets range value that is returned by aio read() //Initialize I2C interface for HD44780 LCD. // Disabled while tinkering with MPU6050 //LCD_Display Display = new LCD_Display(LCD_I2C_ADDRESS, 20, 4); IMU_I2C imu = new IMU_I2C(IMU_I2C.MPU6050_DEFAULT_ADDRESS); SensorData imuData = imu.getSensorData(); bool onboardstate = false; OutputPort onboardled = new OutputPort(Pins.ONBOARD_LED, onboardstate); while (true) { Thread.Sleep(1); imuData = imu.getSensorData(); onboardstate = !onboardstate; onboardled.Write(onboardstate); Debug.Print("X Y Z X' Y' Z' " + imuData.Gyroscope_X.ToString() + " " + imuData.Gyroscope_Y.ToString() + " " + imuData.Gyroscope_Z.ToString() + " " + imuData.Acceleration_X.ToString() + " " + imuData.Acceleration_Y.ToString() + " " + imuData.Acceleration_Z.ToString()); } }
/// <summary> /// Initializes a new instance of the <see cref="ProximitySensor"/> class /// </summary> /// <param name="proximitySensorType"> /// </param> /// <param name="analogInput"> /// The analog input to which the proximity sensor is attached /// </param> /// <exception cref="ArgumentNullException"> /// Thrown when the given <see cref="AnalogInput"/> is null /// </exception> /// <remarks> /// This sensor is only provides valid results for objects farther than 3" away or objects closer than /// <see cref="MaximumReadableDistance"/> from the sensor. Passing a trigger which attempts to obtain /// distances outside of this range will result in a large number of false positives. /// </remarks> public ProximitySensor(ProximitySensorType proximitySensorType, AnalogInput analogInput) { if (analogInput == null) { throw new ArgumentNullException("analogInput"); } this.proximitySensorType = proximitySensorType; MaximumReadableDistance = GetMaximumReadableDistance(analogInput); new Thread(() => { while (true) { if (IsEnabled && ObjectDetectionTrigger != null) { var distance = new Distance(analogInput.ReadRaw(), proximitySensorType); if (ObjectDetectionTrigger(MaximumReadableDistance, distance)) { if (ObjectDetected != null) { ObjectDetected(this, new ObjectDetectedEventArgs(distance, DateTime.UtcNow)); } } } Thread.Sleep(10); } }).Start(); }
public void Dispose() { if (_analogInput != null) { _analogInput.Dispose(); _analogInput = null; } }
protected int ReadAverageDistance(AnalogInput analogInput) { var count = AverageMeasurementCount; var total = 0; while (--count >= 0) { total += analogInput.Read(); } return total / AverageMeasurementCount; }
/// <summary> /// /// </summary> /// <param name="inputPin"></param> /// <param name="tempNominal"></param> /// <param name="thermistorNominal"></param> /// <param name="beta"></param> /// <param name="baseResistance"></param> public ThermistorSensor(Cpu.Pin inputPin, float tempNominal = 25, float thermistorNominal = 10000, float beta = 3950, float baseResistance = 10000) { _Port = new AnalogInput(inputPin); _TempNominal = tempNominal; _ThermistorNominal = thermistorNominal; _Beta = beta; _BaseResistance = baseResistance; }
public SharpGP2Y0A21YK0F(Cpu.Pin[] analogPins) { var sensorId = 0; DistanceSensors = new AnalogInput[analogPins.Length]; foreach (var analogPin in analogPins) { DistanceSensors[sensorId] = new AnalogInput(analogPin); DistanceSensors[sensorId].SetRange(70, 970); sensorId++; } }
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"); } }
/// <summary> /// �R���X�g���N�^�[ /// </summary> /// <param name="channel">�T�[�~�X�^�[��ڑ�����A�i���O�`�����l��</param> /// <param name="bc">�T�[�~�X�^�[��B�萔�l</param> /// <param name="r25">�ێ�25�x�̃[�����ג�R�l</param> /// <param name="vrd">���������R�l</param> /// <param name="adc">A/D�ϊ��̕���\</param> internal Temperature(Cpu.AnalogChannel channel, double bc, double r25, double vrd, double adc) { _temperatureInput = new AnalogInput(channel); _bc = bc; _r25 = r25; _vrd = vrd; _adc = adc; _timer = new Timer(Measure_Timer, null, Timeout.Infinite, Timeout.Infinite); }
public IMUManager() { // Inicializo los puertos AccXPort = new AnalogInput(AccXPin); AccYPort = new AnalogInput(AccYPin); AccZPort = new AnalogInput(AccZPin); // Inicializo el timer loopTimer = new Timer(new System.Threading.TimerCallback(loopTimerCallback), null, 0, T); }
public static void Main() { AnalogInput pot = new AnalogInput(Cpu.AnalogChannel.ANALOG_0); while (true) { Debug.Print(pot.Read().ToString()); Thread.Sleep(200); } }
public PinProbe(AnalogInput input, double[] steinhartValues) { _input = input; _accumulator = 0; _accumulatedCount = 0; TemperatureF = -1; TemperatureR = -1; TemperatureC = -1; TemperatureFAvg = -1; _steinhart = steinhartValues; }
/// <summary> /// Program entry point /// </summary> public static void Main() { var proximitySensorInput = new AnalogInput(Cpu.AnalogChannel.ANALOG_0); var proximitySensor = new ProximitySensor(ProximitySensorType.GP2Y0A21YK, proximitySensorInput) { IsEnabled = true, ObjectDetectionTrigger = (maximumReadableDistance, distance) => distance < maximumReadableDistance, }; proximitySensor.ObjectDetected += OnObjectDetected; }
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 }
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() { // 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); } }
public LightSensor(int id, int portNumber) : base(id) { this.Setup(); if (portNumber > 0 && portNumber < 6) { this.input = new AnalogInput((Cpu.AnalogChannel)this.ports[portNumber]); } else { this.input = new AnalogInput((Cpu.AnalogChannel)this.ports[0]); } }
public LightTracker(Cpu.PWMChannel panPin, Cpu.PWMChannel tiltPin, Cpu.AnalogChannel topLeftPhotocell, Cpu.AnalogChannel topRightPhotocell, Cpu.AnalogChannel bottomLeftPhotocell, Cpu.AnalogChannel bottomRightPhotocell) { _panServo = new ContServo(panPin); _panServo.reset_ticks(); _tiltServo = new Servo(tiltPin, 150) {Degree = 150}; _lastY = _tiltServo.Degree; photoCellTL = new AnalogInput(topLeftPhotocell); photoCellTR = new AnalogInput(topRightPhotocell); photoCellBL = new AnalogInput(bottomLeftPhotocell); photoCellBR = new AnalogInput(bottomRightPhotocell); _trackAction = new WorkItem(SearchForLight, true); }
/// <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 KnockDetector(AnalogInput ai, OutputPort opKnockLed, OutputPort opCalcLed) { beatInterval = 500; knockList = new ArrayList(); knockListSize = 10; knockSensor = ai; knockLed = opKnockLed; calcLed = opCalcLed; knockThreshVolume = 75; lastKnockVolume = 0; knockRisingEdge = false; stopwatch = Stopwatch.StartNew(); stopwatch.Stop(); stopwatch.Reset(); }
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 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")); } }
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 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() { //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); }
public override void Dispose() { _port.Dispose(); _port = null; }
Int32 _maxValue = TEN_BIT_ADC_MAX_VALUE; // default instance maximum value public AnalogInput(Cpu.Pin pin) { Cpu.AnalogChannel channel = GetChannelFromPin(pin); _analogInput = new Microsoft.SPOT.Hardware.AnalogInput(channel); }
public override void Dispose() { this._port.Dispose(); this._port = null; }