Posts Tagged ‘Netduino Potentiometer’

things

Netduino 101 : potentiometer example

December 19, 2012  |  Hardware, Netduino  |  , ,  |  1 Comment  |  Share

Things

potentiometer example takes analog input and light up leds accounting to the input 1023 divide by 5;

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
namespace potentiometer_netduino
{
public class Program
{
public static void Main()
{
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);

OutputPort led1 = new OutputPort(Pins.GPIO_PIN_D1, false);
OutputPort led2 = new OutputPort(Pins.GPIO_PIN_D2, false);
OutputPort led3 = new OutputPort(Pins.GPIO_PIN_D3, false);
OutputPort led4 = new OutputPort(Pins.GPIO_PIN_D4, false);
OutputPort led5 = new OutputPort(Pins.GPIO_PIN_D5, false);

AnalogInput socket = new AnalogInput(Pins.GPIO_PIN_A5);

int INPUT=0;
while (true)
{
INPUT = socket.Read();
if (INPUT > 100 && INPUT <= 200) {
led1.Write(true); led2.Write(false);
led3.Write(false); led4.Write(false);
led5.Write(false);
}
else if (INPUT > 200 && INPUT <= 400) {
led1.Write(true); led2.Write(true);
led3.Write(false); led4.Write(false);
led5.Write(false);
}

else if (INPUT > 400 && INPUT <= 600) {
led1.Write(true); led2.Write(true);
led3.Write(true); led4.Write(false);
led5.Write(false);
}
else if (INPUT > 600 && INPUT <= 800) {
led1.Write(true); led2.Write(true);
led3.Write(true); led4.Write(true);
led5.Write(false);
}
else if (INPUT > 800 && INPUT <= 1000) {
led1.Write(true); led2.Write(true);
led3.Write(true); led4.Write(true);
led5.Write(true);
}
else if (INPUT < 100) {
led1.Write(false); led2.Write(false);
led3.Write(false); led4.Write(false);
led5.Write(false);
}
Debug.Print(INPUT + " ");
}
}
}
}