0

Metro+Music Maker+Neopixel Sheild
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Metro+Music Maker+Neopixel Sheild

by Ecto1 on Wed Oct 10, 2018 8:59 pm

Is it possible to Stack all three things?
i have the wave shield in the middle as i wanted the pixels to show, the Pins are setup as the fallowing, i also have 4 RF buttons and 4 Relays so running low on pins

Code: Select all | TOGGLE FULL SIZE
// These are the pins used for the music maker shield
#define SHIELD_RESET  -1      // VS1053 reset pin (unused!)
#define SHIELD_CS     7      // VS1053 chip select pin (output)
#define SHIELD_DCS    6      // VS1053 Data/command select pin (output)

// These are common pins between breakout and shield
#define CARDCS 4     // Card chip select pin
// DREQ should be an Int pin, see http://arduino.cc/en/Reference/attachInterrupt
#define DREQ 3       // VS1053 Data request, ideally an Interrupt pin

Adafruit_VS1053_FilePlayer musicPlayer =
  Adafruit_VS1053_FilePlayer(SHIELD_RESET, SHIELD_CS, SHIELD_DCS, DREQ, CARDCS);
 
#define PIN A5
#define NUMPIXELS 40

//RLY
const int RLY1 = 10;
const int RLY2 = 11;
const int RLY3 = 12;
const int RLY4 = 13;

//Buttons
const int RFBUTTONA = A3;
const int RFBUTTONB = A2;
const int RFBUTTONC = A1;
const int RFBUTTOND = A0;


but this does not seem to be working
Last edited by Ecto1 on Thu Oct 11, 2018 8:24 pm, edited 1 time in total.

Ecto1
 
Posts: 13
Joined: Wed Sep 05, 2018 2:19 am

Re: Metro+Wave Sheild+Neopixel Sheild

by adafruit_support_bill on Thu Oct 11, 2018 5:47 am

The topic of the thread says "wave shield". But the code fragment posted seems to be for a VS1053. Please post the exact components you are using.

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

Re: Metro+Wave Sheild+Neopixel Sheild

by Ecto1 on Thu Oct 11, 2018 8:22 pm

oh I wonder if that's the issue lol

I have a Adafruit METRO 328 Fully Assembled - Arduino IDE compatible - ATmega328 on the bottom, then the Adafruit "Music Maker" MP3 Shield for Arduino w/3W Stereo Amp - v1.0 in the middle and then a Adafruit NeoPixel Shield for Arduino - 40 RGB LED Pixel Matrix on top

I a Simple RF M4 Receiver - 315MHz Momentary Type going to 4 pins
and then the 4 relays connected to a Particle Relay Shield for Photon

Ecto1
 
Posts: 13
Joined: Wed Sep 05, 2018 2:19 am

Re: Metro+Music Maker+Neopixel Sheild

by Ecto1 on Thu Oct 11, 2018 8:26 pm

here is the code I have

I want button D on the RF remote to start playing track001 and then if you press it again to stop it
Code: Select all | TOGGLE FULL SIZE
// include SPI, MP3 and SD libraries
#include <SPI.h>
#include <Adafruit_VS1053.h>
#include <SD.h>

// define the pins used
//#define CLK 13       // SPI Clock, shared with SD card
//#define MISO 12      // Input data, from VS1053/SD card
//#define MOSI 11      // Output data, to VS1053/SD card
// Connect CLK, MISO and MOSI to hardware SPI pins.
// See http://arduino.cc/en/Reference/SPI "Connections"

// These are the pins used for the breakout example
#define BREAKOUT_RESET  9      // VS1053 reset pin (output)
#define BREAKOUT_CS     10     // VS1053 chip select pin (output)
#define BREAKOUT_DCS    8      // VS1053 Data/command select pin (output)
// These are the pins used for the music maker shield
#define SHIELD_RESET  -1      // VS1053 reset pin (unused!)
#define SHIELD_CS     7      // VS1053 chip select pin (output)
#define SHIELD_DCS    6      // VS1053 Data/command select pin (output)

// These are common pins between breakout and shield
#define CARDCS 4     // Card chip select pin
// DREQ should be an Int pin, see http://arduino.cc/en/Reference/attachInterrupt
#define DREQ 3       // VS1053 Data request, ideally an Interrupt pin

Adafruit_VS1053_FilePlayer musicPlayer =
  // create breakout-example object!
  //Adafruit_VS1053_FilePlayer(BREAKOUT_RESET, BREAKOUT_CS, BREAKOUT_DCS, DREQ, CARDCS);
  // create shield-example object!
  Adafruit_VS1053_FilePlayer(SHIELD_RESET, SHIELD_CS, SHIELD_DCS, DREQ, CARDCS);
 
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
  #include <avr/power.h>
#endif

#define PIN A5
#define NUMPIXELS 40

//RLY
const int RLY1 = 10;
const int RLY2 = 11;
const int RLY3 = 12;
const int RLY4 = 13;

//Buttons
const int RFBUTTONA = A3;
const int RFBUTTONB = A2;
const int RFBUTTONC = A1;
const int RFBUTTOND = A0;

boolean once=false;

int RFBUTTONCPUSHCOUNTER = 0;   
int RFBUTTONCSTATE = 0;         
int RFBUTTONCLASTSTATE = 0;

int RFBUTTONDPUSHCOUNTER = 0;   
int RFBUTTONDSTATE = 0;         
int RFBUTTONDLASTSTATE = 0;

Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);

void setup() {
  for(int i=0;i<40;i++){
   pixels.setPixelColor(i, pixels.Color(255,0,175));
   pixels.show();

  #if defined (__AVR_ATtiny85__)
  if (F_CPU == 16000000) clock_prescale_set(clock_div_1);
#endif
 pixels.begin();
}

 Serial.begin(9600);
  Serial.println("Adafruit VS1053 Simple Test");

  if (! musicPlayer.begin()) { // initialise the music player
     Serial.println(F("Couldn't find VS1053, do you have the right pins defined?"));
     while (1);
  }
  Serial.println(F("VS1053 found"));
 
   if (!SD.begin(CARDCS)) {
    Serial.println(F("SD failed, or not present"));
    while (1);  // don't do anything more
  }
 
  // Set volume for left, right channels. lower numbers == louder volume!
  musicPlayer.setVolume(20,20);

  // Timer interrupts are not suggested, better to use DREQ interrupt!
  //musicPlayer.useInterrupt(VS1053_FILEPLAYER_TIMER0_INT); // timer int

  // If DREQ is on an interrupt pin (on uno, #2 or #3) we can do background
  // audio playing
  musicPlayer.useInterrupt(VS1053_FILEPLAYER_PIN_INT);  // DREQ int
 
  // Play one file, don't return until complete
  Serial.println(F("Playing track 002"));
  musicPlayer.startPlayingFile("track002.mp3");
  // Play another file in the background, REQUIRES interrupts!

 
  pinMode(RFBUTTONA, INPUT_PULLUP);
  pinMode(RFBUTTONB, INPUT_PULLUP);
  pinMode(RFBUTTONC, INPUT_PULLUP);
  pinMode(RFBUTTOND, INPUT_PULLUP);
  pinMode(RLY1, OUTPUT);
  pinMode(RLY2, OUTPUT);
  pinMode(RLY3, OUTPUT);
  pinMode(RLY4, OUTPUT);

delay(5000);
  for(int i=0;i<40;i++){
    pixels.setPixelColor(i, pixels.Color(0,0,0));
    pixels.show();
   
}
 }
