7 extern int64_t stop_tone_callback(alarm_id_t
id,
void *user_data);
22 static bool generate_sound_callback(repeating_timer_t *rt){
24 pt->state = !pt->state;
25 digitalWrite(pt->pin, pt->state);
29 void tone(uint8_t pinNumber,
unsigned int frequency) {
31 int delay = 1000 / frequency / 2;
32 alarm.start(generate_sound_callback, delay, MS,
this);
39 bool operator==(
const PicoTone& other){
40 return other.pin == this->pin;
43 bool operator!=(
const PicoTone& other){
44 return other.pin != this->pin;
61 static int64_t stop_tone_callback(alarm_id_t
id,
void *user_data){
69 static void tone(uint8_t pinNumber,
unsigned int frequency,
int duration) {
70 PicoTone ptone = pinMap().get(pinNumber);
71 if (ptone==empyTone()){
73 pinMap().put(pinNumber, ptone);
75 ptone.tone(pinNumber, frequency);
76 add_alarm_in_ms(duration, stop_tone_callback, &ptone ,
false);
80 static void noTone(uint8_t pinNumber) {
82 PicoTone ptone = pinMap().get(pinNumber);
83 if (ptone!=empyTone()){
96 return ArduinoPicoTonePinMap;
ArduinoPicoTone provides static methods for PicoTone.
Definition: PicoTone.h:59
A simple key value map collection.
Definition: Map.h:13
We use the TimerAlarmRepeating to generate tones.
Definition: PicoTone.h:13
Repeating Timer functions for simple scheduling of repeated execution.
Definition: PicoTimer.h:53