예제 #1
0
        //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));
            }
        }
예제 #2
0
        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()

            /*
             * Spawn task to poll DHT11 temp/humid sensor.
             * This polling takes time and the quality of the hardware/driver mean the
             * polling takes inconsistent amounts of time. Also, the read operation is
             * subject to timeouts which should not be allowed to suspend other tasks.
             */
            Thread analogReadTask = new Thread(new ThreadStart(new AnalogReadClass().PollTempHumidity));

            analogReadTask.Start();

            //Spin untill task spawn completes
            while (!analogReadTask.IsAlive)
            {
                ;
            }

            //initialize PWM properties before handoff to forever loop
            double freq = 1000;
            double duty = .5;

            OutputPort onboardLed = new OutputPort(Pins.ONBOARD_LED, false);
            PWM        led        = new PWM(PWMChannels.PWM_PIN_D5, freq, duty, false);

            //Another output port to drive transistor, which drives coil of relay.
            OutputPort relay = new OutputPort(Pins.GPIO_PIN_D0, false);

            //Starts pwm channel at initialized rate/duty
            //Will be modified by pollwrite loop
            led.Start();

            LCD_Display Display = new LCD_Display(0x27, 20, 4);

            Display.writeValue("Good");

            //loop forever to get AIO value and set led pwm
            PollAndWriteLoop(pot, led, relay);
        }
예제 #3
0
 public void PollTempHumidity()
 {
     while (true)
     {
         Thread.Sleep(period);
         if (dhtSensor.Read())
         {
             Debug.Print("DHT sensor Read() ok, RH = " + dhtSensor.Humidity.ToString("F1") + "%, Temp = " + toDegrees(dhtSensor.Temperature).ToString("F1") + "°F");
             //Also write to LCD display
             if (display != null)
             {
                 display.writeValue("RH = " + dhtSensor.Humidity.ToString("F1") + "%,         Temp = " + toDegrees(dhtSensor.Temperature).ToString("F1") + "F");
             }
         }
         else
         {
             Debug.Print("DHT sensor Read() failed");
         }
     }
 }
예제 #4
0
        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()

            /*
             * Spawn task to poll DHT11 temp/humid sensor.
             * This polling takes time and the quality of the hardware/driver mean the
             * polling takes inconsistent amounts of time. Also, the read operation is
             * subject to timeouts which should not be allowed to suspend other tasks.
             */
            Thread analogReadTask = new Thread(new ThreadStart(new AnalogReadClass().PollTempHumidity));
            analogReadTask.Start();

            //Spin untill task spawn completes
            while (!analogReadTask.IsAlive) ;

            //initialize PWM properties before handoff to forever loop
            double freq = 1000;
            double duty = .5;

            OutputPort onboardLed = new OutputPort(Pins.ONBOARD_LED, false);
            PWM led = new PWM(PWMChannels.PWM_PIN_D5, freq, duty, false);

            //Another output port to drive transistor, which drives coil of relay.
            OutputPort relay = new OutputPort(Pins.GPIO_PIN_D0, false);

            //Starts pwm channel at initialized rate/duty
            //Will be modified by pollwrite loop
            led.Start();

            LCD_Display Display = new LCD_Display(0x27, 20, 4);
            Display.writeValue("Good");

            //loop forever to get AIO value and set led pwm
            PollAndWriteLoop(pot, led, relay);
        }
예제 #5
0
        //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));

            }
        }