Hi, I'm new, please let me know if there's a better section to ask this question..
I've got an issue with an alarm i'm trying to make. It's using an arduino uno with a wave shield to play audio. Also hooked up to the Uno are two MAX7219 chips that are driving 2 8x8 LED matrix's. I got the wave shield working, audio plays through my speakers just fine. I also have both LED matrix's working perfectly. The only problem, they won't work at the same time.
This is some example code I'm using below, look for the "*"s.
//#include <FatReader.h>
//#include <SdReader.h>
//#include <avr/pgmspace.h>
//#include "WaveUtil.h"
#include "WaveHC.h"
#include "LedControl.h"
SdReader card;
FatVolume vol;
FatReader root;
FatReader f;
WaveHC wave;
LedControl lc=LedControl(8,7,6);
LedControl lc2=LedControl(13,12,11);
void setup() {
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
//*********************************************************
// the following 3 if statements is the code giving me issues. The only way to get the LED matrix's working is to comment out these three lines, and the only way to get the speaker working is to leave these lines how they are.
if (!card.init()) {return;}
if (!vol.init(card)) {return;}
if (!root.openRoot(vol)) {return;}
//*********************************************************
lc.shutdown(0,false);
lc.setIntensity(0,8);
lc.clearDisplay(0);
lc2.shutdown(0,false);
lc2.setIntensity(0,8);
lc2.clearDisplay(0);
}
void loop() {
playcomplete("hp1.WAV");
lc.setLed(0,2,3,true);
lc2.setLed(0,4,5,true);
}
void playcomplete(char *name) {
if (wave.isplaying) {wave.stop();}
if (!f.open(root, name)) {return;}
if (!wave.create(f)) {return;}
wave.play();
while (wave.isplaying) { }}
If that code is absolutely necessary, is there another way to get the LED matrix's working?
I have "playcomplete("hp1.WAV");" in my loop so it's saying the audio over and over without stopping. I just tried moving "playcomplete("hp1.WAV");" to another function so it wouldn't keep repeating:
Delta_G:
True if this is written for an UNO. Not a problem for a MEGA. But the OP has chosen to keep the board they are using a secret, which really hinders anyone's ability to give help on anything other than the code itself.
I updated my code so that the lights should be turned on from within the while (wave.isplaying) loop and I added a normal LED along with the 8x8 led matrix. Now when the audio is playing the LED lights up a small amount (should be bright..) and all the lights turn on on the led matrix instead of just 1...
I'm using an Uno.
If you have this device connected to pins 11, 12, and 13, you are not going to be able to use SPI to read from/write to the SD card.
I'm not sure I understand this, what is SPI and why can't I use it if I'm using pins 11, 12 and 13? Should I be using 3 other pins instead?
what is SPI and why can't I use it if I'm using pins 11, 12 and 13? Should I be using 3 other pins instead?
SPI is the Serial Peripheral Interface. It is the process that the Arduino uses to talk to serial peripheral devices, like the Ethernet shield, the WiFi shield, and SD cards. It is hardwired to pins 11, 12, and 13. So, yes, you should be using 3 other pins, instead.
Unfortunately I'm not having much luck with that either. I've trying hooking LedControl lc=LedControl up to 3 different digital pins and even 3 analog pins but I'm not getting any lights to come on on the led matrix. The normal LED blinks fine while audio plays but it's a faint light.
white (CS) goes to A5
green (CLK) goes to A4
orange (DIN) goes to A3
Red goes to v5
black to ground
and the led is on A0 ignore that random black wire under my arduino, it's not hooked up to anything..
This is the code I'm using to declare these pins:
LedControl lc=LedControl(A3,A4,A5);
digitalWrite(A0, HIGH);
Good call PaulS, I declared the single led as an output pin and got the led to light up bright. The LED matrix still isn't working however. I was only using the single LED as a test, i won't actually need to use that for the project, just the led matrix.
The only way I've been able to get the led matrix to work so far is by commenting out these lines:
If there a way to bascially undo what these lines are doing? I can't seem to find any documentation on the function calls for this library - init() and openRoot()..
How are you driving that speaker? Could that be dragging the power down?
The wave shield drives the speakers directly, though I'm not entirely sure how that works.. I plug in both cables from the speaker (vcc and ground) to my wave shield here: Imgur: The magic of the Internet
Why are there no Serial.print() statements to help debug the code?
What serial statements would you suggest? The default serial statements I had for debugging weren't helpful - It was printing all the correct information to the serial monitor.. Again the audio works without errors, just not along with the led matrix.
if (!card.init()) {return;}
Serial.print("Nospacesneededhere");
if (!vol.init(card)) {return;}
Serial.print("Letsputeverythingononelinetomakethecodehardtoread");
if (!root.openRoot(vol)) {return;}
Serial.print("root canal complete");
Then, you'd at least have a clue where the program is dying.