📬❄️📦Adafruit Holiday Shipping Deadlines 2019: Please place all UPS 3 Day orders by 11am ET Friday December 13 📬❄️📦
0

sound effect player connecting to arduino mega
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Re: sound effect player connecting to arduino mega

by roadshark on Tue Nov 05, 2019 8:19 am

I have put this at the start
Code: Select all | TOGGLE FULL SIZE
int scorepin26 = digitalRead(26);

And this in game 2.
Code: Select all | TOGGLE FULL SIZE
 Serial.println(scorepin26);

After I press button 23 it goes into the correct state but the value I see printed for scorepin26 is 1 even when I am continuously pressing the button attached to it.

roadshark
 
Posts: 565
Joined: Sun Nov 29, 2015 5:53 am

Re: sound effect player connecting to arduino mega

by adafruit_support_bill on Tue Nov 05, 2019 10:44 am

int scorepin26 = digitalRead(26);

That will set the value of scorepin26 to either 0 or 1 - depending on whether the button is pressed.

Unless you have some other code that increments scorepin26, it will not change. I don't see scorepin26 at all in the last version of the full code that you posted.

adafruit_support_bill
 
Posts: 75285
Joined: Sat Feb 07, 2009 10:11 am

Re: sound effect player connecting to arduino mega

by roadshark on Wed Nov 06, 2019 6:20 am

Here is the code:)
Code: Select all | TOGGLE FULL SIZE
#include <Adafruit_LEDBackpack.h>
#include <Wire.h>
Adafruit_7segment matrix = Adafruit_7segment();
#include <Servo.h>

Servo ballRelease;// create servo object to control a servo

int pos = 85;    // variable to store the servo position ball release
int gameScore = 0;//players score
int gameScoreDefault = 0;
int sensorPins[] = {22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 47}; //Pin 22 = no scoring. Pin 23 = normal game. Pin 24 = Random scores Pins  (25, 26, 27, 28, 29, 30, 31, 32)= ball sensors
int sensorPinsCount = 12;
int mySensVals[] = {100, 5, 20, 10, 200, 20, 5, 100};//Values for the eight pins normal game.
int possibleValues[] = {100, 5, 20, 10, 200, 20, 5, 100};//Values for a random game.
int headLedPins[] = {33, 34, 35, 36, 37, 38};//LEDS FOR start up sequence
int headLedPinsCount = 6;
int scoreLedPins [] = {39, 40, 41, 42, 43};
int scoreLedPinsCount = 5;
int soundEffectActivationPin[] = {44, 45, 46, 48}; //sound effect player (44=100.  45= 20. 46 = 10   48= start up sound)
int soundEffectActivationPinCount = 4;
int state = 0;
int x = 0;
bool gameTwo = false;

