Hi,
I have this project turning a projector on/off with one button and hide/show picture with another:
// Projektor model Acer H5380BD
#include <Bounce2.h>
#define powerButton 8
#define powerLED 9
#define hideButton 6
#define hideLED 7
int powerLEDState = LOW;
int hideLEDState = LOW;
// Instantiate a Bounce object :
Bounce powerDebouncer = Bounce();
Bounce hideDebouncer = Bounce();
boolean projectorState = false;
boolean hidePicture = false;
void setup() {
Serial.begin(9600);
// Setup the button with an internal pull-up
pinMode(powerButton, INPUT_PULLUP);
pinMode(hideButton, INPUT_PULLUP);
// After setting up the button, setup the Bounce instance
powerDebouncer.attach(powerButton);
powerDebouncer.interval(5);
hideDebouncer.attach(hideButton);
hideDebouncer.interval(5);
// Setup the LED :
pinMode(powerLED, OUTPUT);
digitalWrite(powerLED, powerLEDState);
pinMode(hideLED, OUTPUT);
digitalWrite(hideLED, hideLEDState);
}
void loop() {
int onBlink = 0; //integer to hold value of blinks during 'turning on' state
projectorState = false; //default projector state is off
// Update the Bounce instance
powerDebouncer.update();
hideDebouncer.update();
// Toggle POWER LED and serial output
if (powerDebouncer.fell()) {
powerLEDState = !powerLEDState;
hideLEDState = powerLEDState;
//digitalWrite(powerLED, powerLEDState);
digitalWrite(hideLED, hideLEDState);
projectorState = true;
if (powerLEDState == 1) {
Serial.write("* 0 IR 001\r\n"); // Turn projector on
while (projectorState == true) { //while projectorState is true, blink for 45 seconds while projector is turning on
powerLEDState = false; //switch powerLEDState to off
digitalWrite(powerLED, powerLEDState); //write powerLEDState state to powerLED, turning off the ON LED
delay (500); //delay a half second
powerLEDState = true; //switch powerLEDState to on
digitalWrite(powerLED, powerLEDState); //write powerLEDState state to powerLED, turning on the ON LED
delay (500); //delay a half second
onBlink++; //add 1 to onBlink integer (starting at 0)
if (onBlink == 45) { //if onBlink equals 45
powerLEDState = true; //switch powerLEDState to on
digitalWrite(powerLED, powerLEDState); //write powerLEDState state to powerLED, turning on the ON LED
onBlink = 0; //reset onBlink counter to 0
projectorState = false; //turn off projectorState to end blink program
}
}
}
else {
projectorState = true;
Serial.write("* 0 IR 002\r\n"); // Turn projector off
while (projectorState == true) { //while projectorState is true, blink for 45 seconds while projector is turning on
powerLEDState = false; //switch powerLEDState to off
digitalWrite(powerLED, powerLEDState); //write powerLEDState state to powerLED, turning off the ON LED
delay (200); //delay a half second
powerLEDState = true; //switch powerLEDState to on
digitalWrite(powerLED, powerLEDState); //write powerLEDState state to powerLED, turning on the ON LED
delay (500); //delay a half second
onBlink++; //add 1 to onBlink integer (starting at 0)
if (onBlink == 30) { //if onBlink equals 30
powerLEDState = false; //switch powerLEDState to off
digitalWrite(powerLED, powerLEDState); //write powerLEDState state to powerLED, turning LED OFF
onBlink = 0; //reset onBlink counter to 0
projectorState = false; //turn off projectorState to end blink program
}
}
}
}
// Toggle PICTURE LED and serial output
if (hideDebouncer.fell() && powerLEDState == 1) {
hideLEDState = !hideLEDState;
Serial.write("* 0 IR 030\r\n"); // Send hide/mute command
digitalWrite(hideLED, hideLEDState);
}
}
I would like to have the hide LED blink while the image is off. How do I do this? I've tried to implement the same methos as the power on/off, but all I get is the LED blinking without the system respoding to anything else.
/Carl