How to control melody with LDR

hello everyone i'm new here my problem is i want to control a melody by using LDR so when (ldr >300) the melody run else noTone .
how can i stop the melody immediately when the LDR sensor less then 300
to be clear the tone stop but after the fonction end
if there is any idea how the melody stop i'm apreciate to the help

The delay calls make the code not responsive. Use millis() timing instead of delay().

Non-blocking timing tutorials:
Blink without delay().
Beginner's guide to millis().
Several things at a time.

can you help me to solve it i didn't understand how to correct it
thank you

the purpose that i want is stop the melody when LDR less than 300 however the melody state

Why are you multiplying an int value with a floating point value?
What result are you expecting?
Use the Serial print to the monitor to find out what you really get.

this function is already exist on arduino library all you have to do is create the melody and duration

No.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.