Hi all, first time here =)
I’m EXTREMELLY noob with Arduino, just learning the basics by now so, please, sorry for stupid questions… but anyway, here is my problem:
I’m trying to make a simple thing here: With 2 speakers, I want to make one of them play a note… With a potenciometer, I’ll control the 2nd speaker and, when you get the same note of the 1st speaker, a LED lights.
The problem I’m having is that it seems that I can’t make both speakers play at the same time :~ … Using the same code, if I make one of them play, it works… changing the code to make just the other one plays, works fine as well… If I put both, just one of them is played.
I’m using Notes library
Here’s the code (sorry, it’s a shitty code, I’m still learning hehe :P):
#include <notes.h>
#define WLED 53 //a LED to light when you "tune"
#define BUZZ_1 8 //speaker where you try to "tune"
#define BUZZ_2 2 //speaker that plays the note you want to "tune"
#define KNOB 15 //the potenciometer
int nota;
void setup()
{
pinMode(KNOB, INPUT);
pinMode(WLED, OUTPUT);
pinMode(BTN, INPUT);
pinMode(BUZZ_1, OUTPUT);
pinMode(BUZZ_2, OUTPUT);
//to generate a random note
randomSeed(analogRead(0));
nota = random(1023);
//speaker 2 - I know it's probably in the wrong place, I'll comment later
tone(BUZZ_2, nota);
}
void loop()
{
int pot = analogRead(KNOB);
int mapPot = map(pot, 0,1023,0,1023); //this map is useless here, I'm just leaving it in case I want to make it easier or harder to find the right note)
//LED
if (mapPot >= nota-5 && mapPot <= nota+5) {
digitalWrite(WLED, HIGH);
}
else {
digitalWrite(WLED, LOW);
}
// speaker_1
tone(BUZZ_1, pot);
}
So, first both speakers lines [ tone(BUZZ_1, pot); and tone(BUZZ_2, nota); ] where in the loop, which I thought that might be the problem. I tried to put it out of the loop, but it didn’t work.
I’m supposing there is something wrong with my code… The connections are ok, since separately, the speakers work.
I’m using an Arduino Mega (ATmega 1280) and connecting one speaker in pwn 2 and the other in pwn 8…
Sorry again for stupid “grammar” on my code… Any help is OVERLY appreciated :D!