int led1Pin = 9; // PWM pin 9 for the LED 1
int led2Pin = 10; // PWM pin 10 for the LED 2
int analogPin = 2; // variable resistor on analog pin 2
void setup(){ }
void loop()
{
for (int i=0; i<=255; i++) // ascending value for i
{
analogWrite(led1Pin, i); // sets brightess level to i
delay(delayVal()); // gets time value and pauses
}
for (int i=255; i>=0; i--) // descending value for i
{
analogWrite(led1Pin, i); // sets brightess level to i
delay(delayVal()); // gets time value and pauses
}
for (int i=0; i<=255; i++)
{
analogWrite(led2Pin, i);
delay(delayVal());
}
for (int i=255; i>=0; i--)
{
analogWrite(led2Pin, i);
delay(delayVal());
}
}
int delayVal()
{
int v; // create temporary variable
v = analogRead(analogPin); // read analog value
v /= 10; // this convert 0-1024 to 0-129
return v; // returns final value
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment