Piezo buzzer and RePhone

Since tone() function doesn’t work on RePhone, this code could help

[code]#define buzzer 3

void setup(){
pinMode(buzzer, OUTPUT);
}
void loop(){
tone(buzzer, 1000, 1500);
delay(700);
tone(buzzer, 1000, 0);
delay(700);
}

void tone(uint8_t pin, unsigned long duration, unsigned int frequency)
{
long toggle = 0;
long Delay
;
boolean fHigh = false;

digitalWrite(pin, LOW);
toggle = 2 * frequency * duration / 1000;
Delay
= 800000L/(frequency * 2);

while (toggle–) {
fHigh = !fHigh;
digitalWrite(pin, fHigh? LOW : HIGH);
delayMicroseconds(Delay
);
}
digitalWrite(_pin, LOW);
}[/code]