58 lines
1.2 KiB
Arduino
58 lines
1.2 KiB
Arduino
|
|
||
|
const int buttonPin = 3;
|
||
|
const int ledLargo = 5;
|
||
|
const int ledCorto = 2;
|
||
|
|
||
|
// variables will change:
|
||
|
boolean flag_off = 0; // variable for reading the pushbutton status
|
||
|
|
||
|
void setup() {
|
||
|
// initialize the LED pin as an output:
|
||
|
pinMode(ledLargo, OUTPUT);
|
||
|
pinMode(ledCorto, OUTPUT);
|
||
|
// initialize the pushbutton pin as an input:
|
||
|
pinMode(buttonPin, INPUT);
|
||
|
digitalWrite(ledCorto, LOW);
|
||
|
digitalWrite(ledLargo, LOW);
|
||
|
Serial.begin(9600);
|
||
|
}
|
||
|
|
||
|
void loop(){
|
||
|
|
||
|
if(!digitalRead(buttonPin))
|
||
|
{
|
||
|
delay(10);
|
||
|
if ( (!digitalRead(buttonPin)) && !flag_off ) {
|
||
|
// turn LED on:
|
||
|
digitalWrite(ledLargo, HIGH);
|
||
|
digitalWrite(ledCorto, HIGH);
|
||
|
Serial.println("Encendido");
|
||
|
flag_off = 1;
|
||
|
}
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
delay(10);
|
||
|
if( (digitalRead(buttonPin)) && flag_off)
|
||
|
{
|
||
|
|
||
|
Serial.println("Fade Out");
|
||
|
for (int i=0; i <= 255; i++)
|
||
|
{
|
||
|
analogWrite(ledLargo, 255 - i);
|
||
|
//Serial.println(255 - i);
|
||
|
delay(10);
|
||
|
}
|
||
|
Serial.println("Apagado Led Largo");
|
||
|
delay(60000);
|
||
|
digitalWrite(ledCorto, LOW);
|
||
|
Serial.println("Apagado Led Corto");
|
||
|
flag_off = 0;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
|
||
|
|