//Blinking SCORE LEDS
int ledState = LOW;             // ledState used to set the LED
unsigned long previousMillis = 0;        // will store last time LED was updated
const long interval = 500;           // interval at which to blink (milliseconds)
int blinksLeft = 0;  // set this variable any time you want to start a sequence of blinks
int blinkPin = 0;  // This is the pin number for the led to blink.
int scorepin26 = digitalRead(26);
void setup() {
  Serial.begin(9600);
  Wire.begin ();
  matrix.begin(0x71);

  //ATTACH SEVOS TO PINS AND SET DEFAULT POSITION
  ballRelease.attach(9);
  ballRelease.write(pos);


  pinMode (49, OUTPUT);
  pinMode (50, OUTPUT);

  //Sets the reset button and break beam sensors pins to inputs.
  for (int thisPin = 0; thisPin < sensorPinsCount; thisPin++) {
    pinMode(sensorPins[thisPin], INPUT_PULLUP);
  }
  //Sets the sound effect activation pins to output.
  for (int thisPin = 0; thisPin  < soundEffectActivationPinCount; thisPin++) {
    pinMode(soundEffectActivationPin[thisPin], INPUT);
  }
  //sets the scoring LEDs pins to out put
  for (int thisPin = 0; thisPin  < scoreLedPinsCount; thisPin++) {
    pinMode(scoreLedPins[thisPin], OUTPUT);
  }
  //Sets the pins for the LEDS on MOVING HEAD  to output.
  for (int thisPin = 0; thisPin  < headLedPinsCount; thisPin++) {
    pinMode(headLedPins[thisPin], OUTPUT);
  }

}
void loop() {
  unsigned long currentMillis = millis();
  switch (state)

  {
    case 0:
      Serial.println("In case 0 turn off motor");
      //turns off the motor
      digitalWrite ((49), LOW);//Low_speed
      digitalWrite ((50), LOW);//High_speed



      //matrix.begin(0x71);
      matrix.blinkRate(2);
      matrix.print(gameScore, DEC);
      matrix.writeDisplay();
      state = 1;
      break;

    case 1:
      Serial.println("In case 1 selection of type of game played");

      if (digitalRead (22) == LOW) {
        gameScore = 0;
        for (int j = 0; j < 5; j++)//Start game light sequence
        {
          for (int i = 0; i < headLedPinsCount; i++)
          {
            digitalWrite(headLedPins[i], HIGH);
            delay(100);
            digitalWrite(headLedPins[i], LOW);
            delay (100);
          }
        }
        for (pos = 0; pos <= 85; pos += 5) { // goes from 0 degrees to 85 degrees in steps of 5 degree
          ballRelease.write(pos);              // tell servo to go to position in variable 'pos'
          delay(10);                       // waits 10ms for the servo to reach the position
        }
        delay (3500);//Gives time for the balls to roll down into catcher.
        for (pos = 85; pos >= 0; pos -= 3) { // goes from 85 degrees to 0 degrees
          ballRelease.write(pos);              // tell servo to go to position in variable 'pos'
          delay(10);// waits 10ms for the servo to reach the position

        }

        digitalWrite ((49), HIGH);//Turns on DC motor via resistor AND transistor
        Serial.println("moving to case 2");
        state = 2;
        break;
      }


      if (digitalRead (23) == LOW) {
        gameTwo = true;
        gameScore = 0;
        pinMode (48, OUTPUT);
        digitalWrite ((48), LOW);//Activate start up sound
        delay (150);
        pinMode (48, INPUT);

        for (int j = 0; j < 5; j++)//Start game light sequence
        {
          for (int i = 0; i < headLedPinsCount; i++)
          {
            digitalWrite(headLedPins[i], HIGH);
            delay(100);
            digitalWrite(headLedPins[i], LOW);
            delay (100);
          }
        }
        for (pos = 0; pos <= 85; pos += 5) { // goes from 0 degrees to 120 degrees in steps of 1 degree
          ballRelease.write(pos);              // tell servo to go to position in variable 'pos'
          delay(10);                       // waits 15ms for the servo to reach the position
        }
        delay (3500);//Gives time for the balls to roll down into catcher.
        for (pos = 85; pos >= 0; pos -= 3) { // goes from 120 degrees to 0 degrees
          ballRelease.write(pos);              // tell servo to go to position in variable 'pos'
          delay(10);// waits 10ms for the servo to reach the position

        }


        digitalWrite ((49), HIGH);//Turns on DC motor via resistor AND transistor
        Serial.print("moving to case 3");
        state = 3;
        break;
      }


      if (digitalRead (24) == LOW) {

        gameScore = 0;
        randomSeed(analogRead(A0));//initialize the random number generator with a fairly random input, pin AO
        for ( int i = 0; i < 8; i++) {
          mySensVals[i] = possibleValues[random(0, 7)];

        }
        pinMode (48, OUTPUT);
        digitalWrite ((48), LOW);//Activate start sound
        delay (150);
        pinMode (48, INPUT);
        for (int j = 0; j < 5; j++)//Start game light sequence
        {
          for (int i = 0; i < headLedPinsCount; i++)
          {
            digitalWrite(headLedPins[i], HIGH);
            delay(100);
            digitalWrite(headLedPins[i], LOW);
            delay (100);
          }
        }


        for (pos = 0; pos <= 85; pos += 5) { // goes from 0 degrees to 120 degrees in steps of 1 degree
          ballRelease.write(pos);              // tell servo to go to position in variable 'pos'
          delay(10);                       // waits 15ms for the servo to reach the position
        }
        delay (3500);//Gives time for the balls to roll down into catcher.
        for (pos = 85; pos >= 0; pos -= 3) { // goes from 120 degrees to 0 degrees
          ballRelease.write(pos);              // tell servo to go to position in variable 'pos'
          delay(10);// waits 10ms for the servo to reach the position

        }

        digitalWrite ((49), HIGH);//Turns on DC motor via resistor AND transistor
        Serial.print("moving to case 4");
        state = 4;
        break;
      }
      //state = 1;
      break;//  Here the code loops until a button is pressed to exit this state.
    //***************************************GAME ONE NO SOUNDS AND NO DISPLAY****************************************************
    case 2:
      Serial.println("In case 2 game 1");

      //matrix.begin(0x71);
      matrix.print(gameScoreDefault, DEC);
      matrix.writeDisplay();
      if (digitalRead (47) == LOW) {//reset button

        gameScore = 0;
        state = 0;
        break;
      }
      if (gameScore >= 220) {
        digitalWrite ((49), LOW); //Turns off DC Motor Slow speed.
        digitalWrite ((50), HIGH);//Turns on DC motor High Speed,
      }
      //BREAK BEAM SENSOR SCORING
      if ((digitalRead (25) == LOW) || (digitalRead (32) == LOW)) {
        while ((digitalRead (25) == LOW) || (digitalRead (32) == LOW));
        gameScore += 100;
        digitalWrite(blinkPin, LOW);  // cancel any ongoing blinking
        blinksLeft = 3;  // start a series of blinks
        blinkPin = 39;  // new pin to blink

      }
      if ((digitalRead (26) == LOW) || (digitalRead (31) == LOW)) {
        while ((digitalRead (26) == LOW) || (digitalRead (31) == LOW));
        gameScore += 5;
        digitalWrite(blinkPin, LOW);  // cancel any ongoing blinking
        blinksLeft = 3;  // start a series of blinks
        blinkPin = 40;  // new pin to blink
        Wire.beginTransmission(8); // transmit to device #8
        Wire.write("M"); // sends one bytes.Servo monster head turns.
        Wire.endTransmission();
      }

      if ((digitalRead (27) == LOW) || (digitalRead (30) == LOW)) {
        while ((digitalRead (27) == LOW) || (digitalRead (30) == LOW));
        gameScore += 20;
        digitalWrite(blinkPin, LOW);  // cancel any ongoing blinking
        blinksLeft = 3;  // start a series of blinks
        blinkPin = 41;  // new pin to blink
      }
      if (digitalRead (28) == LOW) {
        while (digitalRead (28));
        gameScore += 10;
        digitalWrite(blinkPin, LOW);  // cancel any ongoing blinking
        blinksLeft = 3;  // start a series of blinks
        blinkPin = 42;  // new pin to blink
      }

      if (digitalRead (29) == LOW) {
        while (digitalRead (29));
        gameScore += 200;

        digitalWrite(blinkPin, LOW);  // cancel any ongoing blinking
        blinksLeft = 3;  // start a series of blinks
        blinkPin = 43;  // new pin to blink
        delay (1000);

        Wire.beginTransmission(8); // transmit to device #8
        Wire.write("H"); // sends one bytes.Servo monster head turns.
        Wire.endTransmission();

      }


      //Herman character turns on  player scores of
      if ((gameScore == 100) || (gameScore == 220))  {
        Wire.beginTransmission(8); // transmit to device #8
        Wire.write("H"); // sends one bytes.Servo Hermans head turns.
        Wire.endTransmission();
      }
      //Monster Character turns on player score when 150 or 300
      if ((gameScore == 150) || (gameScore == 300))  {//Monster head character bonus

        Wire.beginTransmission(8); // transmit to device #8
        Wire.write("M"); // sends one bytes.Servo monster head turns.
        Wire.endTransmission();

      }


      if ((currentMillis - previousMillis >= interval) && (blinksLeft > 0))
      {
        // save the last time you blinked the LED
        previousMillis = currentMillis;
        // if the LED is off turn it on and vice-versa:
        if (ledState == LOW)
        {
          ledState = HIGH;
        }
        else
        {
          ledState = LOW;
          blinksLeft--; // one blink done
        }
        digitalWrite(blinkPin, ledState);
      }
      //state = 2;
      break;




    //*********************************************GAME  TWO********************************************************************************************************************
    case 3:
     
        Serial.println("In case 3 game 2");
        Serial.println(scorepin26);

        //matrix.begin(0x71);
        matrix.print(gameScore, DEC);
        matrix.writeDisplay();
        if (digitalRead (47) == LOW) {

          gameScore = 0;
          state = 0;
          break;
        }


        if (gameScore >= 220) {
          digitalWrite ((49), LOW); //Turns off DC Motor Slow speed.
          digitalWrite ((50), HIGH);//Turns on DC motor High Speed,
        }

        if ((digitalRead (25) == LOW) || (digitalRead (32) == LOW)) {
          while ((digitalRead (25) == LOW) || (digitalRead (32) == LOW));
          gameScore += 100;
          //matrix.begin(0x71);
          matrix.print(gameScore, DEC);
          matrix.writeDisplay();
          pinMode (44, OUTPUT);
          digitalWrite ((44), LOW);//Activate Pin T05 on Sound Effects player.
          delay (150);
          pinMode (44, INPUT);
          digitalWrite(blinkPin, LOW);  // cancel any ongoing blinking
          blinksLeft = 3;  // start a series of blinks
          blinkPin = 39;  // new pin to blink

        }
        if ((digitalRead (26) == LOW) || (digitalRead (31) == LOW)) {
          while ((digitalRead (26) == LOW) || (digitalRead (31) == LOW));
          gameScore += 5;
          //matrix.begin(0x71);
          matrix.print(gameScore, DEC);
          matrix.writeDisplay();

          digitalWrite(blinkPin, LOW);  // cancel any ongoing blinking
          blinksLeft = 3;  // start a series of blinks
          blinkPin = 40;  // new pin to blink


          Wire.beginTransmission(8); // transmit to device #8
          Wire.write("M"); // sends one bytes.Servo monster head turns.
          Wire.endTransmission();



        }

        if ((digitalRead (27) == LOW) || (digitalRead (30) == LOW)) {
          while ((digitalRead (27) == LOW) || (digitalRead (30) == LOW));
          gameScore += 20;
          // matrix.begin(0x71);
          matrix.print(gameScore, DEC);
          matrix.writeDisplay();

          pinMode (45, OUTPUT);
          digitalWrite ((45), LOW);//Activate Pin T05 on Sound Effects player.
          delay (150);
          pinMode (45, INPUT);

          digitalWrite(blinkPin, LOW);  // cancel any ongoing blinking
          blinksLeft = 3;  // start a series of blinks
          blinkPin = 41;  // new pin to blink
        }

        if (digitalRead (28) == LOW) {
          while (digitalRead (28));
          gameScore += 10;
          matrix.begin(0x71);
          matrix.print(gameScore, DEC);
          matrix.writeDisplay();

          pinMode (46, OUTPUT);
          digitalWrite ((46), LOW);//Activate Pin T05 on Sound Effects player.
          delay (150);
          pinMode (46, INPUT);

          digitalWrite(blinkPin, LOW);  // cancel any ongoing blinking
          blinksLeft = 3;  // start a series of blinks
          blinkPin = 42;  // new pin to blink

        }

        if (digitalRead (29) == LOW) {
          while (digitalRead (29));
          gameScore += 200;
          matrix.begin(0x71);
          matrix.print(gameScore, DEC);
          matrix.writeDisplay();

          digitalWrite(blinkPin, LOW);  // cancel any ongoing blinking
          blinksLeft = 3;  // start a series of blinks
          blinkPin = 43;  // new pin to blink


          Wire.beginTransmission(8); // transmit to device #8
          Wire.write("H"); // sends one bytes.Servo Hermans head turns.
          Wire.endTransmission();
        }


        //Herman character turns on bonus player scores of
        if ((gameScore == 120) || (gameScore == 220))  {
          gameScore += 50;
          matrix.begin(0x71);
          matrix.print(gameScore, DEC);
          matrix.writeDisplay();


          Wire.beginTransmission(8); // transmit to device #8
          Wire.write("H"); // sends one bytes.Servo Hermans head turns.
          Wire.endTransmission();
        }
        //Monster Character turns on player score when 150 or 300
        if ((gameScore == 70) || (gameScore == 300))  {//Monster head character bonus
          gameScore += 60;
          // matrix.begin(0x71);
          matrix.print(gameScore, DEC);
          matrix.writeDisplay();

          Wire.beginTransmission(8); // transmit to device #8
          Wire.write("M"); // sends one bytes.Servo monster head turns.
          Wire.endTransmission();



        }
        if ((currentMillis - previousMillis >= interval) && (blinksLeft > 0))
        {
          // save the last time you blinked the LED
          previousMillis = currentMillis;
          // if the LED is off turn it on and vice-versa:
          if (ledState == LOW)
          {
            ledState = HIGH;
          }
          else
          {
            ledState = LOW;
            blinksLeft--; // one blink done
          }
          digitalWrite(blinkPin, ledState);
        }
       
     

      break;



    // *************************************GAME THREE *************************************************************************************************
    case 4:
      Serial.println("In case 4 game 3");

      //matrix.begin(0x71);
      matrix.print(gameScore, DEC);
      matrix.writeDisplay();
      if (digitalRead (47) == LOW) {

        gameScore = 0;
        state = 0;
        break;
      }


      if (gameScore >= 220) {
        digitalWrite ((49), LOW); //Turns off DC Motor Slow speed.
        digitalWrite ((50), HIGH);//Turns on DC motor High Speed,
      }
      //BREAK BEAM SENSOR SCORING
      if (digitalRead (25) == LOW) {
        while (digitalRead (25) == LOW);
        x = mySensVals[1];
        gameScore += x;
        // matrix.begin(0x71);
        matrix.print(gameScore, DEC);
        matrix.writeDisplay();
        if (x == 10) {
          pinMode (46, OUTPUT);
          digitalWrite ((46), LOW);//Activate Pin T05 on Sound Effects player.
          delay (150);
          pinMode (46, INPUT);

          digitalWrite(blinkPin, LOW);  // cancel any ongoing blinking
          blinksLeft = 3;  // start a series of blinks
          blinkPin = 42;  // new pin to blink
        }

        if (x == 20) {

          pinMode (45, OUTPUT);
          digitalWrite ((45), LOW);//Activate Pin T05 on Sound Effects player.
          delay (150);
          pinMode (45, INPUT);

          digitalWrite(blinkPin, LOW);  // cancel any ongoing blinking
          blinksLeft = 3;  // start a series of blinks
          blinkPin = 41;  // new pin to blink

        }
        if (x == 100) {
          pinMode (44, OUTPUT);
          digitalWrite ((44), LOW);//Activate Pin T05 on Sound Effects player.
          delay (150);
          pinMode (44, INPUT);

          digitalWrite(blinkPin, LOW);  // cancel any ongoing blinking
          blinksLeft = 3;  // start a series of blinks
          blinkPin = 39;  // new pin to blink

        }
        if (x == 5) {

          digitalWrite(blinkPin, LOW);  // cancel any ongoing blinking
          blinksLeft = 3;  // start a series of blinks
          blinkPin = 40;  // new pin to blink

          Wire.beginTransmission(8); // transmit to device #8
          Wire.write("M"); // sends one bytes.Servo monster head turns.
          Wire.endTransmission();

        }
        if ( x == 200) {
          digitalWrite(blinkPin, LOW);  // cancel any ongoing blinking
          blinksLeft = 3;  // start a series of blinks
          blinkPin = 43;  // new pin to blink

          Wire.beginTransmission(8); // transmit to device #8
          Wire.write("H"); // sends one bytes.Servo Hermans head turns.
          Wire.endTransmission();
        }

      }

      if (digitalRead (26) == LOW) {
        while (digitalRead (26) == LOW);
        x = mySensVals[2];
        gameScore += x;
        //matrix.begin(0x71);
        matrix.print(gameScore, DEC);
        matrix.writeDisplay();

        if (x == 10) {
          pinMode (46, OUTPUT);
          digitalWrite ((46), LOW);//Activate Pin T05 on Sound Effects player.
          delay (150);
          pinMode (46, INPUT);

          digitalWrite(blinkPin, LOW);  // cancel any ongoing blinking
          blinksLeft = 3;  // start a series of blinks
          blinkPin = 42;  // new pin to blink
        }

        if (x == 20) {

          pinMode (45, OUTPUT);
          digitalWrite ((45), LOW);//Activate Pin T05 on Sound Effects player.
          delay (150);
          pinMode (45, INPUT);
          digitalWrite(blinkPin, LOW);  // cancel any ongoing blinking pinMode (45, OUTPUT);

          blinksLeft = 3;  // start a series of blinks
          blinkPin = 41;  // new pin to blink

        }
        if (x == 100) {
          pinMode (44, OUTPUT);
          digitalWrite ((44), LOW);//Activate Pin T05 on Sound Effects player.
          delay (150);
          pinMode (44, INPUT);

          digitalWrite(blinkPin, LOW);  // cancel any ongoing blinking
          blinksLeft = 3;  // start a series of blinks
          blinkPin = 39;  // new pin to blink

        }
        if (x == 5) {
          digitalWrite(blinkPin, LOW);  // cancel any ongoing blinking
          blinksLeft = 3;  // start a series of blinks
          blinkPin = 40;  // new pin to blink


          Wire.beginTransmission(8); // transmit to device #8
          Wire.write("M"); // sends one bytes.Servo monster head turns.
          Wire.endTransmission();


        }
        if ( x == 200) {
          digitalWrite(blinkPin, LOW);  // cancel any ongoing blinking
          blinksLeft = 3;  // start a series of blinks
          blinkPin = 33;  // new pin to blink

          Wire.beginTransmission(8); // transmit to device #8
          Wire.write("H"); // sends one bytes.Servo Hermans head turns.
          Wire.endTransmission();
        }

      }

      if (digitalRead (27) == LOW)  {
        while (digitalRead (27) == LOW);
        x = mySensVals[3];
        gameScore += x;
        //matrix.begin(0x71);
        matrix.print(gameScore, DEC);
        matrix.writeDisplay();
        if (x == 10) {
          pinMode (46, OUTPUT);
          digitalWrite ((46), LOW);//Activate Pin T05 on Sound Effects player.
          delay (150);
          pinMode (46, INPUT);

          digitalWrite(blinkPin, LOW);  // cancel any ongoing blinking
          blinksLeft = 3;  // start a series of blinks
          blinkPin = 42;  // new pin to blink
        }
        if (x == 20) {
          pinMode (45, OUTPUT);
          digitalWrite ((45), LOW);//Activate Pin T05 on Sound Effects player.
          delay (150);
          pinMode (45, INPUT);

          digitalWrite(blinkPin, LOW);  // cancel any ongoing blinking
          blinksLeft = 3;  // start a series of blinks
          blinkPin = 41;  // new pin to blink

        }
        if (x == 100) {
          pinMode (44, OUTPUT);
          digitalWrite ((44), LOW);//Activate Pin T05 on Sound Effects player.
          delay (150);
          pinMode (44, INPUT);

          digitalWrite(blinkPin, LOW);  // cancel any ongoing blinking
          blinksLeft = 3;  // start a series of blinks
          blinkPin = 39;  // new pin to blink

        }
        if (x == 5) {
          digitalWrite(blinkPin, LOW);  // cancel any ongoing blinking
          blinksLeft = 3;  // start a series of blinks
          blinkPin = 40;  // new pin to blink


          Wire.beginTransmission(8); // transmit to device #8
          Wire.write("M"); // sends one bytes.Servo monster head turns.
          Wire.endTransmission();

        }
        if ( x == 200) {
          digitalWrite(blinkPin, LOW);  // cancel any ongoing blinking
          blinksLeft = 3;  // start a series of blinks
          blinkPin = 43;  // new pin to blink

          Wire.beginTransmission(8); // transmit to device #8
          Wire.write("H"); // sends one bytes.Servo Hermans head turns.
          Wire.endTransmission();
        }




      }

      if (digitalRead (28) == LOW) {
        while (digitalRead (28) == LOW);
        x = mySensVals[4];
        gameScore += x;
        // matrix.begin(0x71);
        matrix.print(gameScore, DEC);
        matrix.writeDisplay();

        if (x == 10) {
          pinMode (46, OUTPUT);
          digitalWrite ((46), LOW);//Activate Pin T05 on Sound Effects player.
          delay (150);
          pinMode (46, INPUT);

          digitalWrite(blinkPin, LOW);  // cancel any ongoing blinking
          blinksLeft = 3;  // start a series of blinks
          blinkPin = 42;  // new pin to blink
        }

        if (x == 20) {

          digitalWrite ((45), LOW);//Activate Pin T05 on Sound Effects player.
          delay (150);
          pinMode (45, INPUT);

          digitalWrite(blinkPin, LOW);  // cancel any ongoing blinking
          blinksLeft = 3;  // start a series of blinks
          blinkPin = 41;  // new pin to blink

        }
        if (x == 100) {
          pinMode (44, OUTPUT);
          digitalWrite ((44), LOW);//Activate Pin T05 on Sound Effects player.
          delay (150);
          pinMode (44, INPUT);

          digitalWrite(blinkPin, LOW);  // cancel any ongoing blinking
          blinksLeft = 3;  // start a series of blinks
          blinkPin = 39;  // new pin to blink

        }
        if (x == 5) {
          digitalWrite(blinkPin, LOW);  // cancel any ongoing blinking
          blinksLeft = 3;  // start a series of blinks
          blinkPin = 40;  // new pin to blink

          Wire.beginTransmission(8); // transmit to device #8
          Wire.write("M"); // sends one bytes.Servo monster head turns.
          Wire.endTransmission();

        }

        if ( x == 200) {
          digitalWrite(blinkPin, LOW);  // cancel any ongoing blinking
          blinksLeft = 3;  // start a series of blinks
          blinkPin = 43;  // new pin to blink

          Wire.beginTransmission(8); // transmit to device #8
          Wire.write("H"); // sends one bytes.Servo Hermans head turns.
          Wire.endTransmission();
        }

      }

      if (digitalRead (29) == LOW) {
        while (digitalRead (29) == LOW);
        x = mySensVals[5];
        gameScore += x;
        //matrix.begin(0x71);
        matrix.print(gameScore, DEC);
        matrix.writeDisplay();

        if (x == 10) {
          pinMode (46, OUTPUT);
          digitalWrite ((46), LOW);//Activate Pin T05 on Sound Effects player.
          delay (150);
          pinMode (46, INPUT);
          digitalWrite(blinkPin, LOW);  // cancel any ongoing blinking
          blinksLeft = 3;  // start a series of blinks
          blinkPin = 42;  // new pin to blink
        }

        if (x == 20) {

          digitalWrite ((45), LOW);//Activate Pin T05 on Sound Effects player.
          delay (150);
          pinMode (45, INPUT);
          digitalWrite(blinkPin, LOW);  // cancel any ongoing blinking
          blinksLeft = 3;  // start a series of blinks
          blinkPin = 41;  // new pin to blink

        }
        if (x == 100) {
          pinMode (44, OUTPUT);
          digitalWrite ((44), LOW);//Activate Pin T05 on Sound Effects player.
          delay (150);
          pinMode (44, INPUT);
          digitalWrite(blinkPin, LOW);  // cancel any ongoing blinking
          blinksLeft = 3;  // start a series of blinks
          blinkPin = 39;  // new pin to blink

        }
        if (x == 5) {
          digitalWrite(blinkPin, LOW);  // cancel any ongoing blinking
          blinksLeft = 3;  // start a series of blinks
          blinkPin = 40;  // new pin to blink

          Wire.beginTransmission(8); // transmit to device #8
          Wire.write("M"); // sends one bytes.Servo monster head turns.
          Wire.endTransmission();

        }

        if ( x == 200) {

          digitalWrite(blinkPin, LOW);  // cancel any ongoing blinking
          blinksLeft = 3;  // start a series of blinks
          blinkPin = 43;  // new pin to blink

          Wire.beginTransmission(8); // transmit to device #8
          Wire.write("H"); // sends one bytes.Servo Hermans head turns.
          Wire.endTransmission();
        }
      }


      if (digitalRead (30) == LOW) {
        while (digitalRead (30) == LOW);
        x = mySensVals[6];
        gameScore += x;
        //matrix.begin(0x71);
        matrix.print(gameScore, DEC);
        matrix.writeDisplay();

        if (x == 10) {
          pinMode (46, OUTPUT);
          digitalWrite ((46), LOW);//Activate Pin T05 on Sound Effects player.
          delay (150);
          pinMode (46, INPUT);

          digitalWrite(blinkPin, LOW);  // cancel any ongoing blinking
          blinksLeft = 3;  // start a series of blinks
          blinkPin = 42;  // new pin to blink
        }

        if (x == 20) {

          digitalWrite ((45), LOW);//Activate Pin T05 on Sound Effects player.
          delay (150);
          pinMode (45, INPUT);

          digitalWrite(blinkPin, LOW);  // cancel any ongoing blinking
          blinksLeft = 3;  // start a series of blinks
          blinkPin = 41;  // new pin to blink

        }

        if (x == 100) {
          pinMode (44, OUTPUT);
          digitalWrite ((43), LOW);//Activate Pin T05 on Sound Effects player.
          delay (150);
          pinMode (44, INPUT);

          digitalWrite(blinkPin, LOW);  // cancel any ongoing blinking
          blinksLeft = 3;  // start a series of blinks
          blinkPin = 39;  // new pin to blink

        }

        if (x == 5) {
          digitalWrite(blinkPin, LOW);  // cancel any ongoing blinking
          blinksLeft = 3;  // start a series of blinks
          blinkPin = 40;  // new pin to blink

          Wire.beginTransmission(8); // transmit to device #8
          Wire.write("M"); // sends one bytes.Servo monster head turns.
          Wire.endTransmission();

        }

        if ( x == 200) {
          digitalWrite(blinkPin, LOW);  // cancel any ongoing blinking
          blinksLeft = 3;  // start a series of blinks
          blinkPin = 43;  // new pin to blink



          Wire.beginTransmission(8); // transmit to device #8
          Wire.write("H"); // sends one bytes.Servo Hermans head turns.
          Wire.endTransmission();
        }

      }

      if (digitalRead (31) == LOW) {
        while (digitalRead (31) == LOW);
        x = mySensVals[7];
        gameScore += x;
        matrix.begin(0x71);
        matrix.print(gameScore, DEC);
        matrix.writeDisplay();

        if (x == 10) {
          pinMode (46, OUTPUT);
          digitalWrite ((46), LOW);//Activate Pin T05 on Sound Effects player.
          delay (150);
          pinMode (46, INPUT);

          digitalWrite(blinkPin, LOW);  // cancel any ongoing blinking
          blinksLeft = 3;  // start a series of blinks
          blinkPin = 42;  // new pin to blink
        }

        if (x == 20) {

          digitalWrite ((45), LOW);//Activate Pin T05 on Sound Effects player.
          delay (150);
          pinMode (45, INPUT);

          digitalWrite(blinkPin, LOW);  // cancel any ongoing blinking
          blinksLeft = 3;  // start a series of blinks
          blinkPin = 41;  // new pin to blink

        }
        if (x == 100) {
          pinMode (44, OUTPUT);
          digitalWrite ((43), LOW);//Activate Pin T05 on Sound Effects player.
          delay (150);
          pinMode (44, INPUT);
          digitalWrite ((43), LOW);//Turn pin off.

          digitalWrite(blinkPin, LOW);  // cancel any ongoing blinking
          blinksLeft = 3;  // start a series of blinks
          blinkPin = 39;  // new pin to blink

        }

        if (x == 5) {
          digitalWrite(blinkPin, LOW);  // cancel any ongoing blinking
          blinksLeft = 3;  // start a series of blinks
          blinkPin = 40;  // new pin to blink

          Wire.beginTransmission(8); // transmit to device #8
          Wire.write("M"); // sends one bytes.Servo monster head turns.
          Wire.endTransmission();

        }

        if ( x == 200) {
          digitalWrite(blinkPin, LOW);  // cancel any ongoing blinking
          blinksLeft = 3;  // start a series of blinks
          blinkPin = 43;  // new pin to blink

          Wire.beginTransmission(8); // transmit to device #8
          Wire.write("H"); // sends one bytes.Servo Hermans head turns.
          Wire.endTransmission();
        }
      }


      if (digitalRead (32) == LOW) {
        while (digitalRead (32) == LOW);
        x = mySensVals[8];
        gameScore += x;
        matrix.begin(0x71);
        matrix.print(gameScore, DEC);
        matrix.writeDisplay();

        if (x == 10) {
          pinMode (46, OUTPUT);
          digitalWrite ((46), LOW);//Activate Pin T05 on Sound Effects player.
          delay (150);
          pinMode (46, INPUT);

          digitalWrite(blinkPin, LOW);  // cancel any ongoing blinking
          blinksLeft = 3;  // start a series of blinks
          blinkPin = 42;  // new pin to blink
        }

        if (x == 20) {

          digitalWrite ((45), LOW);//Activate Pin T05 on Sound Effects player.
          delay (150);
          pinMode (45, INPUT);

          digitalWrite(blinkPin, LOW);  // cancel any ongoing blinking
          blinksLeft = 3;  // start a series of blinks
          blinkPin = 41;  // new pin to blink

        }
        if (x == 100) {
          pinMode (44, OUTPUT);
          digitalWrite ((44), LOW);//Activate Pin T05 on Sound Effects player.
          delay (150);
          pinMode (44, INPUT);

          digitalWrite(blinkPin, LOW);  // cancel any ongoing blinking
          blinksLeft = 3;  // start a series of blinks
          blinkPin = 39;  // new pin to blink

        }

        if (x == 5) {
          digitalWrite(blinkPin, LOW);  // cancel any ongoing blinking
          blinksLeft = 3;  // start a series of blinks
          blinkPin = 40;  // new pin to blink

          Wire.beginTransmission(8); // transmit to device #8
          Wire.write("M"); // sends one bytes.Servo monster head turns.
          Wire.endTransmission();

        }

        if ( x == 200) {
          digitalWrite(blinkPin, LOW);  // cancel any ongoing blinking
          blinksLeft = 3;  // start a series of blinks
          blinkPin = 43;  // new pin to blink

          Wire.beginTransmission(8); // transmit to device #8
          Wire.write("H"); // sends one bytes.Servo Hermans head turns.
          Wire.endTransmission();
        }


        //Herman character turns on bonus player scores of
        if ((gameScore == 120) || (gameScore == 220))  {
          gameScore += 50;
          //matrix.begin(0x71);
          matrix.print(gameScore, DEC);
          matrix.writeDisplay();

          Wire.beginTransmission(8); // transmit to device #8
          Wire.write("H"); // sends one bytes.Servo Hermans head turns.
          Wire.endTransmission();
        }
        //Monster Character turns on player score when 150 or 300
        if ((gameScore == 150) || (gameScore == 300))  {//Monster head character bonus
          gameScore += 60;
          //matrix.begin(0x71);
          matrix.print(gameScore, DEC);
          matrix.writeDisplay();


          Wire.beginTransmission(8); // transmit to device #8
          Wire.write("M"); // sends one bytes.Servo monster head turns.
          Wire.endTransmission();
        }
        if ((currentMillis - previousMillis >= interval) && (blinksLeft > 0))
        {
          // save the last time you blinked the LED
          previousMillis = currentMillis;
          // if the LED is off turn it on and vice-versa:
          if (ledState == LOW)
          {
            ledState = HIGH;
          }
          else
          {
            ledState = LOW;
            blinksLeft--; // one blink done
          }
          digitalWrite(blinkPin, ledState);
        }
        state = 4;
        break;
      }

      break;
  }
}

