Hello, I just got my Netduino plus 2 and the Getting started with Netduino book. I am a beginner and have been reading the forums a bit and have seen that old code from the Netduino plus sometimes won't work on the plus 2. I am in need of some help updating the potentiometer example used in the book which can be seen below:
public static void Main() { // write your code here OutputPort led = new OutputPort(Pins.ONBOARD_LED, false); AnalogInput pot = new AnalogInput(Pins.GPIO_PIN_A0); pot.SetRange(100, 250); int potValue = 0; while (true) { //read the value of the pot potValue = pot.Read(); //blink the led based on the pot's value led.Write(true); Thread.Sleep(potValue); led.Write(false); Thread.Sleep(potValue); } }
The problems I am having are with AnalogInput which I fixed below, the [font="'courier new', courier, monospace;"]SetRange()[/font] command, and the pots value is different from the 0 to 1023 range used in the book. I did some debugging and with [font="'courier new', courier, monospace;"]pot.Read()[/font] it gives me values from 0 to 1, and with [font="'courier new', courier, monospace;"]pot.ReadRaw()[/font] it gives me a range of 0 to 4095. I fixed the AnalogInput from looking at other posts on the forum, and fixed reading the pots value with [font="'courier new', courier, monospace;"]pot.ReadRaw()[/font] but can't find an equivalent command for [font="'courier new', courier, monospace;"]SetRange. [font="arial, helvetica, sans-serif;"] Here is my code:[/font][/font]
public static void Main() { // write your code here OutputPort led = new OutputPort(Pins.ONBOARD_LED, false); AnalogInput pot = new AnalogInput(AnalogChannels.ANALOG_PIN_A0); int potValue = 0; while (true) { potValue = pot.ReadRaw(); //read the value of the potentiometer //blink the led based on the potentiometer's value led.Write(true); Thread.Sleep(potValue); led.Write(false); Thread.Sleep(potValue); } }
I got the led to blink based on the pot and now just need to set the range between 100ms delay and 250ms delay. Any help would be great.
Thanks!