Hi,
Having extreme difficulties now...
Only Estop and reset is working now...
Here is the new code. I have completely removed all variables now and I do not understand..
I have attached code:
#include <Keyboard.h>
// ====================================================================
//Set Pin Values for buttons
const int endofday = 1;
const int reset = 2;
const int switch1 = 3;
const int switch2 = 4;
const int switch3 = 5;
const int switch4 = 6;
const int sstop = 7;
const int preshow = 8;
const int estop = 9;
const int gates = 10;
const int restraintsOPEN = 11;
const int restraintsCLOSED = 12;
const int tilt = 13;
const int selector = A0;
const int launch = A1;
const int dispatch = A2;
// Variable states
int sstopmode = 0; // station stop is off
int power = 0; // Power disconnect is off
int automode = 1; // Auto Mode is ON
void setup(){
// Pin modes
pinMode(endofday, INPUT_PULLUP);
pinMode(reset, INPUT_PULLUP);
pinMode(switch1, INPUT_PULLUP);
pinMode(switch2, INPUT_PULLUP);
pinMode(switch3, INPUT_PULLUP);
pinMode(switch4, INPUT_PULLUP);
pinMode(sstop, INPUT_PULLUP);
pinMode(preshow, INPUT_PULLUP);
pinMode(estop, INPUT_PULLUP);
pinMode(gates, INPUT_PULLUP);
pinMode(restraintsOPEN, INPUT_PULLUP);
pinMode(restraintsCLOSED, INPUT_PULLUP);
pinMode(tilt, INPUT_PULLUP);
pinMode(selector, INPUT_PULLUP);
pinMode(launch, INPUT_PULLUP);
pinMode(dispatch, INPUT_PULLUP);}
void loop() {
// Set variables for button states
int endofdayPOS = digitalRead(endofday);
int resetPOS = digitalRead(reset);
int switch1POS = digitalRead(switch1);
int switch2POS = digitalRead(switch2);
int switch3POS = digitalRead(switch3);
int switch4POS = digitalRead(switch4);
int sstopPOS = digitalRead(sstop);
int preshowPOS = digitalRead(preshow);
int estopPOS = digitalRead(estop);
int gatesPOS = digitalRead(gates);
int tiltPOS = digitalRead(tilt);
int selectorPOS = digitalRead(selector);
int launchPOS = digitalRead(launch);
int dispatchPOS = digitalRead(dispatch);
// |------------------------------------------------------------------------------|
// |===============================Station Controls===============================|
// |------------------------------------------------------------------------------|
//Launch Button
if (digitalRead(launchPOS) == LOW){ // If launch is pressed
Keyboard.press('l'); // Press L
delay (300);
Keyboard.releaseAll();}
// Dispatch Button
if (digitalRead(dispatchPOS) == LOW){ // If dispatch is pressed
Keyboard.press(' '); // Press spacebar
delay (300);
Keyboard.releaseAll();}
// Tilt Button
if (digitalRead(tiltPOS) == LOW){ // If tilt is pressed
Keyboard.press(KEY_RETURN); // Press enter for 4 seconds
delay (4000);
Keyboard.releaseAll();}
//Preshow doors/start
if (digitalRead(preshowPOS) == LOW){ // If preshow is pressed
Keyboard.press(KEY_RETURN); // press return
delay (10000); // delay 10 seconds
Keyboard.releaseAll();}
//Gates
if (digitalRead(gatesPOS) == LOW){
Keyboard.press(KEY_RIGHT_ARROW);
delay (100);
Keyboard.releaseAll();}
else{
Keyboard.press(KEY_LEFT_ARROW);
delay (100);
Keyboard.releaseAll();}
//Restraints
if (digitalRead(restraintsOPEN) == LOW){
Keyboard.press(KEY_UP_ARROW);
delay(100);
Keyboard.releaseAll();}
if (digitalRead(restraintsCLOSED) == LOW){
Keyboard.press(KEY_DOWN_ARROW);
delay(100);
Keyboard.releaseAll();}
//Selector
//if (digitalRead(selectorPOS) == LOW){
// Keyboard.press('x'); // Do nothing. Reprogram if needed // |===================|
// delay (100); // | Disabled |
// Keyboard.releaseAll();} // |===================|
//else{
//Keyboard.press('z');
//delay (100);
//Keyboard.releaseAll();}
// |------------------------------------------------------------------------------|
// |===============================Stop Controls==================================|
// |------------------------------------------------------------------------------|
// Station Stop Button
//Removed for time being
// Station Stop Reset
//if (sstopmode == 1 && resetPOS == LOW){ // If sstop is engaged and reset button is pressed
// sstopmode = 0;} // Turn sstop to 0 (off)
// Estop button
if (estopPOS == LOW){ // If Estop is pressed
sstopmode = 1; // Turn on Station Stop
Keyboard.press('s'); // Press S
delay(100);
Keyboard.releaseAll();}
//Reset Estop
if (estopPOS == HIGH && resetPOS == LOW){ // If estop is up and reset is pushed
Keyboard.press('r'); // press R
delay(100);
Keyboard.releaseAll();}
// End Of Day
if (endofdayPOS == HIGH){ // If endofdayestop is pressed down
Keyboard.press('s');
sstopmode = 1;}
if (endofdayPOS == LOW){ // if endofdayestop is off
sstopmode = 0;}
// |--------------------------------------------------------------------------------------|
// |===============================Maintainance Controls==================================|
// |--------------------------------------------------------------------------------------|
// Switch 1
if (digitalRead(switch1POS) == LOW){ // If switch 1 is pressed // |====================================|
Keyboard.press(KEY_RIGHT_ARROW); // Press 1 // | Only available in Manual Mode |
delay (100); // |====================================|
Keyboard.releaseAll();}
// Switch 2
if (digitalRead(switch2POS) == LOW){ // If switch 2 is pressed
Keyboard.press(KEY_LEFT_ARROW); // Press 2
delay (100);
Keyboard.releaseAll();}
// Switch 3
if (digitalRead(switch2POS) == LOW){ // If switch 3 is pressed
Keyboard.press('1'); // Press 3
delay (100);
Keyboard.releaseAll();}
//Switch 4
if (digitalRead(switch2POS) == LOW){ // If switch 4 is pressed
Keyboard.press('2'); // Press 4
delay (100);
Keyboard.releaseAll();}
// |--------------------------------------------------------------------------------------|
// |=======================================Mode Controls==================================|
// |--------------------------------------------------------------------------------------|
//Switch to auto mode:
//if (resetPOS == LOW && dispatchPOS == LOW){ // If reset and dispatch have been pressed
// automode = 1;} // Set auto mode to ON
//if (resetPOS == LOW && launchPOS){ // If reset and launch have been pressed
//automode = 0;} // Auto mode off.
}
//
/code]
Please help. It is annoying me now :slightly_frowning_face: LOL!