Hello, I am using an arduino MEGA 2560 with a sparkfun mp3 board. It is used to trigger several short audio samples. Along side the samples i want to blink some leds, using a pattern. The problem is the pattern is severly slowing down the reaction time of the samples. This is because i'm using a pattern with a couple of delay's.
I found the scheduler library and used it in my cade, to create a seperate loop for the led blinking. However the code won't compile anymore and i can't find a solution for the error.
These are the errors when i try to compile the code:
C:\Users\jochem\AppData\Local\Temp\cclOdtB7.s: Assembler messages:
C:\Users\jochem\AppData\Local\Temp\cclOdtB7.s:47: Error: constant value required
Anybody have an idea what i can do?
Any suggestions for another way to blink the leds without delaying the mp3 response is welcome.
//includes for sparkfun mp3 player
#include <SPI.h> // SPI library
#include <SdFat.h> // SDFat Library
#include <SdFatUtil.h> // SDFat Util Library
#include <SFEMP3Shield.h> // Mp3 Shield Library
#include <Scheduler.h> // om de led loop te scheiden van de audio loop
SdFat sd; // Create object to handle SD functions
SFEMP3Shield MP3player; // Create Mp3 library object
// These variables are used in the MP3 initialization to set up
// some stereo options:
const uint8_t volume = 0; // MP3 Player volume 0=max, 255=lowest (off)
const uint16_t monoMode = 1; // Mono setting 0=off, 3=max
//pin assignment for leds
const int RODELED = 14; //pin voor rode windmolen lamp
const int LEDHOOG = 39; //pin voor windkracht geluiden rode led
const int LEDMID = 41; //pin voor windkracht geluiden gele led
const int LEDLAAG = 43; //pin voor windkracht geluiden groene led
//pin assignment for controls
int potblink = A1; //potmeter for blink frequency
int valblink = 0; //variable to store read value
//pin assignment for sparkfun
#define TRIGGER_COUNT 11
int triggerPins[TRIGGER_COUNT] = {22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42};
int stopPin = 21; // This pin triggers a track stop.
int lastTrigger = 0; // This variable keeps track of which tune is playing
void setup(){
Scheduler.startLoop(loop2);
//set correct input/output status
pinMode(RODELED, OUTPUT);
pinMode(potblink, INPUT);
pinMode(LEDHOOG, OUTPUT);
pinMode(LEDMID, OUTPUT);
pinMode(LEDLAAG, OUTPUT);
// Set initial output states
digitalWrite(RODELED, LOW);
digitalWrite(LEDHOOG, LOW);
digitalWrite(LEDMID, LOW);
digitalWrite(LEDLAAG, LOW);
/* Set up all trigger pins as inputs, with pull-ups activated: */
for (int i=0; i<TRIGGER_COUNT; i++)
{
pinMode(triggerPins[i], INPUT_PULLUP);
}
pinMode(stopPin, INPUT_PULLUP);
initSD(); // Initialize the SD card
initMP3Player(); // Initialize the MP3 Shield
}
void loop()
{
// read status of blink pot and store
valblink = analogRead(potblink);
if (valblink > 800){
digitalWrite(RODELED, HIGH);
} else {
digitalWrite(RODELED, HIGH); //turn RODELED on with brightness of pot
delay(valblink); //wait for time determined by pot blink
digitalWrite(RODELED, LOW); //turn RODELED off for duration of pot blink
delay(valblink); //wait for time determined by pot blink
}
for (int i=0; i<TRIGGER_COUNT; i++)
{
if ((digitalRead(triggerPins[i]) == LOW) && ((i+1) != lastTrigger))
{
lastTrigger = i+1; // Update lastTrigger variable to current trigger
/* If another track is playing, stop it: */
if (MP3player.isPlaying())
MP3player.stopTrack();
/* Use the playTrack function to play a numbered track: */
uint8_t result = MP3player.playTrack(lastTrigger);
// An alternative here would be to use the
// playMP3(fileName) function, as long as you mapped
// the file names to trigger pins.
if (result == 0) // playTrack() returns 0 on success
{
// Success
}
else // Otherwise there's an error, check the code
{
// Print error code somehow, someway
}
}
}
// After looping through and checking trigger pins, check to
// see if the stopPin (A5) is triggered.
if (digitalRead(stopPin) == LOW)
{
lastTrigger = 0; // Reset lastTrigger
// If another track is playing, stop it.
if (MP3player.isPlaying())
MP3player.stopTrack();
}
}
void loop2()
{
digitalWrite(LEDHOOG, HIGH);
delay(2000);
digitalWrite(LEDHOOG, LOW);
digitalWrite(LEDLAAG, HIGH);
delay(3500);
digitalWrite(LEDLAAG, LOW);
delay(900);
digitalWrite(LEDMID, HIGH);
delay(1000);
digitalWrite(LEDMID, LOW);
delay(500);
digitalWrite(LEDMID, HIGH);
delay(1000);
digitalWrite(LEDMID, LOW);
delay(500);
digitalWrite(LEDMID, HIGH);
delay(1000);
digitalWrite(LEDMID, LOW);
delay(900);
digitalWrite(LEDHOOG, HIGH);
delay(2000);
digitalWrite(LEDHOOG, LOW);
digitalWrite(LEDHOOG, HIGH);
delay(2000);
digitalWrite(LEDHOOG, LOW);
digitalWrite(LEDLAAG, HIGH);
delay(2000);
digitalWrite(LEDLAAG, LOW);
yield();
}
// initSD() initializes the SD card and checks for an error.
void initSD()
{
//Initialize the SdCard.
if(!sd.begin(SD_SEL, SPI_HALF_SPEED))
sd.initErrorHalt();
if(!sd.chdir("/"))
sd.errorHalt("sd.chdir");
}
// initMP3Player() sets up all of the initialization for the
// MP3 Player Shield. It runs the begin() function, checks
// for errors, applies a patch if found, and sets the volume/
// stero mode.
void initMP3Player()
{
uint8_t result = MP3player.begin(); // init the mp3 player shield
if(result != 0) // check result, see readme for error codes.
{
// Error checking can go here!
}
MP3player.setVolume(volume, volume);
MP3player.setMonoMode(monoMode);
}