Tip | ||
---|---|---|
| ||
|
Pre-requisite:
- Finished Starting to play with Arduino
- Optional Dimming LED
- Basic circuit knowledge
Objectives:
- Use analogRead to read AD converter on Arduino.
Descriptions:
Please refer to : http://www.arduino.cc/en/Tutorial/Potentiometer
iFrame src http://www.arduino.cc/en/Tutorial/Potentiometer width 960 id potentiometer height 600 The original programme will blink the led using the input as speed of blinking, It's also possible to adjust the LED intensity using the input.
Code Block int potPin = 0; // select the input pin for the potentiometer int ledPin = 9; // select the pin for the LED (need to be any pin you connected and need to have a "~") int val = 0; // variable to store the value coming from the sensor void setup() { pinMode(ledPin, OUTPUT); // declare the ledPin as an OUTPUT } void loop() { val = analogRead(potPin); // read the value from the sensor analogWrite(ledPin, val >> 2); // because the read value is 0 -> 1023, the output range is 0 -> 255, // >> 2 basically is a faster way of dividing by 4 }