@@ -82,6 +82,9 @@ def _get_value(self):
82
82
return next (self ._gen )
83
83
84
84
def stop (self ):
85
+ """
86
+ Stops the ValueChange object running.
87
+ """
85
88
self ._running = False
86
89
self ._timer .deinit ()
87
90
@@ -259,6 +262,28 @@ class Buzzer(DigitalOutputDevice):
259
262
Buzzer .beep = Buzzer .blink
260
263
261
264
class PWMOutputDevice (OutputDevice ):
265
+ """
266
+ Represents a device driven by a PWM pin.
267
+
268
+ :param int pin:
269
+ The pin that the device is connected to.
270
+
271
+ :param int freq:
272
+ The frequency of the PWM signal in Hertz. Defaults to 100.
273
+
274
+ :param int duty_factor:
275
+ The duty factor of the PWM signal. This is a value between 0 and 65535.
276
+ Defaults to 65535.
277
+
278
+ :param bool active_high:
279
+ If :data:`True` (the default), the :meth:`on` method will set the Pin
280
+ to HIGH. If :data:`False`, the :meth:`on` method will set the Pin to
281
+ LOW (the :meth:`off` method always does the opposite).
282
+
283
+ :param bool initial_value:
284
+ If :data:`False` (the default), the LED will be off initially. If
285
+ :data:`True`, the LED will be switched on initially.
286
+ """
262
287
263
288
PIN_TO_PWM_CHANNEL = ["0A" ,"0B" ,"1A" ,"1B" ,"2A" ,"2B" ,"3A" ,"3B" ,"4A" ,"4B" ,"5A" ,"5B" ,"6A" ,"6B" ,"7A" ,"7B" ,"0A" ,"0B" ,"1A" ,"1B" ,"2A" ,"2B" ,"3A" ,"3B" ,"4A" ,"4B" ,"5A" ,"5B" ,"6A" ,"6B" ]
264
289
_channels_used = {}
@@ -418,6 +443,13 @@ class PWMLED(PWMOutputDevice):
418
443
:param int pin:
419
444
The pin that the device is connected to.
420
445
446
+ :param int freq:
447
+ The frequency of the PWM signal in Hertz. Defaults to 100.
448
+
449
+ :param int duty_factor:
450
+ The duty factor of the PWM signal. This is a value between 0 and 65535.
451
+ Defaults to 65535.
452
+
421
453
:param bool active_high:
422
454
If :data:`True` (the default), the :meth:`on` method will set the Pin
423
455
to HIGH. If :data:`False`, the :meth:`on` method will set the Pin to
@@ -478,21 +510,53 @@ class PWMBuzzer(PWMOutputDevice):
478
510
Represents a passive buzzer driven by a PWM pin whose volume can be changed.
479
511
480
512
:param int pin:
481
- The pin that the device is connected to.
513
+ The pin that the buzzer is connected to.
514
+
515
+ :param int freq:
516
+ The frequency of the PWM signal in Hertz. Defaults to 440.
517
+
518
+ :param int duty_factor:
519
+ The duty factor of the PWM signal. This is a value between 0 and 65535.
520
+ Defaults to 1023.
482
521
483
522
:param bool active_high:
484
523
If :data:`True` (the default), the :meth:`on` method will set the Pin
485
524
to HIGH. If :data:`False`, the :meth:`on` method will set the Pin to
486
525
LOW (the :meth:`off` method always does the opposite).
487
526
488
527
:param bool initial_value:
489
- If :data:`False` (the default), the buzzer will be off initially. If
490
- :data:`True`, the buzzer will be switched on initially.
491
- """
528
+ If :data:`False` (the default), the Buzzer will be off initially. If
529
+ :data:`True`, the Buzzer will be switched on initially.
530
+ """
531
+ def __init__ (self , pin , freq = 440 , duty_factor = 1023 , active_high = True , initial_value = False ):
532
+ super ().__init__ (pin , freq , duty_factor , active_high , initial_value )
533
+
492
534
PWMBuzzer .volume = PWMBuzzer .value
493
535
PWMBuzzer .beep = PWMBuzzer .blink
494
536
495
537
class Speaker (OutputDevice ):
538
+ """
539
+ Represents a speaker driven by a PWM pin.
540
+
541
+ :param int pin:
542
+ The pin that the speaker is connected to.
543
+
544
+ :param int initial_freq:
545
+ The initial frequency of the PWM signal in Hertz. Defaults to 440.
546
+
547
+ :param int initial_volume:
548
+ The initial volume of the PWM signal. This is a value between 0 and
549
+ 1. Defaults to 0.
550
+
551
+ :param int duty_factor:
552
+ The duty factor of the PWM signal. This is a value between 0 and 65535.
553
+ Defaults to 1023.
554
+
555
+ :param bool active_high:
556
+ If :data:`True` (the default), the :meth:`on` method will set the Pin
557
+ to HIGH. If :data:`False`, the :meth:`on` method will set the Pin to
558
+ LOW (the :meth:`off` method always does the opposite).
559
+ """
496
560
NOTES = {
497
561
'b0' : 31 , 'c1' : 33 , 'c#1' : 35 , 'd1' : 37 , 'd#1' : 39 , 'e1' : 41 , 'f1' : 44 , 'f#1' : 46 , 'g1' : 49 ,'g#1' : 52 , 'a1' : 55 ,
498
562
'a#1' : 58 , 'b1' : 62 , 'c2' : 65 , 'c#2' : 69 , 'd2' : 73 , 'd#2' : 78 ,
0 commit comments