Hello,
I have a project where we need to buzz a sound for a duration that's set via a potentiometer. Usually it's fairly easy with a delay function but here I need to use timer interrupts. I still can't figure out how they work and after some research i came up with this code.
It's not working as intended and i still can't understand how to change the interrupt frequency with an analogue signal coming from a potentiometer.
My general idea is:
digitalwrite(buzzer) is set to high, the timer interrupts it with the frequency in "bpm" setting digitalwrite(buzzer) to low. bpm is constantly read in the loop function and sets the according interrupt time.
Could anyone please help me with this project?
Thanks
Darn I have the perfect solution but I cannot tell you how to fix it, your schematic does not show that area. Post a complete schematic, not a frizzy drawing. Yes you must show all connections including power supplies. Also provide links to technical data on all the hardware items.
I don't have a schematic. The buzzing works with a normal code (without using interrupts). The red cable is connected to pin 13 and the black one to GND
Try a different pin, pin 13 has a led connected on the Arduino board. I am assuming you re using a UNO or Nano. You can see that in the Arduino schematic. Most of us draw our own schematics. Had you shown a schematic your problem would have been immediately visible. Remember when learning to draw schematics do it in baby steps and look at others and understand them. It is a whole new picture language.
"pin 13 has a led connected on the Arduino board" UNO DOES NOT HAVE AN LED CONNECTED - D13 drives an Op Amp that drives the LED.
Nano does have an LED directly connected.
""pin 13 has a led connected on the Arduino board" UNO DOES NOT HAVE AN LED CONNECTED - D13 drives an Op Amp that drives the LED." This is correct on REV 3 but not on previous versions. This leaves REV 3 currently unique. Since the Model and version information was not given I took the safe solution.
thanks, i tried with pin 7 but it still doesn't work, my idea is that the issue is not hardware related since i'm just trying to understand how interrupts work and how to control the interrupt frequency with a potentiometer.