You can turn on LED by each level using analogWrite.
analogWrite function has 2 parameter.
analogWrite function's first parameter is pinNumber and second parameter is value.
The value can has number from 0 to 255.
Following is electric circuit diagram.
From ~10 port to the resist and to LED.
The ports have a prefix '~' are analog output ports.
Next code is to send eletric from ~10 analog output port to LED.
// Pin 10 has an LED connected on most Arduino boards.
// give it a name:
int led = 10;
// the setup routine runs once when you press reset:
void setup() {
// initialize the digital pin as an output.
pinMode(led, OUTPUT);
}
// the loop routine runs over and over again forever:
void loop() {
byte n = 5;
for(int x = 0; x < 5; ++x)
{
analogWrite(10, x*255/n);
delay(1000);
}
}
댓글 없음:
댓글 쓰기