roadshark
 
Posts: 565
Joined: Sun Nov 29, 2015 5:53 am

Re: sound effect player connecting to arduino mega

by roadshark on Wed Nov 06, 2019 6:50 am

I moved the reading of pin 26 into the 0 case. When I start the program and hold the button down I see the 1 has changed to a 0 so the button is working. It is just that when the program is in a state and the button is pushed it is not registering:(((( I changed the display to non blinking in each state and altered the game score and both are changed when a game select button is pressed so the program is entering the states except it is disregarding all instructions. I am not even sure if it stays in the state like it should. If I refresh the serial monitor it reads it is in case 0. The program should only leave a state if directed to do so by the pressing of button on pin 47??

roadshark
 
Posts: 565
Joined: Sun Nov 29, 2015 5:53 am

Re: sound effect player connecting to arduino mega

by adafruit_support_bill on Wed Nov 06, 2019 7:25 am

I am not even sure if it stays in the state like it should. If I refresh the serial monitor it reads it is in case 0.

From the code, it looks like the only way to get back to case 0 is if pin 47 goes low.

You check the state of pin 47 in 3 places. Add a Serial.println statement to each of those 3 places so we can see when that code is executed. It is possible you have a short circuit somewhere that is pulling pin 47 low.

Code: Select all | TOGGLE FULL SIZE
        if (digitalRead (47) == LOW) {

          Serial.println("Reset Button Pressed!);
          gameScore = 0;
          state = 0;
          break;
        }

adafruit_support_bill
 
Posts: 75285
Joined: Sat Feb 07, 2009 10:11 am

Re: sound effect player connecting to arduino mega

by roadshark on Wed Nov 06, 2019 7:58 am

nothing comes up in the monitor about pin 47:)

roadshark
 
Posts: 565
Joined: Sun Nov 29, 2015 5:53 am

Re: sound effect player connecting to arduino mega

by adafruit_support_bill on Wed Nov 06, 2019 8:38 am

Can you post some of the serial output? I don't see any other way that the state would go back to zero.

adafruit_support_bill
 
Posts: 75285
Joined: Sat Feb 07, 2009 10:11 am

Re: sound effect player connecting to arduino mega

by roadshark on Thu Nov 07, 2019 3:31 am

Hi Bill, Here is the serial output. After I press 23 the serial displays stops.
In case 0 turn off motor
1
In case 1 selection of type of game played
In case 1 selection of type of game played
In case 1 selection of type of game played
In case 1 selection of type of game played
In case 1 selection of type of game played
In case 1 selection of type of game played
In case 1 selection of type of game played
In case 1 selection of type of game played
In case 1 selection of type of game played
In case 1 selection of type of game played
In case 1 selection of type of game played
moving to case 3In case 3 game 2
If I open the serial display again the following code appears. I do not press any buttons just the refresh icon in arduino program.
yIn case 0 turn off motor
1
In case 1 selection of type of game played
In case 1 selection of type of game played
In case 1 selection of type of game played
In case 1 selection of type of game played

roadshark
 
Posts: 565
Joined: Sun Nov 29, 2015 5:53 am

Re: sound effect player connecting to arduino mega

by adafruit_support_bill on Thu Nov 07, 2019 7:20 am

If I open the serial display again the following code appears.

OK. That makes more sense. Opening up the serial monitor causes a reset signal to be sent to the Arduino, so the program starts over at the beginning.

So I guess we are back to figuring out why the score is not updating for you.

Looking at case 2, you update the display at the beginning like this:
Code: Select all | TOGGLE FULL SIZE
      Serial.println("In case 2 game 1");

      //matrix.begin(0x71);
      matrix.print(gameScoreDefault, DEC);
      matrix.writeDisplay();


"gameScoreDefault" is initialized to 0 and never changes. I think you want to be displaying "gameScore" instead.

adafruit_support_bill
 
Posts: 75285
Joined: Sat Feb 07, 2009 10:11 am

Re: sound effect player connecting to arduino mega

by roadshark on Thu Nov 07, 2019 7:53 am

"gameScoreDefault" is initialized to 0 and never changes. I think you want to be displaying "gameScore" instead.

The reason for this Bill, is that game 1 is the game where the students have to add manually the score of the balls in the slots so I just keep the display reading 0. The only reasons the sensors are active and the 'gameScore' is updated but not displayed is to turn the servo's with the characters. In the other two games the score is shown to the students. In game one there is no sound either as some younger children get very scared of spooky type sounds so they have the option in game choice of choosing game one with no sounds:)

roadshark
 
Posts: 565
Joined: Sun Nov 29, 2015 5:53 am

Re: sound effect player connecting to arduino mega

by adafruit_support_bill on Thu Nov 07, 2019 8:02 am

OK. So the lack of scoring in Game 1 is intentional. Do the other functions in Game 1 work?

adafruit_support_bill
 
Posts: 75285
Joined: Sat Feb 07, 2009 10:11 am

Re: sound effect player connecting to arduino mega

by roadshark on Fri Nov 08, 2019 6:14 am

PROGRESS :) (I think a little bit.) I took out the pin in slot 47 and the buttons now work and update the score. Every thing in every game (Scoring/sound effects/lights ) is doing as instructed. However the issue is I now have no way to reset the game unless I turn the power on and off or press the reset key on the mega.
Code: Select all | TOGGLE FULL SIZE
if (digitalRead (47) == LOW) {

        Serial.println("Reset Button Pressed!");

        state = 0;
        break;
      }

I have tried changing the buttons with same result and in the code I changed pin 47 to 51. Again the program when in a game just loops back to case 0. It is like as soon as it reaches this part of the code it disregards the 'if' and sees 47 as low.
Any ideas??? Here is the updated code with the reset pin is now set to 51.
Code: Select all | TOGGLE FULL SIZE
#include <Adafruit_LEDBackpack.h>
#include <Wire.h>
Adafruit_7segment matrix = Adafruit_7segment();
#include <Servo.h>

Servo ballRelease;// create servo object to control a servo

int pos = 85;    // variable to store the servo position ball release
int gameScore = 0;//players score
int gameScoreDefault = 8888;
int sensorPins[] = {22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 51}; //Pin 22 = no scoring. Pin 23 = normal game. Pin 24 = Random scores    Pins(25, 26, 27, 28, 29, 30, 31, 32)= ball sensors
int sensorPinsCount = 12;
int mySensVals[] = {100, 5, 20, 10, 200, 20, 5, 100};//Values for the eight pins normal game.
int possibleValues[] = {100, 5, 20, 10, 200, 20, 5, 100};//Values for a random game.
int headLedPins[] = {33, 34, 35, 36, 37, 38};//LEDS FOR start up sequence
int headLedPinsCount = 6;
int scoreLedPins [] = {39, 40, 41, 42, 43};
int scoreLedPinsCount = 5;
int soundEffectActivationPin[] = {44, 45, 46, 48}; //sound effect player (44=100.  45= 20. 46 = 10   48= start up sound)
int soundEffectActivationPinCount = 4;
int state = 0;
int x = 0;


//Blinking SCORE LEDS
int ledState = LOW;             // ledState used to set the LED
unsigned long previousMillis = 0;        // will store last time LED was updated
const long interval = 500;           // interval at which to blink (milliseconds)
int blinksLeft = 0;  // set this variable any time you want to start a sequence of blinks
int blinkPin = 0;  // This is the pin number for the led to blink.

void setup() {
  Serial.begin(9600);
  Wire.begin ();
  matrix.begin(0x71);

  //ATTACH SEVOS TO PINS AND SET DEFAULT POSITION
  ballRelease.attach(9);
  ballRelease.write(pos);


  pinMode (49, OUTPUT);
  pinMode (50, OUTPUT);

  //Sets the reset button and break beam sensors pins to inputs.
  for (int thisPin = 0; thisPin < sensorPinsCount; thisPin++) {
    pinMode(sensorPins[thisPin], INPUT_PULLUP);
  }
  //Sets the sound effect activation pins to output.
  for (int thisPin = 0; thisPin  < soundEffectActivationPinCount; thisPin++) {
    pinMode(soundEffectActivationPin[thisPin], INPUT);
  }
  //sets the scoring LEDs pins to out put
  for (int thisPin = 0; thisPin  < scoreLedPinsCount; thisPin++) {
    pinMode(scoreLedPins[thisPin], OUTPUT);
  }
  //Sets the pins for the LEDS on MOVING HEAD  to output.
  for (int thisPin = 0; thisPin  < headLedPinsCount; thisPin++) {
    pinMode(headLedPins[thisPin], OUTPUT);
  }

}
void loop() {
  unsigned long currentMillis = millis();
  switch (state)

  {

    case 0:
      Serial.println("In case 0 turn off motor");

      //turns off the motor
      digitalWrite ((49), LOW);//Low_speed
      digitalWrite ((50), LOW);//High_speed

      matrix.blinkRate(2);
      gameScore = 0;
      matrix.print(gameScore, DEC);
      matrix.writeDisplay();

      state = 1;

      break;

    case 1:
      Serial.println("In case 1 selection of type of game played");

      if (digitalRead (22) == LOW) {
        matrix.blinkRate(0);

        for (int j = 0; j < 5; j++)//Start game light sequence
        {
          for (int i = 0; i < headLedPinsCount; i++)
          {
            digitalWrite(headLedPins[i], HIGH);
            delay(100);
            digitalWrite(headLedPins[i], LOW);
            delay (100);
          }
        }
        for (pos = 0; pos <= 85; pos += 5) { // goes from 0 degrees to 85 degrees in steps of 5 degree
          ballRelease.write(pos);              // tell servo to go to position in variable 'pos'
          delay(10);                       // waits 10ms for the servo to reach the position
        }
        delay (2500);//Gives time for the balls to roll down into catcher.
        for (pos = 85; pos >= 0; pos -= 3) { // goes from 85 degrees to 0 degrees
          ballRelease.write(pos);              // tell servo to go to position in variable 'pos'
          delay(10);// waits 10ms for the servo to reach the position

        }


        Serial.println("moving to case 2");
        state = 2;

        break;
      }


      if (digitalRead (23) == LOW) {
        matrix.blinkRate(0);

        pinMode (48, OUTPUT);
        digitalWrite ((48), LOW);//Activate start up sound
        delay (150);
        pinMode (48, INPUT);
        delay (250);

        for (int j = 0; j < 5; j++)//Start game light sequence
        {
          for (int i = 0; i < headLedPinsCount; i++)
          {
            digitalWrite(headLedPins[i], HIGH);
            delay(100);
            digitalWrite(headLedPins[i], LOW);
            delay (100);
          }
        }
        digitalWrite ((49), HIGH);//Low_speed

        for (pos = 0; pos <= 85; pos += 2) { // goes from 0 degrees to 120 degrees in steps of 1 degree
          ballRelease.write(pos);              // tell servo to go to position in variable 'pos'
          delay(15);                       // waits 15ms for the servo to reach the position
        }
        delay (2500);//Gives time for the balls to roll down into catcher.
        for (pos = 85; pos >= 0; pos -= 5) { // goes from 120 degrees to 0 degrees
          ballRelease.write(pos);              // tell servo to go to position in variable 'pos'
          delay(15);// waits 15ms for the servo to reach the position

        }



        Serial.print("moving to case 3");
        state = 3;
        break;
      }


      if (digitalRead (24) == LOW) {
        matrix.blinkRate(0);


        randomSeed(analogRead(A0));//initialize the random number generator with a fairly random input, pin AO
        for ( int i = 0; i < 8; i++) {
          mySensVals[i] = possibleValues[random(0, 7)];

        }

        pinMode (48, OUTPUT);
        digitalWrite ((48), LOW);//Activate start sound
        delay (150);
        pinMode (48, INPUT);

        for (int j = 0; j < 5; j++)//Start game light sequence
        {
          for (int i = 0; i < headLedPinsCount; i++)
          {
            digitalWrite(headLedPins[i], HIGH);
            delay(100);
            digitalWrite(headLedPins[i], LOW);
            delay (100);
          }
        }


        for (pos = 0; pos <= 85; pos += 5) { // goes from 0 degrees to 85 degrees in steps of 1 degree
          ballRelease.write(pos);              // tell servo to go to position in variable 'pos'
          delay(15);                       // waits 15ms for the servo to reach the position
        }
        delay (3500);//Gives time for the balls to roll down into catcher.
        for (pos = 85; pos >= 0; pos -= 3) { // goes from 120 degrees to 0 degrees
          ballRelease.write(pos);              // tell servo to go to position in variable 'pos'
          delay(15);// waits 15ms for the servo to reach the position

        }


        Serial.print("moving to case 4");
        state = 4;
        break;
      }

      break;//  Here the code loops until a button is pressed to exit this state.

    //***************************************GAME ONE NO SOUNDS AND NO DISPLAY****************************************************

    case 2:
      Serial.println("In case 2 game 1");
      digitalWrite ((49), HIGH);//Low_speed

      matrix.print(gameScoreDefault, DEC);
      matrix.writeDisplay();
      if (digitalRead (51) == LOW) {

        Serial.println("Reset Button Pressed!");

        state = 0;
        break;
      }
      if (gameScore >= 220) {
        digitalWrite ((49), LOW); //Turns off DC Motor Slow speed.
        digitalWrite ((50), HIGH);//Turns on DC motor High Speed,
      }
      //BREAK BEAM SENSOR SCORING
      if ((digitalRead (25) == LOW) || (digitalRead (32) == LOW)) {
        while ((digitalRead (25) == LOW) || (digitalRead (32) == LOW));
        gameScore += 100;

        digitalWrite(blinkPin, LOW);  // cancel any ongoing blinking
        blinksLeft = 3;  // start a series of blinks
        blinkPin = 39;  // new pin to blink

      }
      if ((digitalRead (26) == LOW) || (digitalRead (31) == LOW)) {
        while ((digitalRead (26) == LOW) || (digitalRead (31) == LOW));
        gameScore += 5;
        digitalWrite(blinkPin, LOW);  // cancel any ongoing blinking
        blinksLeft = 3;  // start a series of blinks
        blinkPin = 40;  // new pin to blink
        Wire.beginTransmission(8); // transmit to device #8
        Wire.write("M"); // sends one bytes.Servo monster head turns.
        Wire.endTransmission();
      }

      if ((digitalRead (27) == LOW) || (digitalRead (30) == LOW)) {
        while ((digitalRead (27) == LOW) || (digitalRead (30) == LOW));
        gameScore += 20;
        digitalWrite(blinkPin, LOW);  // cancel any ongoing blinking
        blinksLeft = 3;  // start a series of blinks
        blinkPin = 41;  // new pin to blink
      }
      if (digitalRead (28) == LOW) {
        while (digitalRead (28));
        gameScore += 10;
        digitalWrite(blinkPin, LOW);  // cancel any ongoing blinking
        blinksLeft = 3;  // start a series of blinks
        blinkPin = 42;  // new pin to blink
      }

      if (digitalRead (29) == LOW) {
        while (digitalRead (29));
        gameScore += 200;

        digitalWrite(blinkPin, LOW);  // cancel any ongoing blinking
        blinksLeft = 3;  // start a series of blinks
        blinkPin = 43;  // new pin to blink
        delay (1000);

        Wire.beginTransmission(8); // transmit to device #8
        Wire.write("H"); // sends one bytes.Servo monster head turns.
        Wire.endTransmission();

      }


      //Herman character turns on  player scores of
      if ((gameScore == 100) || (gameScore == 220))  {
        Wire.beginTransmission(8); // transmit to device #8
        Wire.write("H"); // sends one bytes.Servo Hermans head turns.
        Wire.endTransmission();
      }
      //Monster Character turns on player score when 150 or 300
      if ((gameScore == 150) || (gameScore == 300))  {//Monster head character bonus

        Wire.beginTransmission(8); // transmit to device #8
        Wire.write("M"); // sends one bytes.Servo monster head turns.
        Wire.endTransmission();

      }


      if ((currentMillis - previousMillis >= interval) && (blinksLeft > 0))
      {
        // save the last time you blinked the LED
        previousMillis = currentMillis;
        // if the LED is off turn it on and vice-versa:
        if (ledState == LOW)
        {
          ledState = HIGH;
        }
        else
        {
          ledState = LOW;
          blinksLeft--; // one blink done
        }
        digitalWrite(blinkPin, ledState);
      }
      //state = 2;
      break;




    //*********************************************GAME  TWO********************************************************************************************************************
    case 3:

      Serial.println("In case 3 game 2");
      digitalWrite ((49), HIGH);//Low_speed
      matrix.print(gameScore, DEC);
      matrix.writeDisplay();
      if (digitalRead (51) == LOW) {

        Serial.println("Reset Button Pressed!");

        state = 0;
        break;
      }


      if (gameScore >= 220) {
        digitalWrite ((49), LOW); //Turns off DC Motor Slow speed.
        digitalWrite ((50), HIGH);//Turns on DC motor High Speed,
      }

      if ((digitalRead (25) == LOW) || (digitalRead (32) == LOW)) {
        while ((digitalRead (25) == LOW) || (digitalRead (32) == LOW));
        gameScore += 100;
        matrix.print(gameScore, DEC);
        matrix.writeDisplay();
        pinMode (44, OUTPUT);
        digitalWrite ((44), LOW);//Activate Pin T05 on Sound Effects player.
        delay (150);
        pinMode (44, INPUT);
        digitalWrite(blinkPin, LOW);  // cancel any ongoing blinking
        blinksLeft = 3;  // start a series of blinks
        blinkPin = 39;  // new pin to blink

      }
      if ((digitalRead (26) == LOW) || (digitalRead (31) == LOW)) {
        while ((digitalRead (26) == LOW) || (digitalRead (31) == LOW));
        gameScore += 5;

        matrix.print(gameScore, DEC);
        matrix.writeDisplay();

        digitalWrite(blinkPin, LOW);  // cancel any ongoing blinking
        blinksLeft = 3;  // start a series of blinks
        blinkPin = 40;  // new pin to blink


        Wire.beginTransmission(8); // transmit to device #8
        Wire.write("M"); // sends one bytes.Servo monster head turns.
        Wire.endTransmission();



      }

      if ((digitalRead (27) == LOW) || (digitalRead (30) == LOW)) {
        while ((digitalRead (27) == LOW) || (digitalRead (30) == LOW));
        gameScore += 20;
        matrix.print(gameScore, DEC);
        matrix.writeDisplay();

        pinMode (45, OUTPUT);
        digitalWrite ((45), LOW);//Activate Pin T05 on Sound Effects player.
        delay (150);
        pinMode (45, INPUT);

        digitalWrite(blinkPin, LOW);  // cancel any ongoing blinking
        blinksLeft = 3;  // start a series of blinks
        blinkPin = 41;  // new pin to blink
      }

      if (digitalRead (28) == LOW) {
        while (digitalRead (28) == LOW);
        gameScore += 10;

        matrix.print(gameScore, DEC);
        matrix.writeDisplay();

        pinMode (46, OUTPUT);
        digitalWrite ((46), LOW);//Activate Pin T05 on Sound Effects player.
        delay (150);
        pinMode (46, INPUT);

        digitalWrite(blinkPin, LOW);  // cancel any ongoing blinking
        blinksLeft = 3;  // start a series of blinks
        blinkPin = 42;  // new pin to blink

      }

      if (digitalRead (29) == LOW) {
       
        while (digitalRead (29) == LOW);
        gameScore += 200;

        matrix.print(gameScore, DEC);
        matrix.writeDisplay();

        digitalWrite(blinkPin, LOW);  // cancel any ongoing blinking
        blinksLeft = 3;  // start a series of blinks
        blinkPin = 43;  // new pin to blink


        Wire.beginTransmission(8); // transmit to device #8
        Wire.write("H"); // sends one bytes.Servo Hermans head turns.
        Wire.endTransmission();
      }


      //Herman character turns on bonus player scores of
      if ((gameScore == 120) || (gameScore == 220))  {
        gameScore += 50;

        matrix.print(gameScore, DEC);
        matrix.writeDisplay();


        Wire.beginTransmission(8); // transmit to device #8
        Wire.write("H"); // sends one bytes.Servo Hermans head turns.
        Wire.endTransmission();
      }
      //Monster Character turns on player score when 150 or 300
      if ((gameScore == 70) || (gameScore == 300))  {//Monster head character bonus
        gameScore += 60;

        matrix.print(gameScore, DEC);
        matrix.writeDisplay();

        Wire.beginTransmission(8); // transmit to device #8
        Wire.write("M"); // sends one bytes.Servo monster head turns.
        Wire.endTransmission();



      }
      if ((currentMillis - previousMillis >= interval) && (blinksLeft > 0))
      {
        // save the last time you blinked the LED
        previousMillis = currentMillis;
        // if the LED is off turn it on and vice-versa:
        if (ledState == LOW)
        {
          ledState = HIGH;
        }
        else
        {
          ledState = LOW;
          blinksLeft--; // one blink done
        }
        digitalWrite(blinkPin, ledState);
      }



      break;



    // *************************************GAME THREE *************************************************************************************************
    case 4:
      Serial.println("In case 4 game 3");

      digitalWrite ((49), HIGH);//Low_speed
      matrix.print(gameScore, DEC);
      matrix.writeDisplay();
      if (digitalRead (51) == LOW) {

        Serial.println("Reset Button Pressed!");

        state = 0;
        break;
      }


      if (gameScore >= 220) {
        digitalWrite ((49), LOW); //Turns off DC Motor Slow speed.
        digitalWrite ((50), HIGH);//Turns on DC motor High Speed,
      }
      //BREAK BEAM SENSOR SCORING
      if (digitalRead (25) == LOW) {
        while (digitalRead (25) == LOW);
        x = mySensVals[1];
        gameScore += x;

        matrix.print(gameScore, DEC);
        matrix.writeDisplay();
        if (x == 10) {
          pinMode (46, OUTPUT);
          digitalWrite ((46), LOW);//Activate Pin T05 on Sound Effects player.
          delay (150);
          pinMode (46, INPUT);

          digitalWrite(blinkPin, LOW);  // cancel any ongoing blinking
          blinksLeft = 3;  // start a series of blinks
          blinkPin = 42;  // new pin to blink
        }

        if (x == 20) {

          pinMode (45, OUTPUT);
          digitalWrite ((45), LOW);//Activate Pin T05 on Sound Effects player.
          delay (150);
          pinMode (45, INPUT);

          digitalWrite(blinkPin, LOW);  // cancel any ongoing blinking
          blinksLeft = 3;  // start a series of blinks
          blinkPin = 41;  // new pin to blink

        }
        if (x == 100) {
          pinMode (44, OUTPUT);
          digitalWrite ((44), LOW);//Activate Pin T05 on Sound Effects player.
          delay (150);
          pinMode (44, INPUT);

          digitalWrite(blinkPin, LOW);  // cancel any ongoing blinking
          blinksLeft = 3;  // start a series of blinks
          blinkPin = 39;  // new pin to blink

        }
        if (x == 5) {

          digitalWrite(blinkPin, LOW);  // cancel any ongoing blinking
          blinksLeft = 3;  // start a series of blinks
          blinkPin = 40;  // new pin to blink

          Wire.beginTransmission(8); // transmit to device #8
          Wire.write("M"); // sends one bytes.Servo monster head turns.
          Wire.endTransmission();

        }
        if ( x == 200) {
          digitalWrite(blinkPin, LOW);  // cancel any ongoing blinking
          blinksLeft = 3;  // start a series of blinks
          blinkPin = 43;  // new pin to blink

          Wire.beginTransmission(8); // transmit to device #8
          Wire.write("H"); // sends one bytes.Servo Hermans head turns.
          Wire.endTransmission();
        }

      }

      if (digitalRead (26) == LOW) {
        while (digitalRead (26) == LOW);
        x = mySensVals[2];
        gameScore += x;

        matrix.print(gameScore, DEC);
        matrix.writeDisplay();

        if (x == 10) {
          pinMode (46, OUTPUT);
          digitalWrite ((46), LOW);//Activate Pin T05 on Sound Effects player.
          delay (150);
          pinMode (46, INPUT);

          digitalWrite(blinkPin, LOW);  // cancel any ongoing blinking
          blinksLeft = 3;  // start a series of blinks
          blinkPin = 42;  // new pin to blink
        }

        if (x == 20) {

          pinMode (45, OUTPUT);
          digitalWrite ((45), LOW);//Activate Pin T05 on Sound Effects player.
          delay (150);
          pinMode (45, INPUT);
          digitalWrite(blinkPin, LOW);  // cancel any ongoing blinking pinMode (45, OUTPUT);

          blinksLeft = 3;  // start a series of blinks
          blinkPin = 41;  // new pin to blink

        }
        if (x == 100) {
          pinMode (44, OUTPUT);
          digitalWrite ((44), LOW);//Activate Pin T05 on Sound Effects player.
          delay (150);
          pinMode (44, INPUT);

          digitalWrite(blinkPin, LOW);  // cancel any ongoing blinking
          blinksLeft = 3;  // start a series of blinks
          blinkPin = 39;  // new pin to blink

        }
        if (x == 5) {
          digitalWrite(blinkPin, LOW);  // cancel any ongoing blinking
          blinksLeft = 3;  // start a series of blinks
          blinkPin = 40;  // new pin to blink


          Wire.beginTransmission(8); // transmit to device #8
          Wire.write("M"); // sends one bytes.Servo monster head turns.
          Wire.endTransmission();


        }
        if ( x == 200) {
          digitalWrite(blinkPin, LOW);  // cancel any ongoing blinking
          blinksLeft = 3;  // start a series of blinks
          blinkPin = 33;  // new pin to blink

          Wire.beginTransmission(8); // transmit to device #8
          Wire.write("H"); // sends one bytes.Servo Hermans head turns.
          Wire.endTransmission();
        }

      }

      if (digitalRead (27) == LOW)  {
        while (digitalRead (27) == LOW);
        x = mySensVals[3];
        gameScore += x;

        matrix.print(gameScore, DEC);
        matrix.writeDisplay();
        if (x == 10) {
          pinMode (46, OUTPUT);
          digitalWrite ((46), LOW);//Activate Pin T05 on Sound Effects player.
          delay (150);
          pinMode (46, INPUT);

          digitalWrite(blinkPin, LOW);  // cancel any ongoing blinking
          blinksLeft = 3;  // start a series of blinks
          blinkPin = 42;  // new pin to blink
        }
        if (x == 20) {
          pinMode (45, OUTPUT);
          digitalWrite ((45), LOW);//Activate Pin T05 on Sound Effects player.
          delay (150);
          pinMode (45, INPUT);

          digitalWrite(blinkPin, LOW);  // cancel any ongoing blinking
          blinksLeft = 3;  // start a series of blinks
          blinkPin = 41;  // new pin to blink

        }
        if (x == 100) {
          pinMode (44, OUTPUT);
          digitalWrite ((44), LOW);//Activate Pin T05 on Sound Effects player.
          delay (150);
          pinMode (44, INPUT);

          digitalWrite(blinkPin, LOW);  // cancel any ongoing blinking
          blinksLeft = 3;  // start a series of blinks
          blinkPin = 39;  // new pin to blink

        }
        if (x == 5) {
          digitalWrite(blinkPin, LOW);  // cancel any ongoing blinking
          blinksLeft = 3;  // start a series of blinks
          blinkPin = 40;  // new pin to blink


          Wire.beginTransmission(8); // transmit to device #8
          Wire.write("M"); // sends one bytes.Servo monster head turns.
          Wire.endTransmission();

        }
        if ( x == 200) {
          digitalWrite(blinkPin, LOW);  // cancel any ongoing blinking
          blinksLeft = 3;  // start a series of blinks
          blinkPin = 43;  // new pin to blink

          Wire.beginTransmission(8); // transmit to device #8
          Wire.write("H"); // sends one bytes.Servo Hermans head turns.
          Wire.endTransmission();
        }




      }

      if (digitalRead (28) == LOW) {
        while (digitalRead (28) == LOW);
        x = mySensVals[4];
        gameScore += x;

        matrix.print(gameScore, DEC);
        matrix.writeDisplay();

        if (x == 10) {
          pinMode (46, OUTPUT);
          digitalWrite ((46), LOW);//Activate Pin T05 on Sound Effects player.
          delay (150);
          pinMode (46, INPUT);

          digitalWrite(blinkPin, LOW);  // cancel any ongoing blinking
          blinksLeft = 3;  // start a series of blinks
          blinkPin = 42;  // new pin to blink
        }

        if (x == 20) {

          digitalWrite ((45), LOW);//Activate Pin T05 on Sound Effects player.
          delay (150);
          pinMode (45, INPUT);

          digitalWrite(blinkPin, LOW);  // cancel any ongoing blinking
          blinksLeft = 3;  // start a series of blinks
          blinkPin = 41;  // new pin to blink

        }
        if (x == 100) {
          pinMode (44, OUTPUT);
          digitalWrite ((44), LOW);//Activate Pin T05 on Sound Effects player.
          delay (150);
          pinMode (44, INPUT);

          digitalWrite(blinkPin, LOW);  // cancel any ongoing blinking
          blinksLeft = 3;  // start a series of blinks
          blinkPin = 39;  // new pin to blink

        }
        if (x == 5) {
          digitalWrite(blinkPin, LOW);  // cancel any ongoing blinking
          blinksLeft = 3;  // start a series of blinks
          blinkPin = 40;  // new pin to blink

          Wire.beginTransmission(8); // transmit to device #8
          Wire.write("M"); // sends one bytes.Servo monster head turns.
          Wire.endTransmission();

        }

        if ( x == 200) {
          digitalWrite(blinkPin, LOW);  // cancel any ongoing blinking
          blinksLeft = 3;  // start a series of blinks
          blinkPin = 43;  // new pin to blink

          Wire.beginTransmission(8); // transmit to device #8
          Wire.write("H"); // sends one bytes.Servo Hermans head turns.
          Wire.endTransmission();
        }

      }

      if (digitalRead (29) == LOW) {
        while (digitalRead (29) == LOW);
        x = mySensVals[5];
        gameScore += x;

        matrix.print(gameScore, DEC);
        matrix.writeDisplay();

        if (x == 10) {
          pinMode (46, OUTPUT);
          digitalWrite ((46), LOW);//Activate Pin T05 on Sound Effects player.
          delay (150);
          pinMode (46, INPUT);
          digitalWrite(blinkPin, LOW);  // cancel any ongoing blinking
          blinksLeft = 3;  // start a series of blinks
          blinkPin = 42;  // new pin to blink
        }

        if (x == 20) {

          digitalWrite ((45), LOW);//Activate Pin T05 on Sound Effects player.
          delay (150);
          pinMode (45, INPUT);
          digitalWrite(blinkPin, LOW);  // cancel any ongoing blinking
          blinksLeft = 3;  // start a series of blinks
          blinkPin = 41;  // new pin to blink

        }
        if (x == 100) {
          pinMode (44, OUTPUT);
          digitalWrite ((44), LOW);//Activate Pin T05 on Sound Effects player.
          delay (150);
          pinMode (44, INPUT);
          digitalWrite(blinkPin, LOW);  // cancel any ongoing blinking
          blinksLeft = 3;  // start a series of blinks
          blinkPin = 39;  // new pin to blink

        }
        if (x == 5) {
          digitalWrite(blinkPin, LOW);  // cancel any ongoing blinking
          blinksLeft = 3;  // start a series of blinks
          blinkPin = 40;  // new pin to blink

          Wire.beginTransmission(8); // transmit to device #8
          Wire.write("M"); // sends one bytes.Servo monster head turns.
          Wire.endTransmission();

        }

        if ( x == 200) {

          digitalWrite(blinkPin, LOW);  // cancel any ongoing blinking
          blinksLeft = 3;  // start a series of blinks
          blinkPin = 43;  // new pin to blink

          Wire.beginTransmission(8); // transmit to device #8
          Wire.write("H"); // sends one bytes.Servo Hermans head turns.
          Wire.endTransmission();
        }
      }


      if (digitalRead (30) == LOW) {
        while (digitalRead (30) == LOW);
        x = mySensVals[6];
        gameScore += x;

        matrix.print(gameScore, DEC);
        matrix.writeDisplay();

        if (x == 10) {
          pinMode (46, OUTPUT);
          digitalWrite ((46), LOW);//Activate Pin T05 on Sound Effects player.
          delay (150);
          pinMode (46, INPUT);

          digitalWrite(blinkPin, LOW);  // cancel any ongoing blinking
          blinksLeft = 3;  // start a series of blinks
          blinkPin = 42;  // new pin to blink
        }

        if (x == 20) {

          digitalWrite ((45), LOW);//Activate Pin T05 on Sound Effects player.
          delay (150);
          pinMode (45, INPUT);

          digitalWrite(blinkPin, LOW);  // cancel any ongoing blinking
          blinksLeft = 3;  // start a series of blinks
          blinkPin = 41;  // new pin to blink

        }

        if (x == 100) {
          pinMode (44, OUTPUT);
          digitalWrite ((43), LOW);//Activate Pin T05 on Sound Effects player.
          delay (150);
          pinMode (44, INPUT);

          digitalWrite(blinkPin, LOW);  // cancel any ongoing blinking
          blinksLeft = 3;  // start a series of blinks
          blinkPin = 39;  // new pin to blink

        }

        if (x == 5) {
          digitalWrite(blinkPin, LOW);  // cancel any ongoing blinking
          blinksLeft = 3;  // start a series of blinks
          blinkPin = 40;  // new pin to blink

          Wire.beginTransmission(8); // transmit to device #8
          Wire.write("M"); // sends one bytes.Servo monster head turns.
          Wire.endTransmission();

        }

        if ( x == 200) {
          digitalWrite(blinkPin, LOW);  // cancel any ongoing blinking
          blinksLeft = 3;  // start a series of blinks
          blinkPin = 43;  // new pin to blink



          Wire.beginTransmission(8); // transmit to device #8
          Wire.write("H"); // sends one bytes.Servo Hermans head turns.
          Wire.endTransmission();
        }

      }

      if (digitalRead (31) == LOW) {
        while (digitalRead (31) == LOW);
        x = mySensVals[7];
        gameScore += x;

        matrix.print(gameScore, DEC);
        matrix.writeDisplay();

        if (x == 10) {
          pinMode (46, OUTPUT);
          digitalWrite ((46), LOW);//Activate Pin T05 on Sound Effects player.
          delay (150);
          pinMode (46, INPUT);

          digitalWrite(blinkPin, LOW);  // cancel any ongoing blinking
          blinksLeft = 3;  // start a series of blinks
          blinkPin = 42;  // new pin to blink
        }

        if (x == 20) {

          digitalWrite ((45), LOW);//Activate Pin T05 on Sound Effects player.
          delay (150);
          pinMode (45, INPUT);

          digitalWrite(blinkPin, LOW);  // cancel any ongoing blinking
          blinksLeft = 3;  // start a series of blinks
          blinkPin = 41;  // new pin to blink

        }
        if (x == 100) {
          pinMode (44, OUTPUT);
          digitalWrite ((43), LOW);//Activate Pin T05 on Sound Effects player.
          delay (150);
          pinMode (44, INPUT);
          digitalWrite ((43), LOW);//Turn pin off.

          digitalWrite(blinkPin, LOW);  // cancel any ongoing blinking
          blinksLeft = 3;  // start a series of blinks
          blinkPin = 39;  // new pin to blink

        }

        if (x == 5) {
          digitalWrite(blinkPin, LOW);  // cancel any ongoing blinking
          blinksLeft = 3;  // start a series of blinks
          blinkPin = 40;  // new pin to blink

          Wire.beginTransmission(8); // transmit to device #8
          Wire.write("M"); // sends one bytes.Servo monster head turns.
          Wire.endTransmission();

        }

        if ( x == 200) {
          digitalWrite(blinkPin, LOW);  // cancel any ongoing blinking
          blinksLeft = 3;  // start a series of blinks
          blinkPin = 43;  // new pin to blink

          Wire.beginTransmission(8); // transmit to device #8
          Wire.write("H"); // sends one bytes.Servo Hermans head turns.
          Wire.endTransmission();
        }
      }


      if (digitalRead (32) == LOW) {
        while (digitalRead (32) == LOW);
        x = mySensVals[8];
        gameScore += x;

        matrix.print(gameScore, DEC);
        matrix.writeDisplay();

        if (x == 10) {
          pinMode (46, OUTPUT);
          digitalWrite ((46), LOW);//Activate Pin T05 on Sound Effects player.
          delay (150);
          pinMode (46, INPUT);

          digitalWrite(blinkPin, LOW);  // cancel any ongoing blinking
          blinksLeft = 3;  // start a series of blinks
          blinkPin = 42;  // new pin to blink
        }

        if (x == 20) {

          digitalWrite ((45), LOW);//Activate Pin T05 on Sound Effects player.
          delay (150);
          pinMode (45, INPUT);

          digitalWrite(blinkPin, LOW);  // cancel any ongoing blinking
          blinksLeft = 3;  // start a series of blinks
          blinkPin = 41;  // new pin to blink

        }
        if (x == 100) {
          pinMode (44, OUTPUT);
          digitalWrite ((44), LOW);//Activate Pin T05 on Sound Effects player.
          delay (150);
          pinMode (44, INPUT);

          digitalWrite(blinkPin, LOW);  // cancel any ongoing blinking
          blinksLeft = 3;  // start a series of blinks
          blinkPin = 39;  // new pin to blink

        }

        if (x == 5) {
          digitalWrite(blinkPin, LOW);  // cancel any ongoing blinking
          blinksLeft = 3;  // start a series of blinks
          blinkPin = 40;  // new pin to blink

          Wire.beginTransmission(8); // transmit to device #8
          Wire.write("M"); // sends one bytes.Servo monster head turns.
          Wire.endTransmission();

        }

        if ( x == 200) {
          digitalWrite(blinkPin, LOW);  // cancel any ongoing blinking
          blinksLeft = 3;  // start a series of blinks
          blinkPin = 43;  // new pin to blink

          Wire.beginTransmission(8); // transmit to device #8
          Wire.write("H"); // sends one bytes.Servo Hermans head turns.
          Wire.endTransmission();
        }


        //Herman character turns on bonus player scores of
        if ((gameScore == 120) || (gameScore == 220))  {
          gameScore += 50;

          matrix.print(gameScore, DEC);
          matrix.writeDisplay();

          Wire.beginTransmission(8); // transmit to device #8
          Wire.write("H"); // sends one bytes.Servo Hermans head turns.
          Wire.endTransmission();
        }
        //Monster Character turns on player score when 150 or 300
        if ((gameScore == 150) || (gameScore == 300))  {//Monster head character bonus
          gameScore += 60;

          matrix.print(gameScore, DEC);
          matrix.writeDisplay();


          Wire.beginTransmission(8); // transmit to device #8
          Wire.write("M"); // sends one bytes.Servo monster head turns.
          Wire.endTransmission();
        }
        if ((currentMillis - previousMillis >= interval) && (blinksLeft > 0))
        {
          // save the last time you blinked the LED
          previousMillis = currentMillis;
          // if the LED is off turn it on and vice-versa:
          if (ledState == LOW)
          {
            ledState = HIGH;
          }
          else
          {
            ledState = LOW;
            blinksLeft--; // one blink done
          }
          digitalWrite(blinkPin, ledState);
        }
        state = 4;
        break;
      }

      break;
  }
}

I still have yet to connect the itsy and see if the serial communication works:)

roadshark
 
Posts: 565
Joined: Sun Nov 29, 2015 5:53 am

Re: sound effect player connecting to arduino mega

by adafruit_support_bill on Fri Nov 08, 2019 7:06 am

It sounds like the pullip on your reset pin is not working. Your logic to set all the input pullup pinmodes looks correct. But just to be sure, try adding an explicit pinmode for pin 51:

Code: Select all | TOGGLE FULL SIZE
  //Sets the reset button and break beam sensors pins to inputs.
  for (int thisPin = 0; thisPin < sensorPinsCount; thisPin++) {
    pinMode(sensorPins[thisPin], INPUT_PULLUP);
  }

  pinmode(51, INPUT_PULLUP);  // just to be sure!


Another option would be to attach your reset button to the RESET pin on the Mega. You should find that right next to the 3.3v pin. Pulling that LOW should be the same as pressing the reset button on the board.

adafruit_support_bill
 
Posts: 75285
Joined: Sat Feb 07, 2009 10:11 am

Re: sound effect player connecting to arduino mega

by roadshark on Fri Nov 08, 2019 7:49 am

That would be pinMode :) Tried that with same results. I have the slot 51 on the mega connected via a jumper lead attached to a momentary contact switch on a breadboard. If I remove the lead from the switch the program runs fine. As soon as I place the wire back into the switch the program goes back to case O with out pushing the button. This is a mystery as the switch is open so how is there a circuit???? I would like to try and crack the case?? If I comment out the reset code the game works fine.


You are correct about the reset pin. I would connect this to one side of a momentary contact switch and the other side of the switch to GND. Would I need to place a resistor in the wiring?

roadshark
 
Posts: 565
Joined: Sun Nov 29, 2015 5:53 am

Re: sound effect player connecting to arduino mega

by adafruit_support_bill on Fri Nov 08, 2019 9:30 am

If you post some photos of the switch wiring we'll see if we can spot any problems there.

No need for a pullup resistor on the reset pin. There is one on the board.

adafruit_support_bill
 
Posts: 75285
Joined: Sat Feb 07, 2009 10:11 am

Please be positive and constructive with your questions and comments.