Hi Arduino users out there in the Big World!
I need your help. I'm currently trying to make a DFPlayer to work, for that I started a very simple sketch I want to expand as I go along collecting more experience with this circuit.
Now this sketch returns with an error message I did not see before:
collect2.exe: error: ld returned 5 exit status
I managed to figure out that if I remove the following line from the sketch, the complilation does not give me trouble any more:
attachInterrupt(0, ISR_MainSwitchPressed, FALLING); // int.0 is the pin2 on the Nano board
The thing I do not understand it: I copied this line from a working, more complex sketch. So I do not know why it triggers the error.
Please kindly advice, I would really like to have this ISR in my code...
#include <stdlib.h>
//#include "DFPlayer_Mini_Mp3.h"
#include <SoftwareSerial.h>
SoftwareSerial mySerial(7, 8); // RX, TX
// Arduino Wire library is required if I2Cdev I2CDEV_ARDUINO_WIRE implementation
// is used in I2Cdev.h
#if I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE
#include "Wire.h"
#endif
const int momSwitch =2;
volatile int SwitchedOn=0; // state of the saber blade: True - on; False - off
volatile int PressMainSwitch; // ISR volatile variable to flag is main switch has been pushed
char buffer[4];
int received;
void ISR_MainSwitchPressed() {
// ISR to sense when the main switch has been pressed (so far press duration is not considered)
PressMainSwitch =1;
//if (SwitchedOn==0) {SwitchedOn=1} ;
//else if (SwitchedOn==1) {SwitchedOn=0};
}
// Collection of DFPlayer funcions from the DFPlayer_Mini_Mp3 library
extern uint8_t send_buf[10];
extern uint8_t recv_buf[10];
//calc checksum (1~6 byte)
uint16_t mp3_get_checksum (uint8_t *thebuf) {
uint16_t sum = 0;
for (int i=1; i<7; i++) {
sum += thebuf[i];
}
return -sum;
}
void setup() {
// put your setup code here, to run once:
// join I2C bus (I2Cdev library doesn't do this automatically)
#if I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE
Wire.begin();
#elif I2CDEV_IMPLEMENTATION == I2CDEV_BUILTIN_FASTWIRE
Fastwire::setup(400, true);
#endif
// define momentary switch
pinMode(momSwitch, INPUT_PULLUP); // set a digital pin as an input with pull-up used as a switch input
// initialize serial communication
// (38400 chosen because it works as well at 8MHz as it does at 16MHz, but
// it's really up to you depending on your project)
Serial.begin(9600);
received = 0;
buffer[received] = '\0';
// configure pins and set the data rate for the SoftwareSerial port
// these 2 pins will be used to communicate with the DFPlayer
pinMode(7,INPUT); //SS_RX
pinMode(8,OUTPUT); //SS_TX
mySerial.begin(9600);
SwitchedOn=0; // initialize saber state variable
// define Interrupt Service for main switch
attachInterrupt(0, ISR_MainSwitchPressed, FALLING); // int.0 is the pin2 on the Nano board
}
void loop() {
// put your main code here, to run repeatedly:
if (SwitchedOn==0 and PressMainSwitch==1) {
//IgniteSaber(true);
SwitchedOn = 1;
PressMainSwitch=0;
}
else if (SwitchedOn==1 and PressMainSwitch==1){
//RetractSaber();
SwitchedOn = 0;
PressMainSwitch=0;
}
if (SwitchedOn==1) {
//RandomFlicker(DriveStrengthHum,10,100);
//Flicker(DriveStrengthHum, 10, 5, 10);
}
}