Created
          June 13, 2020 20:47 
        
      - 
      
 - 
        
Save FoamyGuy/31b321666e58232cc7c082e4993a4cf4 to your computer and use it in GitHub Desktop.  
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | import time | |
| import board | |
| from digitalio import DigitalInOut, Direction, Pull | |
| import audiopwmio | |
| import neopixel | |
| from audiocore import WaveFile | |
| filename = "electrons.wav" | |
| # The pad our button is connected to: | |
| button = DigitalInOut(board.BUTTON_A) | |
| button.direction = Direction.INPUT | |
| button.pull = Pull.DOWN | |
| # Required for CircuitPlayground Express | |
| speaker_enable = DigitalInOut(board.SPEAKER_ENABLE) | |
| speaker_enable.switch_to_output(value=True) | |
| pixels = neopixel.NeoPixel(board.NEOPIXEL, 10, brightness=0.1) | |
| # NeoPixel Animation | |
| def simpleCircle(wait): | |
| PURPLE = (255, 0, 255) | |
| BLACK = (0, 0, 0) | |
| CYAN = (0, 255, 255) | |
| ORANGE = (255, 255, 0) | |
| for i in range(len(pixels)): | |
| pixels[i] = PURPLE | |
| time.sleep(wait) | |
| for i in range(len(pixels)): | |
| pixels[i] = CYAN | |
| time.sleep(wait) | |
| for i in range(len(pixels)): | |
| pixels[i] = ORANGE | |
| time.sleep(wait) | |
| for i in range(len(pixels)): | |
| pixels[i] = BLACK | |
| time.sleep(wait) | |
| # Audio Play File | |
| def play_file(playname): | |
| print("Playing File " + playname) | |
| wave_file = open(playname, "rb") | |
| with WaveFile(wave_file) as wave: | |
| with audiopwmio.PWMAudioOut(board.SPEAKER) as audio: | |
| audio.play(wave) | |
| while audio.playing: | |
| simpleCircle(.02) | |
| print("finished") | |
| while True: | |
| print(button.value) | |
| if button.value: | |
| play_file(filename) | |
| time.sleep(0.1) | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment