That worked! Played no problem. I tried to make the same edits to the pit droid sketch...but it's doesn't seem to work. I am probably missing something. I posted the original sketch for the Nano below and the edits I made to it underneath that. All I did was remove the SoftwareSerial.h and changed SoftwareSerial to Serial1. Thanks again for your help, I spent days racking over this...lol.
// This sketch was created by Dan Massey July 4_2021. It controls an Adafruit NeoPixel and
//a DF Player Mini to animate a Pit Droid. It also has a switch that can control the activity level of the sounds.
#include <Wire.h> // these two lines are loading libraries to operate the NeoPixels.
#include <Adafruit_NeoPixel.h>
#define PIN 7 //this is the pin on the Arduino that goes to the input of the first NeoPixel.
// Parameter 1 = number of pixels in strip
// Parameter 2 = Arduino pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
// NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
// NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products)
// NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
// NEO_RGBW Pixels are wired for RGBW bitstream (NeoPixel RGBW products)
Adafruit_NeoPixel strip = Adafruit_NeoPixel(12, 7, NEO_GRB + NEO_KHZ800); //the settings for the type of NeoPixel you are using (see 8 of the lines above).
// IMPORTANT: To reduce NeoPixel burnout risk, add 1000 uF capacitor across
// pixel power leads, add 300 - 500 Ohm resistor on first pixel's data input // these are things to remember to do if you are connecting to an actual Neopixel set.
// and minimize distance between Arduino and first pixel. Avoid connecting
// on a live circuit...if you must, connect GND first.
#include "SoftwareSerial.h"
#include "DFRobotDFPlayerMini.h"
// Use pins 2 and 3 to communicate with DFPlayer Mini
static const uint8_t PIN_MP3_TX = 2; // Connects to module's RX
static const uint8_t PIN_MP3_RX = 3; // Connects to module's TX
SoftwareSerial softwareSerial(PIN_MP3_RX, PIN_MP3_TX);
DFRobotDFPlayerMini player;// Create the DF Mini Player object
int numSongs = 31; //the number of tracks on the SD card
unsigned long lastMillis = 0; //Resets the time counter
int pirSensor = 8; // PIR Sensor is attached to pin 8
long eventInterval = 0;
int timer = 5000;//Time delay for the eye color to stay on
int track = random(1,numSongs+1);
int highActivityInput = 5; //variable to allow the trigger of high activity setting (connected to a switch)
void setup() {
strip.begin(); //starts the NeoPixel sketch
strip.show(); // Initialize all pixels to 'off'
softwareSerial.begin(9600);// Initialize serial port for DFPlayer Mini
player.begin(softwareSerial);//Begins serial communication
player.volume(30);// Set volume to maximum (0 to 30).
randomSeed(analogRead(A0));//Sets up a random number lottery
pinMode(pirSensor, INPUT);//Sets the PIR sensor as an input
pinMode (highActivityInput, INPUT);
}
void loop() {
boolean highSwitch = digitalRead (highActivityInput); //checks to see if the activity swtich is set to High (active)
if (highSwitch == true){ // if the high setting on the switch is turned on then then the time delay will be set to "Talk a Lot" mode:
eventInterval = 8000; //set this to a short time interval for "Talk a Lot" mode.
}
if (highSwitch == false){ // if the low setting on the switch is turned on then then the time delay will be set to normal time delay mode:
eventInterval = 60000; //set this to a longer time interval for "Normal" mode.
}
int sensorValue = digitalRead(pirSensor);//reads the PIR sensor value
if (sensorValue == 1 ) { //If the PIR sensor is triggered it will do the 2 functions below
playtrack(); //Plays audio selection if it hasn't already been triggered within the time limit selected
selectColor();//Chooses a random color for the eye
delay (timer); // The amount of time the eye color stays on
colorWipe(strip.Color(0, 0, 0), 300); // Resets all LEDs to off
}
}
// This function selects a random audio track from the SD card
void playtrack(){
unsigned long currentMillis = millis();
if(currentMillis - lastMillis > eventInterval){
int track = random(1,numSongs+1);
player.play(track);
lastMillis = currentMillis;
}
}
// This function selects a random color for the eye as well as a random intensity for the LEDs
void selectColor(){
int Red = random (0,255);
int Green = random (0,255);
int Blue = random (0,255);
colorWipe(strip.Color(Red, Green, Blue), 100);
}
// This function fills the dots one after the other with a color.
void colorWipe(uint32_t c, uint8_t wait) {
for(uint16_t i=0; i<strip.numPixels(); i++) {
strip.setPixelColor(i, c);
strip.show();
delay(0);
}
}
And here is my modification of the sketch based on your previous suggestion
// This sketch was created by Dan Massey July 4_2021. It controls an Adafruit NeoPixel and
//a DF Player Mini to animate a Pit Droid. It also has a switch that can control the activity level of the sounds.
#include <Wire.h> // these two lines are loading libraries to operate the NeoPixels.
#include <Adafruit_NeoPixel.h>
#define PIN 7 //this is the pin on the Arduino that goes to the input of the first NeoPixel.
// Parameter 1 = number of pixels in strip
// Parameter 2 = Arduino pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
// NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
// NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products)
// NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
// NEO_RGBW Pixels are wired for RGBW bitstream (NeoPixel RGBW products)
Adafruit_NeoPixel strip = Adafruit_NeoPixel(12, 7, NEO_GRB + NEO_KHZ800); //the settings for the type of NeoPixel you are using (see 8 of the lines above).
// IMPORTANT: To reduce NeoPixel burnout risk, add 1000 uF capacitor across
// pixel power leads, add 300 - 500 Ohm resistor on first pixel's data input // these are things to remember to do if you are connecting to an actual Neopixel set.
// and minimize distance between Arduino and first pixel. Avoid connecting
// on a live circuit...if you must, connect GND first.
#include "DFRobotDFPlayerMini.h"
DFRobotDFPlayerMini player;// Create the DF Mini Player object
int numSongs = 31; //the number of tracks on the SD card
unsigned long lastMillis = 0; //Resets the time counter
int pirSensor = 8; // PIR Sensor is attached to pin 8
long eventInterval = 0;
int timer = 5000;//Time delay for the eye color to stay on
int track = random(1,numSongs+1);
int highActivityInput = 5; //variable to allow the trigger of high activity setting (connected to a switch)
void setup() {
strip.begin(); //starts the NeoPixel sketch
strip.show(); // Initialize all pixels to 'off'
Serial1.begin(9600);// Initialize serial port for DFPlayer Mini
player.begin(Serial1);//Begins serial communication
player.volume(30);// Set volume to maximum (0 to 30).
randomSeed(analogRead(A0));//Sets up a random number lottery
pinMode(pirSensor, INPUT);//Sets the PIR sensor as an input
pinMode (highActivityInput, INPUT);
}
void loop() {
boolean highSwitch = digitalRead (highActivityInput); //checks to see if the activity swtich is set to High (active)
if (highSwitch == true){ // if the high setting on the switch is turned on then then the time delay will be set to "Talk a Lot" mode:
eventInterval = 8000; //set this to a short time interval for "Talk a Lot" mode.
}
if (highSwitch == false){ // if the low setting on the switch is turned on then then the time delay will be set to normal time delay mode:
eventInterval = 60000; //set this to a longer time interval for "Normal" mode.
}
int sensorValue = digitalRead(pirSensor);//reads the PIR sensor value
if (sensorValue == 1 ) { //If the PIR sensor is triggered it will do the 2 functions below
playtrack(); //Plays audio selection if it hasn't already been triggered within the time limit selected
selectColor();//Chooses a random color for the eye
delay (timer); // The amount of time the eye color stays on
colorWipe(strip.Color(0, 0, 0), 300); // Resets all LEDs to off
}
}
// This function selects a random audio track from the SD card
void playtrack(){
unsigned long currentMillis = millis();
if(currentMillis - lastMillis > eventInterval){
int track = random(1,numSongs+1);
player.play(track);
lastMillis = currentMillis;
}
}
// This function selects a random color for the eye as well as a random intensity for the LEDs
void selectColor(){
int Red = random (0,255);
int Green = random (0,255);
int Blue = random (0,255);
colorWipe(strip.Color(Red, Green, Blue), 100);
}
// This function fills the dots one after the other with a color.
void colorWipe(uint32_t c, uint8_t wait) {
for(uint16_t i=0; i<strip.numPixels(); i++) {
strip.setPixelColor(i, c);
strip.show();
delay(0);
}
}