void loop() {
  int RFBUTTONASTATE = 0;
  int RFBUTTONBSTATE = 0;
  int RFBUTTONCSTATE = 0;
  int RFBUTTONDSTATE = 0;
 
  RFBUTTONASTATE = digitalRead (RFBUTTONA);
  digitalWrite(RLY1, RFBUTTONASTATE);
  RFBUTTONBSTATE = digitalRead (RFBUTTONB);
  RFBUTTONCSTATE = digitalRead (RFBUTTONC);
  RFBUTTONDSTATE = digitalRead (RFBUTTOND);



if (RFBUTTONBSTATE == HIGH) {
    digitalWrite (RLY1,HIGH);
    delay(200);
    digitalWrite (RLY1,LOW);
    delay(1500);
    digitalWrite (RLY3,HIGH);
    delay(200);
    digitalWrite (RLY3,LOW);
    delay(1800);
    digitalWrite (RLY2,HIGH);
    delay(200);
    digitalWrite (RLY2,LOW);
    delay(1200);
    digitalWrite (RLY4,HIGH);
    delay(200);
    digitalWrite (RLY4,LOW);
    delay(1000);
    once=true; 
}
if (RFBUTTONCSTATE != RFBUTTONCLASTSTATE){
   if (RFBUTTONCSTATE == HIGH)
   {RFBUTTONCPUSHCOUNTER++;
      delay(50);}}
   RFBUTTONCLASTSTATE = RFBUTTONCSTATE;

   if (RFBUTTONCPUSHCOUNTER >= 5){
  RFBUTTONCPUSHCOUNTER=0;}


switch (RFBUTTONCPUSHCOUNTER) {
   case 0: for(int i=0;i<40;i++){
    pixels.setPixelColor(i, pixels.Color(0,0,0));
    pixels.show();}
    break;
   
   case 1:for(int i=0;i<40;i++){
    pixels.setPixelColor(i, pixels.Color(255,0,175));
    pixels.show();}
    break;
   
   case 2:for(int i=0;i<40;i++){
    pixels.setPixelColor(i, pixels.Color(0,255,0));
    pixels.show();}
    break;

   case 3:for(int i=0;i<40;i++){
    pixels.setPixelColor(i, pixels.Color(0,0,255));
    pixels.show();}
    break;

   case 4:for(int i=0;i<40;i++){
    pixels.setPixelColor(i, pixels.Color(255,0,0));
    pixels.show();}
    break;
}
if (RFBUTTONDSTATE != RFBUTTONDLASTSTATE){
   if (RFBUTTONDSTATE == HIGH)
   {RFBUTTONDPUSHCOUNTER++;
      delay(50);}}
   RFBUTTONDLASTSTATE = RFBUTTONDSTATE;

   if (RFBUTTONDPUSHCOUNTER >= 2){
  RFBUTTONDPUSHCOUNTER=0;}


switch (RFBUTTONCPUSHCOUNTER) {
   case 0: musicPlayer.startPlayingFile("track001.mp3");
    break;
   
   case 1: musicPlayer.stopPlaying();
    break;
}
}

Ecto1
 
Posts: 13
Joined: Wed Sep 05, 2018 2:19 am

Re: Metro+Music Maker+Neopixel Sheild

by Ecto1 on Thu Oct 11, 2018 8:26 pm

also when I send it to the Metro Relay 1 and 2 trigger when the program boots

Ecto1
 
Posts: 13
Joined: Wed Sep 05, 2018 2:19 am

Re: Metro+Music Maker+Neopixel Sheild

by adafruit_support_bill on Thu Oct 11, 2018 8:48 pm

OK. The Music Maker shield is based on the VS1053. It is a more powerful sound processor than the older Wave Shield.

However, it still has the same SPI interface to the SD card for storing sound files. This uses pins 11, 12 and 13 - which would conflict with the pins you are using for your relays.

For a full list of pins used by the shield, see this page of the guide:
https://learn.adafruit.com/adafruit-mus ... akouts-2-3

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

Re: Metro+Music Maker+Neopixel Sheild

by Ecto1 on Thu Oct 11, 2018 8:56 pm

ok so I fixed that up thanks for the help I think I miss read there so now when I press button D I want it to play the track001 and then when pressed again stop playing

here is what i have for the code

