File tree Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments