36
36
__version__ = "0.0.0-auto.0"
37
37
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_CircuitPlayground.git"
38
38
39
-
40
39
class Photocell :
41
40
"""Simple driver for analog photocell on the Circuit Playground Express and Bluefruit."""
42
41
@@ -55,6 +54,8 @@ class CircuitPlaygroundBase: # pylint: disable=too-many-public-methods
55
54
"""Circuit Playground base class."""
56
55
57
56
_audio_out = None
57
+ SINE_WAVE = 0
58
+ SQUARE_WAVE = 1
58
59
59
60
def __init__ (self ):
60
61
# Define switch:
@@ -705,23 +706,23 @@ def _square_sample(length):
705
706
for _ in range (half_length ):
706
707
yield 0
707
708
708
- def _generate_sample (self , length = 100 , waveform = "sine" ):
709
+ def _generate_sample (self , length = 100 , waveform = SINE_WAVE ):
709
710
if self ._sample is not None :
710
711
return
711
- if waveform == "square" :
712
+ if waveform == self . SQUARE_WAVE :
712
713
self ._wave = array .array ("H" , self ._square_sample (length ))
713
714
else :
714
715
self ._wave = array .array ("H" , self ._sine_sample (length ))
715
716
self ._sample = self ._audio_out (board .SPEAKER ) # pylint: disable=not-callable
716
717
self ._wave_sample = audiocore .RawSample (self ._wave )
717
718
718
- def play_tone (self , frequency , duration , waveform = "sine" ):
719
+ def play_tone (self , frequency , duration , waveform = SINE_WAVE ):
719
720
"""Produce a tone using the speaker. Try changing frequency to change
720
721
the pitch of the tone.
721
722
722
723
:param int frequency: The frequency of the tone in Hz
723
724
:param float duration: The duration of the tone in seconds
724
- :param str waveform: Type of waveform to be generated [sine, square ]. Default = sine .
725
+ :param str waveform: Type of waveform to be generated [SINE_WAVE, SQUARE_WAVE ]. Default = SINE_WAVE .
725
726
726
727
.. image :: ../docs/_static/speaker.jpg
727
728
:alt: Onboard speaker
@@ -739,12 +740,12 @@ def play_tone(self, frequency, duration, waveform="sine"):
739
740
time .sleep (duration )
740
741
self .stop_tone ()
741
742
742
- def start_tone (self , frequency , waveform = "sine" ):
743
+ def start_tone (self , frequency , waveform = SINE_WAVE ):
743
744
"""Produce a tone using the speaker. Try changing frequency to change
744
745
the pitch of the tone.
745
746
746
747
:param int frequency: The frequency of the tone in Hz
747
- :param str waveform: Type of waveform to be generated [sine, square ]. Default = sine .
748
+ :param str waveform: Type of waveform to be generated [SINE_WAVE, SQUARE_WAVE ]. Default = SINE_WAVE .
748
749
749
750
.. image :: ../docs/_static/speaker.jpg
750
751
:alt: Onboard speaker
0 commit comments