Objective:
Control the LED's rate of blinking with a Potentiometer.
Parts:
LED
330 Ohm Resistor
Potentiometer
Sketch:
int sensorPin = 0;
int ledPin = 13;
void setup()
{
pinMode(ledPin, OUTPUT);
}
void loop() // this function runs repeatedly after setup() finishes
{
int sensorValue;
sensorValue = analogRead(sensorPin);
digitalWrite(ledPin, HIGH);
delay(sensorValue);
digitalWrite(ledPin, LOW);
delay(sensorValue);
}
Analysis:
The LED [Connected to pin number 13, declared as "ledPin"] turns on [HIGH] for "sensorValue" seconds [delay(sensorValue)]. After that, it turns off [LOW] for "sensorValue" seconds [delay(sensorValue)].
"sensorValue" depends on how much you turn the potentiometer.
No comments:
Post a Comment