Why will this not let me take a wire to ground out pin 3 it requires me to turn it off in the serial monitor and back on.
#include <Boards.h>
#include <Firmata.h>
#include <FirmataConstants.h>
#include <FirmataDefines.h>
#include <FirmataMarshaller.h>
#include <FirmataParser.h>
#include <Wire.h>
// this constant won't change:
const int Down_buttonPin = 3;
// Variables will change:
int shotsLeftCheck = 35; // Check How Many Shots Left
int down_buttonState = 0; // current state of the trigger
int down_lastButtonState = 0; // previous state of the trigger
int Game_start = 4; // Starts Game
int Game_startState; // Shows Game On or Off
int pincheck[18] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
int prevpincheck[18] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
bool bPress = false;
String pin_str = "";
void setup()
{
Serial.begin(9600);
pinMode( Down_buttonPin , INPUT_PULLUP);
digitalWrite(Game_start, HIGH);
pinMode(Game_start, OUTPUT);
for (int ii = 2;ii<=sizeof(pincheck)/sizeof(pincheck[0]);ii++){
pinMode(ii,OUTPUT);
}
}
void loop()
{
while (Serial.available()){
char in_char = Serial.read();
if (int(in_char)!=-1){
pin_str+=in_char;
}
if (in_char=='\n'){
int pin_num = pin_str.toInt();
pincheck[pin_num] = !pincheck[pin_num];
digitalWrite(pin_num, pincheck[pin_num]);
Serial.print("Pin # ");
Serial.print(pin_num);
if (pincheck[pin_num]==0){
Serial.println(" OFF");
} else {
Serial.println(" ON");
}
pin_str = "";
pincheck[Game_start] = digitalRead(Game_start);
if (pincheck[Game_start] == HIGH){
delay(5);
Serial.println("Press Play");
} else {
Serial.println("Begin");
checkDown();
delay(5);
}
}
}
}
void checkDown()
{
down_buttonState = digitalRead(Down_buttonPin);
Serial.print("Down Button State ");
Serial.println(down_buttonState);
if(shotsLeftCheck <= 0 || shotsLeftCheck >3) {
digitalWrite(Game_start , HIGH);
shotsLeftCheck = 3;
Serial.println("Shoft Left Check Set to 3");
} else {
Serial.println("Bang Check");
// compare the buttonState to its previous state
if (down_buttonState != down_lastButtonState) {
// if the state has changed, increment the counter
if (down_buttonState == LOW) {
// if the current state is HIGH then the button went from off to on:
Serial.println("Bang");
Serial.print("Number Of Shots Remaining: ");
Serial.println(shotsLeftCheck);
shotsLeftCheck--;
}
// Delay a little bit to avoid bouncing
delay(50);
}
// save the current state as the last state, for next time through the loop
down_lastButtonState = down_buttonState;
}
}