I’ve encountered a weird problem with an Arduino with this simple task. It involves just a buzzer and LED and a very simple custom library that I made.
I wanted the buzzer to sweep back and forth with a specified frequency range (f1, f2), the led will also display a specific brightness (0, 50) based on the frequency being played.
The buzzer works perfectly on its own, and also the LED, but when you put them together, it malfunctions.
**A more detailed explanation can be found here: https://tilarduino.wordpress.com/2015/11/27/weird-arduino-problem-buzzer-led-brightness/
And i've included all the files i've used here: https://gist.github.com/mithi/09ae419a3c7eba285221**
Using this code below, commenting out line 19 with line 18 uncommented-out will make the buzzer work, and commenting out line 19 with line 18 back in will make the led work as expected. But together, the code malfunctions. buzzer is attached to pin 13 and led is attached to pin 11.
#include "SimplestLibrary.h"
Sweeper sweeper;
Buzzer buzzer;
AnalogLED led;
int f1 = 3000;
int f2 = 4500;
int f = 0;
void setup() {
sweeper.New(f1, f2, BACKANDFORTH);
buzzer.New(13);
led.New(11);
}
void loop() {
f = sweeper.Update(1);
buzzer.Play(f, 4, 2);
led.NewBrightness(map(f, f1, f2, 0, 50));
delay(1);
}