'My Arduino seems to just not function with my program, what can I do?
I've been working on a small lights and sounds system for a prop I've been building, nothing fancy, just blink some lights and play some sounds when a Switch is flipped.
I originally wrote the two programs separately so I knew each part of my circuit worked, the lights blinked, the sound effect was played from the MP3 module. I'm confident this is a code issue, as I had to make some modifications when adapting both programs into one big master program.
When this new program is flashed, nothing happens at all, the Arduino is on, everything is connected as it should be. I'm still quite new to Arduino's language; so I'm going to post the full code, because I'm honestly not sure where the problem may lie. EDIT: That shouldn't be pin 1 that's being checked by the IF statement, it should be 13, that was leftover from some troubleshooting which I clarified in a comment below.
#include "Arduino.h"
#include "SoftwareSerial.h"
#include "DFRobotDFPlayerMini.h"
SoftwareSerial mySoftwareSerial(10, 11); // RX, TX
DFRobotDFPlayerMini myDFPlayer;
void printDetail(uint8_t type, int value);
void setup() {
// put your setup code here, to run once:
/*This code is a work on progress and is
designed to provide lights and sounds for
a custom-modified Spirit Halloween Ghostbusters
Proton Pack*/
pinMode(6, OUTPUT); //Port for the Cyclotron Lights
pinMode(7, OUTPUT); //Port for the Cyclotron Lights
pinMode(5, OUTPUT); //Port for the Cyclotron Lights
pinMode(4, OUTPUT); //Port for the Cyclotron Lights
pinMode(12, OUTPUT); //Control Switch Input Voltage
pinMode(13, INPUT); //Control Switch Output Voltage
pinMode(9, OUTPUT); //Port for Blue Meter
mySoftwareSerial.begin(9600);
Serial.begin(115200);
/*Serial.println();
Serial.println(F("Starting Sound System"));
Serial.println(F("Initializing Player ... (May take 3~5 seconds)"));
if (!myDFPlayer.begin(mySoftwareSerial)) { //Use softwareSerial to communicate with
mp3.
Serial.println(F("Unable to begin:"));
Serial.println(F("1.Please recheck the connection!"));
Serial.println(F("2.Please insert the SD card!"));
while (true)
;
}
Serial.println(F("Player online."));
*/
myDFPlayer.setTimeOut(500); //Set serial communictaion time out 500ms
int switchCommand;
digitalWrite(12, HIGH);
switchCommand = digitalRead(13);
if (switchCommand == HIGH) {
//if switch command == 1, then the switch has been flicked and the cyclotron lights
should be working
//Serial.println(switchCommand);
myDFPlayer.volume(10); //Set volume value. From 0 to 30
myDFPlayer.play(1); //Play the first mp3
delay(400);
myDFPlayer.disableLoopAll(); //stop loop all mp3 files.
myDFPlayer.sleep(); //sleep
}
}
void loop() {
// put your main code here, to run repeatedly:
/* Here, in this part of the loop (for now)
* the code will cycle between ports 7, 6, 5,
* and 4, lighting up the Cyclotron lights for
* brief periods.
*/
int blueMeter = 9; // Blue Meter LEDs 1-4 will go here.
int lighting = 0; // Sets brightness of LEDs
int fadeQuantity = 5; //amount to fade LEDs
int switchCommand;
//int switchManager;
int loopStarter;
loopStarter = 1;
int i;
loopStarter = i;
digitalWrite(12, HIGH);
switchCommand = digitalRead(13);
if (switchCommand == HIGH) {
//if switch command == 1, then the switch has been flicked and the lights should be
working
//Serial.println(switchCommand);
for (int i = 1; i <= 4; i++) {
//set lighting of blueMeter
analogWrite(blueMeter, lighting);
//changing lighting
lighting = lighting + fadeQuantity;
// reverse the direction of the fading at the ends of the fade:
if (lighting <= 0 || lighting >= 255) {
fadeQuantity = -fadeQuantity;
}
// wait for 300 milliseconds to see the dimming effect
delay(300);
digitalWrite(6, HIGH);
delay(500);
digitalWrite(6, LOW);
delay(500);
digitalWrite(7, HIGH);
delay(500);
digitalWrite(7, LOW);
delay(500);
digitalWrite(5, HIGH);
delay(500);
digitalWrite(5, LOW);
delay(500);
digitalWrite(4, HIGH);
delay(500);
digitalWrite(4, LOW);
delay(500);
}
} }
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
