Thursday, July 7, 2011

Netduino - dimmer update

I have done a slight update to my dimmer code as I noticed that there was a little noise at the bottom end which led to the led flickering slightly rather than being completely off. I corrected this with a simple if less than or equal to 3% then set to 0%. I also looked at inverse usage of the pots reading, this is done by taking the pot value away from 100, as the range of the pot was set to 0 - 100.

using System;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using SecretLabs.NETMF.Hardware;
using SecretLabs.NETMF.Hardware.Netduino;

namespace CIRC_08
    public class Program

        static PWM pwm2 = new PWM(Pins.GPIO_PIN_D10);
        static AnalogInput potentiometer = new AnalogInput(Pins.GPIO_PIN_A0);
        static PWM pwm = new PWM(Pins.GPIO_PIN_D5);

        public static void Main()
            int sensorValue = 0;
            potentiometer.SetRange(0, 100);

            while (true)
                sensorValue = potentiometer.Read();
                if (sensorValue <= 3)
                    sensorValue = 0;
                Debug.Print("pot value = " + sensorValue.ToString());


No comments:

Post a Comment