Here is a tone function that does Arduino's tone()
The buzzer is connected between pin 6 and ground :
For some reason I get a sound when the program starts, in the parameters of the first tone line. I inserted a 1 sec delay to eliminate it.
The buzzer is connected between pin 6 and ground :
B4X:
Private Sub AppStart
Serial1.Initialize(115200)
Log("AppStart")
Delay( 1000)
tone( 6 , 500, 500)
Delay( 100)
tone( 6 , 750, 500)
Delay( 100)
tone( 6 , 1000, 500)
Delay( 100)
tone( 6 , 1500, 500)
End Sub
Sub tone(Pin As Byte, freq As Int, duration As ULong)
Dim sound As Pin
sound.Initialize(Pin,sound.MODE_OUTPUT)
Dim d As ULong = 500000/freq
Dim tnow As ULong = Micros
Do While Micros - tnow < duration * 1000
sound.digitalWrite(True)
DelayMicroseconds(d)
sound.digitalWrite(False)
DelayMicroseconds(d)
Loop
End Sub
For some reason I get a sound when the program starts, in the parameters of the first tone line. I inserted a 1 sec delay to eliminate it.
Last edited: