So I have a bunch of momentary push button switches. Basically what I am trying to do is when a button is pressed the light inside turns on or off and it sends a keyboard press to a computer. Then when it is pushed a second time it the light inside turns on or off and it sends a different keyboard press. I am a beginner so I am not sure what the best way is. I have been trying to use a boolean but it doesn't work like how I want it to(I understand that the boolean is doing exactly what it should be doing). I was just wondering what the best way was to execute button presses and lights like I explained above. Any pointers are much appreciated. Code is below. Thanks for your time!
const int PowerSwitch = 12;
const int Floorlight = 11;
const int FloorButton = 10;
const int Stopresetlight = 9;
const int StopresetButton = 8;
const int Stoplight = 7;
const int StopButton = 6;
const int GatesSwitch = 5;
const int Harnesslight = 4;
const int HarnessButton = 3;
const int Dispatchlight = 2;
const int DispatchButton = 1;
boolean DispatchButtonbuttonPressed;
boolean HarnessButtonbuttonPressed;
boolean FloorButtonbuttonPressed;
boolean StopButtonbuttonPressed;
boolean StopresetButtonbuttonPressed;
boolean GatesSwitchbuttonPressed;
boolean PowerSwitchbuttonPressed;
#include <Keyboard.h>
void setup() {
pinMode(Dispatchlight,OUTPUT);
pinMode(DispatchButton, INPUT_PULLUP);
pinMode(Harnesslight, OUTPUT);
pinMode(HarnessButton, INPUT_PULLUP);
pinMode(GatesSwitch, INPUT_PULLUP);
pinMode(StopButton, INPUT_PULLUP);
pinMode(Stoplight, OUTPUT);
pinMode(StopresetButton, INPUT_PULLUP);
pinMode(Stopresetlight, OUTPUT);
pinMode(FloorButton, INPUT_PULLUP);
pinMode(Floorlight, OUTPUT);
pinMode(PowerSwitch, INPUT_PULLUP);
digitalWrite(DispatchButton, HIGH);
digitalWrite(HarnessButton, HIGH);
digitalWrite(GatesSwitch, HIGH);
digitalWrite(StopButton, HIGH);
digitalWrite(StopresetButton, HIGH);
digitalWrite(FloorButton, HIGH);
digitalWrite(PowerSwitch, HIGH);
}
void loop() {
if (digitalRead(StopButton) == LOW) {
StopButtonbuttonPressed = true;
} else {
StopButtonbuttonPressed = false;
}
{
if(StopButtonbuttonPressed == true) {
digitalWrite(Stoplight, HIGH);
Keyboard.press(0xD1);
digitalWrite(Stopresetlight, HIGH);
delay(250);
digitalWrite(Stopresetlight, LOW);
delay(250);
}
else {
digitalWrite(Stoplight, LOW);
delay(500);
digitalWrite(Stoplight, HIGH);
delay(500);
}
if (digitalRead(StopresetButton) == LOW) {
StopresetButtonbuttonPressed = true;
} else {
StopresetButtonbuttonPressed = false;
}
if(StopresetButtonbuttonPressed == true) {
digitalWrite(Stopresetlight, HIGH);
delay(5000);
digitalWrite(Stopresetlight,LOW);
Keyboard.release(0xD1);
}
else {
digitalWrite(Stopresetlight, LOW);
}
{
}
}
}