Tone may be suitable for this. I started to write my own very basic version, however for some reason my millis function isn't working now. I thought it was a problem with the timers, but I'm not using them now so I'm pretty confused as to why this is happening. My understanding is that millis is a built in method that should work out of the box? If the below works for you, I wonder if my Arduino is damaged?
unsigned long currentTimeStamp;
unsigned long serialLastWriteTimeStamp;
void setup()
{
Serial.begin(9600);
while (!Serial)
{
; // Wait for serial to connect
}
currentTimeStamp = millis();
serialLastWriteTimeStamp = millis();
Serial.print("currentTimeStamp: "); Serial.println(currentTimeStamp);
Serial.print("serialLastWriteTimeStamp: "); Serial.println(serialLastWriteTimeStamp);
Serial.print("currentTimeStamp - serialLastWriteTimeStamp: "); Serial.println(currentTimeStamp - serialLastWriteTimeStamp);
}
void loop() {
// put your main code here, to run repeatedly:
}