The goal is to get a light to stay permanently on when a switch is moved into the "open" position, and then when the switch moves back to the "closed" position, the light turns off.
I have this sample of my code, currently, when you turn the switch to "open", the light flashes on for a millisecond basically and then immediately turns off. As I said just before, I want the light to stay on when the switch is "open" and turn off when the switch is "closed."
else{ //If restraint button in open position...
Keyboard.press(KEY_F9);
Keyboard.press(KEY_F10);//Press F9 Key
delay (100); //Delay 100ms
Keyboard.releaseAll(); //Release F9 Key
digitalWrite(DispatchLT, HIGH);
RestraintHX = RestraintPOS;} //Save new button value
If anyone can help me figure out what I need to add to the code, it would be greatly appreciated!
Thanks!
The goal is to get a light to stay permanently on when a switch is moved into the "open" position, and then when the switch moves back to the "closed" position, the light turns off.
Which light? Which switch?
Your code would be a lot easier to read if the { and } lined up properly. Put each { on a new line, and use Tools + Auto Format.
Keyboard.press(KEY_F10);//Press F9 Key
Looks like you are confused again. Comments that state the obvious do not add any value.
I'm gonna be honest. My friend wrote the code and I've been using it, so all the errors you see are pretty much his fault and I don't have the knowledge to clean it up. I'll have to nudge him to do that.
So I reformatted and attached the file here, hopefully it makes a difference.
The light I am talking about is DispatchLT and the switch I am talking about is RestraintBT
The specific code is this.
if (RestraintHX != RestraintPOS){ //If restraint button has moved...
delay (100); //Delay 100ms
if (RestraintPOS == LOW){ //If restraint button in close position...
Keyboard.press(KEY_F11); //Press F12 Key
Keyboard.press(KEY_F12);
delay (100); //Delay 100ms
Keyboard.releaseAll(); //Release F12 Key
digitalWrite(DispatchLT, LOW);
RestraintHX = RestraintPOS;
} //Save new button value
else{ //If restraint button in open position...
Keyboard.press(KEY_F9);
Keyboard.press(KEY_F10);//Press F9 Key
delay (100); //Delay 100ms
Keyboard.releaseAll(); //Release F9 Key
digitalWrite(DispatchLT, HIGH);
RestraintHX = RestraintPOS;
} //Save new button value
}
The goal is to get a light to stay permanently on when a switch is moved into the "open" position, and then when the switch moves back to the "closed" position, the light turns off.
Isn't this just as simple as
void loop() {
ledState = ! digitalRead(switchPin); // assume ON = LOW so invert the value
digitalWrite(ledPin, ledState)
}
Or perhaps the title and the question need a bit more thought.
Here is a video I took of myself, I modified the code by adding a delay onto it...
Here is the part I modified.
RestraintHX = RestraintPOS;
} //Save new button value
else{ //If restraint button in open position...
Keyboard.press(KEY_F9);
Keyboard.press(KEY_F10);//Press F9 Key
delay (100); //Delay 100ms
Keyboard.releaseAll(); //Release F9 Key
digitalWrite(DispatchLT, HIGH);
delay(1000);
RestraintHX = RestraintPOS;
} //Save new button value
}
It makes make the DispatchLT go on when RestraintPOS changes to "High." It only stays on for 1 second, and while it is on, nothing else works because it is on a delay.
The goal is to get this light to stay on permanently while the switch is "high" and to allow the device to continue working and not be frozen up in the "delay" mode. Then, when the switch is turned back to the "Low" position, the DispatchLT light turns off.
TTD03:
The goal is to get this light to stay on permanently while the switch is "high" and to allow the device to continue working and not be frozen up in the "delay" mode. Then, when the switch is turned back to the "Low" position, the DispatchLT light turns off.
Isn't that what my little piece of code does - without a delay() anywhere - adapt/adopt the idea into your code.