Code: Select all | TOGGLE FULL SIZE
// include SPI, MP3 and SD libraries
#include <SPI.h>
#include <Adafruit_VS1053.h>
#include <SD.h>

// define the pins used
#define CLK 13       // SPI Clock, shared with SD card
#define MISO 12      // Input data, from VS1053/SD card
#define MOSI 11      // Output data, to VS1053/SD card
//Connect CLK, MISO and MOSI to hardware SPI pins.
// See http://arduino.cc/en/Reference/SPI "Connections"

// These are the pins used for the music maker shield
#define SHIELD_RESET  -1      // VS1053 reset pin (unused!)
#define SHIELD_CS     7      // VS1053 chip select pin (output)
#define SHIELD_DCS    6      // VS1053 Data/command select pin (output)

// These are common pins between breakout and shield
#define CARDCS 4     // Card chip select pin
// DREQ should be an Int pin, see http://arduino.cc/en/Reference/attachInterrupt
#define DREQ 3       // VS1053 Data request, ideally an Interrupt pin

Adafruit_VS1053_FilePlayer musicPlayer =
  // create breakout-example object!
  //Adafruit_VS1053_FilePlayer(BREAKOUT_RESET, BREAKOUT_CS, BREAKOUT_DCS, DREQ, CARDCS);
  // create shield-example object!
  Adafruit_VS1053_FilePlayer(SHIELD_RESET, SHIELD_CS, SHIELD_DCS, DREQ, CARDCS);
 
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
  #include <avr/power.h>
#endif

#define PIN 10
#define NUMPIXELS 40

//RLY
const int RLY1 = 2;
const int RLY2 = 5;
const int RLY3 = A4;
const int RLY4 = A5;

//Buttons
const int RFBUTTONA = A3;
const int RFBUTTONB = A2;
const int RFBUTTONC = A1;
const int RFBUTTOND = A0;

boolean once=false;

int RFBUTTONCPUSHCOUNTER = 0;   
int RFBUTTONCSTATE = 0;         
int RFBUTTONCLASTSTATE = 0;

int RFBUTTONDPUSHCOUNTER = 0;   
int RFBUTTONDSTATE = 0;         
int RFBUTTONDLASTSTATE = 0;

Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);

void setup() {
  for(int i=0;i<40;i++){
   pixels.setPixelColor(i, pixels.Color(255,0,175));
   pixels.show();

  #if defined (__AVR_ATtiny85__)
  if (F_CPU == 16000000) clock_prescale_set(clock_div_1);
#endif
 pixels.begin();
}

 Serial.begin(9600);
  Serial.println("Adafruit VS1053 Simple Test");

  if (! musicPlayer.begin()) { // initialise the music player
     Serial.println(F("Couldn't find VS1053, do you have the right pins defined?"));
     while (1);
  }
  Serial.println(F("VS1053 found"));
 
   if (!SD.begin(CARDCS)) {
    Serial.println(F("SD failed, or not present"));
    while (1);  // don't do anything more
  }
 
  // Set volume for left, right channels. lower numbers == louder volume!
  musicPlayer.setVolume(20,20);

  // Timer interrupts are not suggested, better to use DREQ interrupt!
  //musicPlayer.useInterrupt(VS1053_FILEPLAYER_TIMER0_INT); // timer int

  // If DREQ is on an interrupt pin (on uno, #2 or #3) we can do background
  // audio playing
  musicPlayer.useInterrupt(VS1053_FILEPLAYER_PIN_INT);  // DREQ int
 
  // Play one file, don't return until complete
  Serial.println(F("Playing track 002"));
  musicPlayer.startPlayingFile("track002.mp3");
  // Play another file in the background, REQUIRES interrupts!

 
  pinMode(RFBUTTONA, INPUT_PULLUP);
  pinMode(RFBUTTONB, INPUT_PULLUP);
  pinMode(RFBUTTONC, INPUT_PULLUP);
  pinMode(RFBUTTOND, INPUT_PULLUP);
  pinMode(RLY1, OUTPUT);
  pinMode(RLY2, OUTPUT);
  pinMode(RLY3, OUTPUT);
  pinMode(RLY4, OUTPUT);

delay(5000);
  for(int i=0;i<40;i++){
    pixels.setPixelColor(i, pixels.Color(0,0,0));
    pixels.show();
   
}
 }
