greenhouse
Functions
Jukebox Namespace Reference

Functions

void play ()
 
void stop ()
 
bool is_playing ()
 

Function Documentation

◆ is_playing()

bool Jukebox::is_playing ( )

Definition at line 137 of file jukebox.cpp.

137  {
138  return isPlaying;
139 }
bool isPlaying
Definition: jukebox.cpp:8

References isPlaying.

Referenced by _button_handler().

Here is the caller graph for this function:

◆ play()

void Jukebox::play ( )

Definition at line 97 of file jukebox.cpp.

97  {
98  if (isPlaying) {
99  return;
100  }
101 
102  isPlaying = true;
103  buzzer.resume();
104 
105  const int songspeed = 1.5;
106  float result;
107  float bzz = 0.5;
108 
109  for (int i = 0; i < 203; i++) {
110  if (!isPlaying) {
111  stop();
112  }
113 
114  int w = duration[i] * songspeed;
115  if (notes[i] == 0) {
116  result = 1;
117  bzz = 0;
118  } else {
119  result = 1 / notes[i];
120  bzz = 0.4;
121  }
122 
123  buzzer.period(result);
124  buzzer.write(bzz);
125 
126  wait_us(w * 1000);
127  }
128 
129  buzzer.suspend();
130 }
int duration[]
Definition: jukebox.cpp:62
PwmOut buzzer(D3)
float notes[]
Definition: jukebox.cpp:25
void stop()
Definition: jukebox.cpp:132

References buzzer(), duration, isPlaying, notes, and stop().

Referenced by _button_handler().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ stop()

void Jukebox::stop ( )

Definition at line 132 of file jukebox.cpp.

132  {
133  buzzer.suspend();
134  isPlaying = false;
135 }

References buzzer(), and isPlaying.

Referenced by _button_handler(), and play().

Here is the call graph for this function:
Here is the caller graph for this function: