調整PWM的週期控制led閃爍的間隔時間: http://arduino.tw/articlesindex/electricity/206-whatspwm.html http://blog.21ic.com/user1/5475/archives/2009/58014.html
----------------------------------------------------
int sensorReading; // create a variable to store the
// value of variable resistor
int ledValue; // create a variable to store the
// value of led
void setup() {
}
void loop() {
// get the value of variable resistor and store in sensorReading
// it has a range between 0 - 1023
sensorReading = analogRead(3);
// however value for LED can only be 0 to 255, so we have to
// scale down the sensorReading using 「map」 function
ledValue = map(sensorReading, 0, 1023, 0, 255);
// send the signal to pin 9 (PWM) to control intensity of the LED
analogWrite(9, ledValue);
}