fade a led using arduino
here we will find that how the analog pins are use for the working purpose...
we are not only fading the led .. we also using the variable resistor for very sensitive case. the output of the pin13 will be change from high - low when we move the joystick.
/*Fade
This example shows how to fade an LED
using the analogWrite() function.
This example code is in the public domain.
*/
const int lowestPin = 2;
const int highestPin = 13;
int value1=0;
int joyPin1 = 0;
int led = 13; // the pin that the LED is attached to
int brightness = 0; // how bright the LED is
// how many points to fade the LED by
// the setup routine runs once when you press reset:
void setup() {
// declare pin 9 to be an output:
Serial.begin(9600);
pinMode(led, OUTPUT);
joyPin1=Serial.read();
}
// the loop routine runs over and over again forever:
void loop() {
value1 = analogRead(joyPin1);
// set the brightness of pin 0:
for (int thisPin = lowestPin; thisPin <= highestPin; thisPin++) {
// fade the LED on thisPin from off to brightest:
for (int value1 = 0; value1 < 255;value1++) {
digitalWrite(thisPin, brightness);
delay(2);
}
digitalWrite(led, value1);
value1 = digitalRead(joyPin1);
if(value1==0 ||value1==123){ // change the brightness for next time through the loop:
value1=value1;}
// reverse the direction of the fading at the ends of the fade:
Serial.println(value1);
// wait for 30 milliseconds to see the dimming effect
delay(30);
}
}
Comments
Post a Comment