SHOW:
|
|
- or go back to the newest paste.
1 | /* | |
2 | Reading a potentiometer on analog pin A0 | |
3 | - | and printing out the value |
3 | + | and printing out the value |
4 | - | */ |
4 | + | and controls the PWM of an LED |
5 | */ | |
6 | ||
7 | int potValue = 0; | |
8 | int potPin = A0; | |
9 | int pwmValue = 0; | |
10 | - | Serial.begin(9600); |
10 | + | int ledPin = 6; |
11 | ||
12 | void setup(){ | |
13 | Serial.begin(9600); | |
14 | - | potValue = analogRead( potPin ); |
14 | + | pinMode(ledPin, OUTPUT); |
15 | - | Serial.print("potValue = "); |
15 | + | |
16 | - | Serial.println(potValue); |
16 | + | |
17 | - | delay(100); |
17 | + | |
18 | potValue = analogRead( potPin ); | |
19 | Serial.print("potValue = "); | |
20 | Serial.println(potValue); | |
21 | ||
22 | pwmValue = map(potValue, 0, 1023, 0, 255); | |
23 | analogWrite(ledPin, pwmValue); | |
24 | delay(100); | |
25 | } |