Skip to content

Commit b6fd7f5

Browse files
author
Martin O'Hanlon
authored
Merge pull request #37 from RaspberryPiFoundation/dev
push to master to v0.0.1
2 parents 80281ec + fc965a3 commit b6fd7f5

File tree

4 files changed

+44
-13
lines changed

4 files changed

+44
-13
lines changed

README.rst

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,19 @@ A beginner-friendly library for using common electronics components with the Ras
1616
else:
1717
led.off()
1818
19-
Full documentation is available at `picozero.readthedocs.io <https://picozero.readthedocs.io>`_ :
19+
Status
20+
------
21+
22+
Pre-alpha - not yet for general release. Documentation is not yet available. There will be many bugs and issues.
23+
24+
Full documentation will be available at `picozero.readthedocs.io <https://picozero.readthedocs.io>`_ :
2025

2126
- `Installation and getting started guide <https://picozero.readthedocs.io/en/latest/gettingstarted.html>`_
2227
- `Recipes and how-to's <https://picozero.readthedocs.io/en/latest/recipes.html>`_
2328
- `API <https://picozero.readthedocs.io/en/latest/api.html>`_
2429

25-
picozero is inspired by `gpiozero <https://gpiozero.readthedocs.io/en/stable/>`_ (and reuses some of its underlying structure), but is by design lighter weight and aligned with the Raspberry Pi Pico.
30+
Notes
31+
-----
32+
33+
picozero is inspired by `gpiozero <https://gpiozero.readthedocs.io/en/stable/>`_ (and reuses some of its underlying structure), but is by design lighter weight and aligned with the Raspberry Pi Pico. Thank you to everyone who has contributed to the gpiozero project.
2634

docs/examples/speaker_midi_notes.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
from picozero import Speaker
2+
from time import sleep
3+
4+
speaker = Speaker(5)
5+
6+
BEAT = 0.25 # 240 BPM
7+
8+
dance = [[55, BEAT], ['', BEAT / 2], [55, BEAT], ['', BEAT / 2], [55, BEAT * 1.25], [55, BEAT], ['', BEAT / 2], [55, BEAT],
9+
[57, BEAT], ['', BEAT / 2], [57, BEAT], ['', BEAT / 2], [54, BEAT * 1.25], [54, BEAT], ['', BEAT / 2], [55, BEAT],
10+
[55, BEAT], [79, BEAT / 2], [55, BEAT], [79, BEAT / 2], [55, BEAT * 1.25], [55, BEAT], ['', BEAT / 2], [55, BEAT],
11+
[57, BEAT], [75, BEAT / 2], [57, BEAT], [75, BEAT / 2], [72, BEAT * 1.25], [56, BEAT], ['', BEAT / 2], [56, BEAT]]
12+
13+
try:
14+
speaker.play(dance)
15+
16+
finally: # Turn speaker off if interrupted
17+
speaker.off()

picozero/picozero.py

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -611,7 +611,7 @@ def volume(self):
611611
@volume.setter
612612
def volume(self, value):
613613
self._volume = value
614-
self.value = (self.freq, self._volume)
614+
self.value = (self.freq, self.volume)
615615

616616
@property
617617
def freq(self):
@@ -622,14 +622,16 @@ def freq(self):
622622

623623
@freq.setter
624624
def freq(self, freq):
625-
self._pwm_buzzer.freq(freq)
626-
625+
self.value = (freq, self.volume)
626+
627627
def _write(self, value):
628628
# set the frequency
629-
self._pwm_buzzer.freq = value[0]
629+
if value[0] is not None:
630+
self._pwm_buzzer.freq = value[0]
630631

631632
# write the volume value
632-
self._pwm_buzzer.volume = value[1]
633+
if value[1] is not None:
634+
self._pwm_buzzer.volume = value[1]
633635

634636
def _to_freq(self, freq):
635637
if freq is not None and freq != '' and freq != 0:
@@ -688,7 +690,7 @@ def play(self, tune=440, duration=1, volume=1, n=1, wait=True):
688690
+ a frequency in Hz e.g. `440`
689691
+ a midi note e.g. `60`
690692
+ a note name as a string e.g `"E4"`
691-
+ a list of single notes e.g. `[440, 60, "E4"]`
693+
+ a list of note and duration e.g. `[440, 1]` or `["E4", 2]`
692694
+ a list of 2 value tuples of (note, duration) e.g. `[(440,1), (60, 2), ("e4", 3)]`
693695
694696
Defaults to `440`.
@@ -712,10 +714,13 @@ def play(self, tune=440, duration=1, volume=1, n=1, wait=True):
712714
# tune isnt a list, so it must be a single frequency or note
713715
if not isinstance(tune, (list, tuple)):
714716
tune = [(tune, duration)]
717+
# if the first element isnt a list, then it must be list of a single note and duration
718+
elif not isinstance(tune[0], (list, tuple)):
719+
tune = [tune]
715720

716721
def tune_generator():
717722
for note in tune:
718-
723+
719724
# note isnt a list or tuple, it must be a single frequency or note
720725
if not isinstance(note, (list, tuple)):
721726
# make it into a tuple
@@ -724,12 +729,13 @@ def tune_generator():
724729
# turn the notes in frequencies
725730
freq = self._to_freq(note[0])
726731
freq_duration = note[1]
732+
freq_volume = volume if freq is not None else 0
727733

728734
# if this is a tune of greater than 1 note, add gaps between notes
729735
if len(tune) == 1:
730-
yield ((freq, volume), freq_duration)
736+
yield ((freq, freq_volume), freq_duration)
731737
else:
732-
yield ((freq, volume), freq_duration * 0.9)
738+
yield ((freq, freq_volume), freq_duration * 0.9)
733739
yield ((freq, 0), freq_duration * 0.1)
734740

735741
self._start_change(tune_generator, n, wait)

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22

33
__project__ = 'picozero'
44
__packages__ = ['picozero']
5-
__desc__ = 'A beginner-friendly library for using common electronics components with the Raspberry Pi Pico.'
5+
__desc__ = 'A beginner-friendly library for using common electronics components with the Raspberry Pi Pico. Not yet for general release.'
66
__version__ = '0.0.1'
77
__author__ = "Raspberry Pi Foundation"
88
__author_email__ = '[email protected]'
99
__license__ = 'MIT'
10-
__url__ = 'https://github.com/%3Cspan%20class="x x-first x-last">raspberrypilearning/picozero'
10+
__url__ = 'https://github.com/%3Cspan%20class="x x-first x-last">RaspberryPiFoundation/picozero'
1111
__keywords__ = [
1212
'raspberry',
1313
'pi',

0 commit comments

Comments
 (0)