Skip to content

Commit 0e44e69

Browse files
committed
Add simple sketch for PWMing a LED (strip) using a simple trim pot
1 parent 1ff5cf6 commit 0e44e69

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

PWM_LED_Control/PWM_LED_Control.ino

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* PWM_LED_Control
3+
* A simple combination of the AnalogReadSerial and Fade Arduino examples.
4+
*
5+
* Reads an analog input on pin 0, prints the result to the serial monitor,
6+
* and PWM the LED on pin 9 using the analogWrite() function.
7+
*
8+
* Attach the center pin of a potentiometer to pin A0, and the outside pins to
9+
* +5V and ground, and connect an LED to pin 9.
10+
*
11+
* This example code is in the public domain.
12+
*/
13+
14+
const int pot_pin = 0;
15+
const int led_pin = 9;
16+
17+
void setup() {
18+
Serial.begin(9600);
19+
Serial.println("Ready.");
20+
}
21+
22+
void loop() {
23+
int value = analogRead(pot_pin); // 0 <= N < 1024
24+
analogWrite(led_pin, value / 4); // 0 <= N < 255
25+
Serial.println(value);
26+
delay(100);
27+
}

0 commit comments

Comments
 (0)