7 extern int64_t stop_tone_callback(alarm_id_t
id,
void *user_data);
24 static bool generate_sound_callback(repeating_timer_t *rt){
26 pt->state = !pt->state;
27 digitalWrite(pt->pin, pt->state);
31 void tone(uint8_t pinNumber,
unsigned int frequency) {
33 int delay = 1000 / frequency / 2;
34 alarm.start(generate_sound_callback, delay, MS,
this);
41 bool operator==(
const PicoTone& other){
42 return other.pin == this->pin;
45 bool operator!=(
const PicoTone& other){
46 return other.pin != this->pin;
63 static int64_t stop_tone_callback(alarm_id_t
id,
void *user_data){
71 static void tone(uint8_t pinNumber,
unsigned int frequency,
int duration) {
72 PicoTone ptone = pinMap().get(pinNumber);
73 if (ptone==empyTone()){
75 pinMap().put(pinNumber, ptone);
77 ptone.tone(pinNumber, frequency);
78 add_alarm_in_ms(duration, stop_tone_callback, &ptone ,
false);
82 static void noTone(uint8_t pinNumber) {
84 PicoTone ptone = pinMap().get(pinNumber);
85 if (ptone!=empyTone()){
98 return ArduinoPicoTonePinMap;
ArduinoPicoTone provides static methods for PicoTone.
Definition: PicoTone.h:61
A simple key value map collection.
Definition: Map.h:12
We use the TimerAlarmRepeating to generate tones.
Definition: PicoTone.h:15
Repeating Timer functions for simple scheduling of repeated execution.
Definition: PicoTimer.h:54