void loop() {
  int RFBUTTONASTATE = 0;
  int RFBUTTONBSTATE = 0;
  int RFBUTTONCSTATE = 0;
  int RFBUTTONDSTATE = 0;
 
  RFBUTTONASTATE = digitalRead (RFBUTTONA);
  digitalWrite(RLY1, RFBUTTONASTATE);
  RFBUTTONBSTATE = digitalRead (RFBUTTONB);
  RFBUTTONCSTATE = digitalRead (RFBUTTONC);
  RFBUTTONDSTATE = digitalRead (RFBUTTOND);



if (RFBUTTONBSTATE == HIGH) {
    digitalWrite (RLY1,HIGH);
    delay(200);
    digitalWrite (RLY1,LOW);
    delay(1500);
    digitalWrite (RLY3,HIGH);
    delay(200);
    digitalWrite (RLY3,LOW);
    delay(1800);
    digitalWrite (RLY2,HIGH);
    delay(200);
    digitalWrite (RLY2,LOW);
    delay(1200);
    digitalWrite (RLY4,HIGH);
    delay(200);
    digitalWrite (RLY4,LOW);
    delay(1000);
    once=true; 
}
if (RFBUTTONCSTATE != RFBUTTONCLASTSTATE){
   if (RFBUTTONCSTATE == HIGH)
   {RFBUTTONCPUSHCOUNTER++;
      delay(50);}}
   RFBUTTONCLASTSTATE = RFBUTTONCSTATE;

   if (RFBUTTONCPUSHCOUNTER >= 5){
  RFBUTTONCPUSHCOUNTER=0;}


switch (RFBUTTONCPUSHCOUNTER) {
   case 0: for(int i=0;i<40;i++){
    pixels.setPixelColor(i, pixels.Color(0,0,0));
    pixels.show();}
    break;
   
   case 1:for(int i=0;i<40;i++){
    pixels.setPixelColor(i, pixels.Color(255,0,175));
    pixels.show();}
    break;
   
   case 2:for(int i=0;i<40;i++){
    pixels.setPixelColor(i, pixels.Color(0,255,0));
    pixels.show();}
    break;

   case 3:for(int i=0;i<40;i++){
    pixels.setPixelColor(i, pixels.Color(0,0,255));
    pixels.show();}
    break;

   case 4:for(int i=0;i<40;i++){
    pixels.setPixelColor(i, pixels.Color(255,0,0));
    pixels.show();}
    break;
}
if (RFBUTTONDSTATE != RFBUTTONDLASTSTATE){
   if (RFBUTTONDSTATE == HIGH)
   {RFBUTTONDPUSHCOUNTER++;
      delay(50);}}
   RFBUTTONDLASTSTATE = RFBUTTONDSTATE;

   if (RFBUTTONDPUSHCOUNTER >= 2){
  RFBUTTONDPUSHCOUNTER=0;}


switch (RFBUTTONCPUSHCOUNTER) {
   case 0: musicPlayer.startPlayingFile("track001.mp3");
    break;
   
   case 1: musicPlayer.stopPlaying();
    break;
}
}

Ecto1
 
Posts: 13
Joined: Wed Sep 05, 2018 2:19 am

Re: Metro+Music Maker+Neopixel Sheild

by Ecto1 on Thu Oct 11, 2018 9:04 pm

the RF and Relays work fine like this the neopixels come up the pink like the start of the code says but they never go off like at the end of the Void Setup and nothing on button C controls it when stacked

Ecto1
 
Posts: 13
Joined: Wed Sep 05, 2018 2:19 am

Re: Metro+Music Maker+Neopixel Sheild

