|
69 | 69 | sys.path.insert(0, os.path.join(abs_path)) |
70 | 70 | import neopixel |
71 | 71 | from base_circuitpython import base_cp_constants as CONSTANTS |
| 72 | +from common import utils |
72 | 73 |
|
73 | 74 | # REVISED VERSION OF THE ADAFRUIT CLUE LIBRARY FOR DSX |
74 | 75 |
|
@@ -205,7 +206,7 @@ def __init__(self): |
205 | 206 | "sea_level_pressure": 1013.25, |
206 | 207 | "temperature": 0, |
207 | 208 | "proximity": 0, |
208 | | - "gesture": 0, # Can only be 0, 1, 2, 3, 4 |
| 209 | + "gesture": "", |
209 | 210 | "humidity": 0, |
210 | 211 | "pressure": 0, |
211 | 212 | "pixel": neopixel.NeoPixel( |
@@ -285,6 +286,21 @@ def acceleration(self): |
285 | 286 | self.__state["motion_z"], |
286 | 287 | ) |
287 | 288 |
|
| 289 | + def shake(self, shake_threshold=30, avg_count=10, total_delay=0.1): |
| 290 | + """Not implemented! |
| 291 | + Detect when the accelerometer is shaken. Optional parameters: |
| 292 | + :param shake_threshold: Increase or decrease to change shake sensitivity. This |
| 293 | + requires a minimum value of 10. 10 is the total |
| 294 | + acceleration if the board is not moving, therefore |
| 295 | + anything less than 10 will erroneously report a constant |
| 296 | + shake detected. (Default 30) |
| 297 | + :param avg_count: The number of readings taken and used for the average |
| 298 | + acceleration. (Default 10) |
| 299 | + :param total_delay: The total time in seconds it takes to obtain avg_count |
| 300 | + readings from acceleration. (Default 0.1) |
| 301 | + """ |
| 302 | + utils.print_for_unimplemented_functions(Clue.shake.__name__) |
| 303 | + |
288 | 304 | @property |
289 | 305 | def color(self): |
290 | 306 | """The red, green, blue, and clear light values. (r, g, b, c) |
@@ -367,7 +383,8 @@ def gesture(self): |
367 | 383 | while True: |
368 | 384 | print("Gesture: {}".format(clue.gesture)) |
369 | 385 | """ |
370 | | - return self.__state["gesture"] |
| 386 | + gesture_mapping = {"": 0, "up": 1, "down": 2, "left": 3, "right": 4} |
| 387 | + return gesture_mapping[self.__state["gesture"]] |
371 | 388 |
|
372 | 389 | @property |
373 | 390 | def humidity(self): |
@@ -439,6 +456,202 @@ def pixel(self): |
439 | 456 | """ |
440 | 457 | return self.__state["pixel"] |
441 | 458 |
|
| 459 | + @property |
| 460 | + def touch_0(self): |
| 461 | + """Not Implemented! |
| 462 | +
|
| 463 | + Detect touch on capacitive touch pad 0. |
| 464 | + .. image :: ../docs/_static/pad_0.jpg |
| 465 | + :alt: Pad 0 |
| 466 | + This example prints when pad 0 is touched. |
| 467 | + To use with the CLUE: |
| 468 | + .. code-block:: python |
| 469 | + from adafruit_clue import clue |
| 470 | + while True: |
| 471 | + if clue.touch_0: |
| 472 | + print("Touched pad 0") |
| 473 | + """ |
| 474 | + utils.print_for_unimplemented_functions(Clue.touch_0.__name__) |
| 475 | + |
| 476 | + @property |
| 477 | + def touch_1(self): |
| 478 | + """Not Implemented! |
| 479 | + |
| 480 | + Detect touch on capacitive touch pad 1. |
| 481 | + .. image :: ../docs/_static/pad_1.jpg |
| 482 | + :alt: Pad 1 |
| 483 | + This example prints when pad 1 is touched. |
| 484 | + To use with the CLUE: |
| 485 | + .. code-block:: python |
| 486 | + from adafruit_clue import clue |
| 487 | + while True: |
| 488 | + if clue.touch_1: |
| 489 | + print("Touched pad 1") |
| 490 | + """ |
| 491 | + utils.print_for_unimplemented_functions(Clue.touch_1.__name__) |
| 492 | + |
| 493 | + @property |
| 494 | + def touch_2(self): |
| 495 | + """Not Implemented! |
| 496 | + |
| 497 | + Detect touch on capacitive touch pad 2. |
| 498 | + .. image :: ../docs/_static/pad_2.jpg |
| 499 | + :alt: Pad 2 |
| 500 | + This example prints when pad 2 is touched. |
| 501 | + To use with the CLUE: |
| 502 | + .. code-block:: python |
| 503 | + from adafruit_clue import clue |
| 504 | + while True: |
| 505 | + if clue.touch_2: |
| 506 | + print("Touched pad 2") |
| 507 | + """ |
| 508 | + utils.print_for_unimplemented_functions(Clue.touch_2.__name__) |
| 509 | + |
| 510 | + @property |
| 511 | + def white_leds(self): |
| 512 | + """Not Implemented! |
| 513 | + |
| 514 | + The red led next to the USB plug labeled LED. |
| 515 | + .. image :: ../docs/_static/white_leds.jpg |
| 516 | + :alt: White LEDs |
| 517 | + This example turns on the white LEDs. |
| 518 | + To use with the CLUE: |
| 519 | + .. code-block:: python |
| 520 | + from adafruit_clue import clue |
| 521 | + clue.white_leds = True |
| 522 | + """ |
| 523 | + utils.print_for_unimplemented_functions(Clue.white_leds.__name__) |
| 524 | + |
| 525 | + @white_leds.setter |
| 526 | + def white_leds(self, value): |
| 527 | + """Not Implemented!""" |
| 528 | + utils.print_for_unimplemented_functions(Clue.white_leds.__name__) |
| 529 | + |
| 530 | + @property |
| 531 | + def red_led(self): |
| 532 | + """Not Implemented! |
| 533 | + |
| 534 | + The red led next to the USB plug labeled LED. |
| 535 | + .. image :: ../docs/_static/red_led.jpg |
| 536 | + :alt: Red LED |
| 537 | + This example turns on the red LED. |
| 538 | + To use with the CLUE: |
| 539 | + .. code-block:: python |
| 540 | + from adafruit_clue import clue |
| 541 | + clue.red_led = True |
| 542 | + """ |
| 543 | + utils.print_for_unimplemented_functions(Clue.red_led.__name__) |
| 544 | + |
| 545 | + @red_led.setter |
| 546 | + def red_led(self, value): |
| 547 | + """Not Implemented!""" |
| 548 | + utils.print_for_unimplemented_functions(Clue.red_led.__name__) |
| 549 | + |
| 550 | + def play_tone(self, frequency, duration): |
| 551 | + """ Not Implemented! |
| 552 | + Produce a tone using the speaker. Try changing frequency to change |
| 553 | + the pitch of the tone. |
| 554 | + :param int frequency: The frequency of the tone in Hz |
| 555 | + :param float duration: The duration of the tone in seconds |
| 556 | + .. image :: ../docs/_static/speaker.jpg |
| 557 | + :alt: Speaker |
| 558 | + This example plays a 880 Hz tone for a duration of 1 second. |
| 559 | + To use with the CLUE: |
| 560 | + .. code-block:: python |
| 561 | + from adafruit_clue import clue |
| 562 | + clue.play_tone(880, 1) |
| 563 | + """ |
| 564 | + utils.print_for_unimplemented_functions(Clue.play_tone.__name__) |
| 565 | + |
| 566 | + def start_tone(self, frequency): |
| 567 | + """ Not Implemented! |
| 568 | + Produce a tone using the speaker. Try changing frequency to change |
| 569 | + the pitch of the tone. |
| 570 | + :param int frequency: The frequency of the tone in Hz |
| 571 | + .. image :: ../docs/_static/speaker.jpg |
| 572 | + :alt: Speaker |
| 573 | + This example plays a 523Hz tone when button A is pressed and a 587Hz tone when button B is |
| 574 | + pressed, only while the buttons are being pressed. |
| 575 | + To use with the CLUE: |
| 576 | + .. code-block:: python |
| 577 | + from adafruit_clue import clue |
| 578 | + while True: |
| 579 | + if clue.button_a: |
| 580 | + clue.start_tone(523) |
| 581 | + elif clue.button_b: |
| 582 | + clue.start_tone(587) |
| 583 | + else: |
| 584 | + clue.stop_tone() |
| 585 | + """ |
| 586 | + utils.print_for_unimplemented_functions(Clue.start_tone.__name__) |
| 587 | + |
| 588 | + def stop_tone(self): |
| 589 | + """ Not Implemented! |
| 590 | + Use with start_tone to stop the tone produced. |
| 591 | + .. image :: ../docs/_static/speaker.jpg |
| 592 | + :alt: Speaker |
| 593 | + This example plays a 523Hz tone when button A is pressed and a 587Hz tone when button B is |
| 594 | + pressed, only while the buttons are being pressed. |
| 595 | + To use with the CLUE: |
| 596 | + .. code-block:: python |
| 597 | + from adafruit_clue import clue |
| 598 | + while True: |
| 599 | + if clue.button_a: |
| 600 | + clue.start_tone(523) |
| 601 | + elif clue.button_b: |
| 602 | + clue.start_tone(587) |
| 603 | + else: |
| 604 | + clue.stop_tone() |
| 605 | + """ |
| 606 | + utils.print_for_unimplemented_functions(Clue.stop_tone.__name__) |
| 607 | + |
| 608 | + @property |
| 609 | + def sound_level(self): |
| 610 | + """Not Implemented! |
| 611 | + Obtain the sound level from the microphone (sound sensor). |
| 612 | + .. image :: ../docs/_static/microphone.jpg |
| 613 | + :alt: Microphone (sound sensor) |
| 614 | + This example prints the sound levels. Try clapping or blowing on |
| 615 | + the microphone to see the levels change. |
| 616 | + .. code-block:: python |
| 617 | + from adafruit_clue import clue |
| 618 | + while True: |
| 619 | + print(clue.sound_level) |
| 620 | + """ |
| 621 | + utils.print_for_unimplemented_functions(Clue.sound_level.__name__) |
| 622 | + |
| 623 | + def loud_sound(self, sound_threshold=200): |
| 624 | + """Not Implemented! |
| 625 | + Utilise a loud sound as an input. |
| 626 | + :param int sound_threshold: Threshold sound level must exceed to return true (Default: 200) |
| 627 | + .. image :: ../docs/_static/microphone.jpg |
| 628 | + :alt: Microphone (sound sensor) |
| 629 | + This example turns the NeoPixel LED blue each time you make a loud sound. |
| 630 | + Try clapping or blowing onto the microphone to trigger it. |
| 631 | + .. code-block:: python |
| 632 | + from adafruit_clue import clue |
| 633 | + while True: |
| 634 | + if clue.loud_sound(): |
| 635 | + clue.pixel.fill((0, 50, 0)) |
| 636 | + else: |
| 637 | + clue.pixel.fill(0) |
| 638 | + You may find that the code is not responding how you would like. |
| 639 | + If this is the case, you can change the loud sound threshold to |
| 640 | + make it more or less responsive. Setting it to a higher number |
| 641 | + means it will take a louder sound to trigger. Setting it to a |
| 642 | + lower number will take a quieter sound to trigger. The following |
| 643 | + example shows the threshold being set to a higher number than |
| 644 | + the default. |
| 645 | + .. code-block:: python |
| 646 | + from adafruit_clue import clue |
| 647 | + while True: |
| 648 | + if clue.loud_sound(sound_threshold=300): |
| 649 | + clue.pixel.fill((0, 50, 0)) |
| 650 | + else: |
| 651 | + clue.pixel.fill(0) |
| 652 | + """ |
| 653 | + utils.print_for_unimplemented_functions(Clue.loud_sound.__name__) |
| 654 | + |
442 | 655 | @staticmethod |
443 | 656 | def simple_text_display( |
444 | 657 | title=None, |
|
0 commit comments