by Ecto1 on Thu Oct 11, 2018 10:29 pm

this is what I have for the RF button but it floods the serial a million times

Code: Select all | TOGGLE FULL SIZE
if (RFBUTTONDSTATE != RFBUTTONDLASTSTATE){
   if (RFBUTTONDSTATE == HIGH)
   {RFBUTTONDPUSHCOUNTER++;
      delay(50);}}
   RFBUTTONDLASTSTATE = RFBUTTONDSTATE;

   if (RFBUTTONDPUSHCOUNTER >= 2){
  RFBUTTONDPUSHCOUNTER=0;}


switch (RFBUTTONDPUSHCOUNTER) {
   case 0: musicPlayer.stopPlaying();
    break;
   
   case 1: Serial.println(F("Playing track 001"));
           musicPlayer.startPlayingFile("track001.mp3");
    break;
  }

Ecto1
 
Posts: 13
Joined: Wed Sep 05, 2018 2:19 am

Re: Metro+Music Maker+Neopixel Sheild

by adafruit_support_bill on Fri Oct 12, 2018 5:35 am

You need to move that switch/case statement inside your buttonstate test code. You don't want to execute that code unless the state of the button has changed.

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

Re: Metro+Music Maker+Neopixel Sheild

by Ecto1 on Fri Oct 12, 2018 11:42 am

    Ya lost me?

    Also are the commands correct?

    Ecto1
     
    Posts: 13
    Joined: Wed Sep 05, 2018 2:19 am

    Re: Metro+Music Maker+Neopixel Sheild

    by adafruit_support_bill on Fri Oct 12, 2018 12:10 pm

    The commands are correct, but the logic is wrong. You are sending commands on every iteration of the loop. You only want to send commands when the button is pressed.

    It is a LOT easier to understand the structure of your code if you indent consistently. What you want is something like this:

    Code: Select all | TOGGLE FULL SIZE
    if (RFBUTTONDSTATE != RFBUTTONDLASTSTATE)  // Look for a change in the button state
    {
       if (RFBUTTONDSTATE == HIGH) // Check to see if it is a button press
       {
          // The following code only gets executed on an actual button press event
          
          RFBUTTONDPUSHCOUNTER++;  // increment the counter
       
          if (RFBUTTONDPUSHCOUNTER >= 2)  // Counter must be 0 or 1
          {
             RFBUTTONDPUSHCOUNTER=0;
          }
          
          switch (RFBUTTONDPUSHCOUNTER)  // Handle the button press event.
          {
             case 0: musicPlayer.stopPlaying();
             break;

             case 1: Serial.println(F("Playing track 001"));
             musicPlayer.startPlayingFile("track001.mp3");
             break;
          }
       }
       RFBUTTONDLASTSTATE = RFBUTTONDSTATE;  // remember the current state for next time
       delay(50);  // some debounce time
    }

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

    Re: Metro+Music Maker+Neopixel Sheild

    by Ecto1 on Fri Oct 12, 2018 6:36 pm

    Sweet so everything is working great with the buttons the only thing is the LED is flickering when the music starts playing but stops when the music stops

    Ecto1
     
    Posts: 13
    Joined: Wed Sep 05, 2018 2:19 am

    Re: Metro+Music Maker+Neopixel Sheild

    by adafruit_support_bill on Fri Oct 12, 2018 9:14 pm

    Which led is flickering? If you post the code you have now, we can tale a look.

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

    Re: Metro+Music Maker+Neopixel Sheild

    by Ecto1 on Fri Oct 12, 2018 10:39 pm

    its all the LEDs on the shield

    Code: Select all | TOGGLE FULL SIZE
    // include SPI, MP3 and SD libraries
    #include <SPI.h>
    #include <Adafruit_VS1053.h>
    #include <SD.h>

    // define the pins used
    #define CLK 13       // SPI Clock, shared with SD card
    #define MISO 12      // Input data, from VS1053/SD card
    #define MOSI 11      // Output data, to VS1053/SD card
    //Connect CLK, MISO and MOSI to hardware SPI pins.
    // See http://arduino.cc/en/Reference/SPI "Connections"

    // These are the pins used for the music maker shield
    #define SHIELD_RESET  -1      // VS1053 reset pin (unused!)
    #define SHIELD_CS     7      // VS1053 chip select pin (output)
    #define SHIELD_DCS    6      // VS1053 Data/command select pin (output)

    // These are common pins between breakout and shield
    #define CARDCS 4     // Card chip select pin
    // DREQ should be an Int pin, see http://arduino.cc/en/Reference/attachInterrupt
    #define DREQ 3       // VS1053 Data request, ideally an Interrupt pin

    Adafruit_VS1053_FilePlayer musicPlayer =
      // create breakout-example object!
      //Adafruit_VS1053_FilePlayer(BREAKOUT_RESET, BREAKOUT_CS, BREAKOUT_DCS, DREQ, CARDCS);
      // create shield-example object!
      Adafruit_VS1053_FilePlayer(SHIELD_RESET, SHIELD_CS, SHIELD_DCS, DREQ, CARDCS);
     
    #include <Adafruit_NeoPixel.h>
    #ifdef __AVR__
      #include <avr/power.h>
    #endif

    #define PIN 8
    #define NUMPIXELS 40

    //RLY
    const int RLY1 = 2;
    const int RLY2 = 5;
    const int RLY3 = A4;
    const int RLY4 = A5;

    //Buttons
    const int RFBUTTONA = A3;
    const int RFBUTTONB = A2;
    const int RFBUTTONC = A1;
    const int RFBUTTOND = A0;

    boolean once=false;

    int RFBUTTONCPUSHCOUNTER = 0;   
    int RFBUTTONCSTATE = 0;         
    int RFBUTTONCLASTSTATE = 0;

    int RFBUTTONDPUSHCOUNTER = 0;   
    int RFBUTTONDSTATE = 0;         
    int RFBUTTONDLASTSTATE = 0;

    Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);

    void setup() {
      for(int i=0;i<40;i++){
       pixels.setPixelColor(i, pixels.Color(0,255,0));
       pixels.show();

         #if defined (__AVR_ATtiny85__)
      if (F_CPU == 16000000) clock_prescale_set(clock_div_1);
    #endif
     pixels.begin();
    }

    delay(1000);

     Serial.begin(9600);
      Serial.println("Ghostbusters 2 Toaster Program running");

      if (! musicPlayer.begin()) { // initialise the music player
         Serial.println(F("Couldn't find VS1053, do you have the right pins defined?"));
         while (1);
      }
      Serial.println(F("Soundcard Found and Online!!"));
     
       if (!SD.begin(CARDCS)) {
        Serial.println(F("SD failed, or not present"));
        while (1);  // don't do anything more
      }
     
      // Set volume for left, right channels. lower numbers == louder volume!
      musicPlayer.setVolume(5,5);

      // Timer interrupts are not suggested, better to use DREQ interrupt!
      //musicPlayer.useInterrupt(VS1053_FILEPLAYER_TIMER0_INT); // timer int

      // If DREQ is on an interrupt pin (on uno, #2 or #3) we can do background
      // audio playing
      musicPlayer.useInterrupt(VS1053_FILEPLAYER_PIN_INT);  // DREQ int
     
      // Play one file, don't return until complete
      Serial.println(F("Playing Normal_Toaster.MP3"));
      musicPlayer.startPlayingFile("Track002.mp3");
      // Play another file in the background, REQUIRES interrupts!

     
      pinMode(RFBUTTONA, INPUT_PULLUP);
      pinMode(RFBUTTONB, INPUT_PULLUP);
      pinMode(RFBUTTONC, INPUT_PULLUP);
      pinMode(RFBUTTOND, INPUT_PULLUP);
      pinMode(RLY1, OUTPUT);
      pinMode(RLY2, OUTPUT);
      pinMode(RLY3, OUTPUT);
      pinMode(RLY4, OUTPUT);

      for(int i=0;i<40;i++){
        pixels.setPixelColor(i, pixels.Color(0,0,255));
        pixels.show();
      }
    delay(6000);
      for(int i=0;i<40;i++){
        pixels.setPixelColor(i, pixels.Color(0,0,0));
        pixels.show();
       
    }
     }
    void loop() {
      int RFBUTTONASTATE = 0;
      int RFBUTTONBSTATE = 0;
      int RFBUTTONCSTATE = 0;
      int RFBUTTONDSTATE = 0;
     
      RFBUTTONASTATE = digitalRead (RFBUTTONA);
      digitalWrite(RLY1, RFBUTTONASTATE);
      RFBUTTONBSTATE = digitalRead (RFBUTTONB);
      RFBUTTONCSTATE = digitalRead (RFBUTTONC);
      RFBUTTONDSTATE = digitalRead (RFBUTTOND);



    if (RFBUTTONBSTATE == HIGH) {
        digitalWrite (RLY1,HIGH);
        delay(200);
        digitalWrite (RLY1,LOW);
        delay(1500);
        digitalWrite (RLY3,HIGH);
        delay(200);
        digitalWrite (RLY3,LOW);
        delay(1800);
        digitalWrite (RLY2,HIGH);
        delay(200);
        digitalWrite (RLY2,LOW);
        delay(1200);
        digitalWrite (RLY4,HIGH);
        delay(200);
        digitalWrite (RLY4,LOW);
        delay(1000);
        once=true; 
    }
    if (RFBUTTONCSTATE != RFBUTTONCLASTSTATE){
       if (RFBUTTONCSTATE == HIGH)
       {RFBUTTONCPUSHCOUNTER++;
          delay(50);}}
       RFBUTTONCLASTSTATE = RFBUTTONCSTATE;

       if (RFBUTTONCPUSHCOUNTER >= 5){
      RFBUTTONCPUSHCOUNTER=0;}


    switch (RFBUTTONCPUSHCOUNTER) {
       case 0: for(int i=0;i<40;i++){
        pixels.setPixelColor(i, pixels.Color(0,0,0));
        pixels.show();}
        break;
       
       case 1:for(int i=0;i<40;i++){
        pixels.setPixelColor(i, pixels.Color(255,0,175));
        pixels.show();}
        break;
       
       case 2:for(int i=0;i<40;i++){
        pixels.setPixelColor(i, pixels.Color(0,255,0));
        pixels.show();}
        break;

       case 3:for(int i=0;i<40;i++){
        pixels.setPixelColor(i, pixels.Color(0,0,255));
        pixels.show();}
        break;

       case 4:for(int i=0;i<40;i++){
        pixels.setPixelColor(i, pixels.Color(255,0,0));
        pixels.show();}
        break;
    }
    if (RFBUTTONDSTATE != RFBUTTONDLASTSTATE)  // Look for a change in the button state
    {
       if (RFBUTTONDSTATE == HIGH) // Check to see if it is a button press
       {
          // The following code only gets executed on an actual button press event
         
          RFBUTTONDPUSHCOUNTER++;  // increment the counter
       
          if (RFBUTTONDPUSHCOUNTER >= 2)  // Counter must be 0 or 1
          {
             RFBUTTONDPUSHCOUNTER=0;
          }
         
          switch (RFBUTTONDPUSHCOUNTER)  // Handle the button press event.
          {
             case 0: musicPlayer.stopPlaying();
             break;

             case 1: Serial.println(F("Playing track 001"));
             musicPlayer.startPlayingFile("track001.mp3");
             break;
          }
       }
       RFBUTTONDLASTSTATE = RFBUTTONDSTATE;  // remember the current state for next time
       delay(50);  // some debounce time
    }
    }

    Ecto1
     
    Posts: 13
    Joined: Wed Sep 05, 2018 2:19 am

    Please be positive and constructive with your questions and comments.