def main(): # 各ピンをbuzzer設定 factory = PiGPIOFactory() buzzer = TonalBuzzer(BUZZER_PIN, pin_factory=factory) # 音を鳴らす try: # 音符指定 for onpu in ONPUS: buzzer.play(Tone(onpu)) sleep(0.5) buzzer.stop() sleep(0.5) # midi note指定 (!!!57-81の範囲のみ指定可能) for note_no in range(60, 80, 5): buzzer.play(Tone(midi=note_no)) # middle C in MIDI notation sleep(0.5) buzzer.stop() sleep(0.5) # 周波数指定 for freq in range(300, 400, 100): buzzer.play(Tone(frequency=freq)) sleep(0.5) buzzer.stop() sleep(0.5) except: buzzer.stop() print("stop") return
def beep(buzzer): buzzer.play(Tone(500.0)) # Hz sleep(0.15) buzzer.stop() sleep(0.15) buzzer.play(Tone(500.0)) # Hz sleep(0.15) buzzer.stop()
def Noise1(): # String of Buzzing 1 buzzer.play(Tone('A4')) sleep(.3) buzzer.play(Tone('B4')) sleep(.15) buzzer.play(Tone('C4')) sleep(.15) buzzer.play(Tone('D4')) sleep(.35)
def Noise1(): buzzer.play(Tone('A4')) sleep(.3) buzzer.play(Tone('B4')) sleep(.15) buzzer.play(Tone('C4')) sleep(.15) buzzer.play(Tone('D4')) sleep(.35)
def alarm_buzzer_melody(): tone_buzzer = TonalBuzzer(27) for _ in range(5): tone_buzzer.play(Tone("C4")) sleep(0.15) tone_buzzer.play(Tone("G4")) sleep(0.15) tone_buzzer.play(Tone("F4")) sleep(0.15) tone_buzzer.stop() sleep(2)
def alarm(b): '''b is a gpiozero TonalBuzzer ''' start = 60 #hz high = 80 inc = 5 gap = 0.05 for f in range(start, high, inc): b.play(Tone(midi=f)) time.sleep(gap) # then increase for f in range(high, start, -inc): b.play(Tone(midi=f)) time.sleep(gap) b.stop()
def test_tone_str(A4): assert str(A4) == "A4" assert str(A4.up()) == "A#4" assert str(A4.down(12)) == "A3" assert repr( A4) == "<Tone note={note!r} midi=69 frequency=440.00Hz>".format( note='A4') assert repr(Tone(13000)) == '<Tone frequency=13000.00Hz>'
def green(time): ledG.on() bz.play(Tone(659.255)) sleep(time) ledG.off() sleep(time) bz.stop() return
def red(time): ledR.on() bz.play(Tone(440)) sleep(time) ledR.off() sleep(time) bz.stop() return
def blue(time): ledB.on() bz.play(Tone(329.628)) sleep(time) ledB.off() sleep(time) bz.stop() return
def yellow(time): ledY.on() bz.play(Tone(554.365)) sleep(time) ledY.off() sleep(time) bz.stop() return
def game_end_audio(bz): delays = [.4, .3, .2, .1, .3, .6] notes = ['A4', 'B4', 'D4'] for i in range(len(delays)): note = notes[i] delay = delays[i] bz.play(Tone(note)) sleep(delay)
def buttonspressed(max_power): # function for handling button presses # dictionary to store if button is pressed button_status = { 'leftTurn': False, 'rightTurn': False, 'brake': False, 'headLight': False, 'horn': False } try: if leftButton.is_pressed: # left signal button i2cBus.write_byte_data(tailEndPicAddress, 0, 1) button_status['leftTurn'] = True else: i2cBus.write_byte_data(tailEndPicAddress, 0, 0) button_status['leftTurn'] = False if rightButton.is_pressed: # right signal button i2cBus.write_byte_data(tailEndPicAddress, 1, True) button_status['rightTurn'] = True else: i2cBus.write_byte_data(tailEndPicAddress, 1, False) button_status['rightTurn'] = False if brakeButton.is_pressed: # brake signal button i2cBus.write_byte_data(tailEndPicAddress, 5, True) i2cBus.write_byte_data(batteryPicAddress, 2, False) button_status['brake'] = True else: i2cBus.write_byte_data(tailEndPicAddress, 5, False) i2cBus.write_byte_data(batteryPicAddress, 2, True) button_status['brake'] = False if headLightButton.is_pressed: # headlight button i2cBus.write_byte_data(tailEndPicAddress, 2, True) i2cBus.write_byte_data(tailEndPicAddress, 3, True) button_status['headLight'] = True else: i2cBus.write_byte_data(tailEndPicAddress, 2, False) i2cBus.write_byte_data(tailEndPicAddress, 3, False) button_status['headLight'] = False if hornButton.is_pressed: horn.play(Tone(220.0)) button_status['horn'] = True else: horn.stop() button_status['horn'] = False i2cBus.write_byte_data(batteryPicAddress, 4, int(max_power)) # send max power values to pic except: logging.error('Buttons Error') return button_status
def transmission_start_end(): tbuzzer = TonalBuzzer(22) led.blink(0.025, 0.025) tbuzzer.play(Tone(frequency=500)) sleep(3) led.off() tbuzzer.stop() tbuzzer.close() return render_template('json.html')
def game_start_audio(bz): # audio played on startup delays = [.4, .2, .2, .4, .2, .4] notes = ['A3', 'A4', 'A3', 'B4', 'B3', 'C5'] for i in range(len(delays)): note = notes[i] delay = delays[i] bz.play(Tone(note)) sleep(delay) bz.stop()
def beep(self,n=1,t=.1): for i in range(0,n): for tn in self.seq: try: self._buzzer.play(Tone(midi=tn)) except: pass sleep(t) self._buzzer.stop()
def beep(self): self.buzzer_lock.acquire() self.buzzer.play(Tone("A4")) sleep(0.1) self.buzzer.stop() sleep(0.1) self.buzzer_lock.release()
def play(song, speed=False): for (note, duration, rest) in song: if speed: duration = duration * speed rest = rest * speed buzzer.play(Tone(note)) time.sleep(duration) buzzer.stop() time.sleep(rest)
def handleKeyPress(self, key): if not self.can_open: self.password += key buzzer.play(Tone("C4")) time.sleep(0.1) buzzer.stop() if len(self.password) == 4: print(f'password: {self.password}') self.checkpassword() self.password = ""
def test_tone_init(A4): with warnings.catch_warnings(record=True) as w: warnings.resetwarnings() assert Tone(440) == A4 assert Tone("A4") == A4 assert len(w) == 0 assert Tone(69) == A4 assert len(w) == 1 assert isinstance(w[0].message, AmbiguousTone) assert Tone(frequency=440) == A4 assert Tone(note="A4") == A4 assert Tone(midi=69) == A4 with pytest.raises(TypeError): Tone() with pytest.raises(TypeError): Tone(foo=1) with pytest.raises(TypeError): Tone(frequency=440, midi=69)
def SNDEventHandler(sensor): #creates the SNDEventHandler method which takes in the value of sensor print ("Sound Detected!") #prints message to the console SNDdetected = 1 #sets SNDdetected value to 1 buzzer.play(Tone(note='A5')) #sends message to the passive buzzer to play note A5 if (SNDdetected == 1): #if a sound is detected camera.capture(fileLoc) #camera takes a photo and saves the image to the fileLoc folder defined above storeFileFB.store_file(fileLoc) #triggers store_file method from storeFileFB script using value of fileLoc which stores the captured image in firebase storage storeFileFB.push_db(fileLoc, currentTime) #triggers push_db method from storeFileFB script using value of fileLoc and current time which pushes the captured image to the firebase realtime database time.sleep(5) #sleep for 5 seconds while buzzer is ringing away buzzer.stop() #stops the buzzer conn = urlopen(baseURL + '&field1=%s' % (SNDdetected)) #triggers a URL using the Thingspeak URL above which reads in the new value of SNDdetected triggering the ThingTweet to be posted. print(conn.read()) #information is printed to the URL thus triggering the ThingTweet conn.close() #temp connection to trigger URL is then closed
def main(): # 各ピンをbuzzer設定 factory = PiGPIOFactory() buzzers = {} for key, pin in buzzer_pins.items(): buzzers[key] = TonalBuzzer(pin, pin_factory=PiGPIOFactory()) # 音を鳴らす try: for _ in range(5): for key, buzzer in buzzers.items(): buzzer.play(Tone("A4")) sleep(0.5) buzzer.play(Tone(220.0)) # Hz sleep(0.5) buzzer.play(Tone(60)) # middle C in MIDI notation sleep(0.5) buzzer.stop() except KeyboardInterrupt: print("stop") return
def scale(self, pick=1): music = '' pause = 1 print(' Scale ' + str(pick) + '!') if pick == 1: music = 'C4 D4 E4 F4 G4 A4 B4 C5' pause = 0.5 elif pick == 2: music = 'G4 C4 A4 F4 E4 C4 D4' for note in music.split(): tone = Tone(note) self.buzzer.play(tone) sleep(pause) self.no()
def dpad(pos): #controls are backwards because a lot of German tanks had frontal Engines but i found out the TigerII has backend engines later on after i already put the board in. if pos.top: #print ("up") robot.backward() elif pos.left: #print ("left") robot.right() elif pos.right: #print ("right") robot.left() elif pos.bottom: #print ("down") robot.forward() elif pos.middle: #print("fire") led.on() fire.play(Tone(500)) sleep(.1) fire.play(Tone(220)) sleep(.1) fire.stop() led.off()
def run(self): while True: # time.sleep(0.050) item = self.rcv_que.get() ic("[buzzer_th]", "run : get : ", item) if "buzzer" not in item["type"]: ic("[buzzer_th]", "error!") continue ms_time = int(item["time"]) / 1000 # item["note"] : 'C4', 'D4', 'E4', 'F4', 'G4', 'A4', 'B4', 'C5' self._buzzer[item["name"]].play(Tone(item["note"])) time.sleep(ms_time) self._buzzer[item["name"]].stop() return
def play_me(my_buzzer, my_buttons, reactivity=0.1): """ Description ----------- Play the buzzer with some arbitrary number of GPIO buttons all hooked up! Params ------ :my_buzzer: gpiozero.TonalBuzzer The buzzer object you will be buzzing. :buttons: list[gpiozero.Button] A list of buttons that you will be using to play said buzzer. The order of the list will dictate where in the evaluation order that the button will take priority. The buttons with lower indices, if pressed, will be prioritized over buttons with higher indices that are also pressed. There can only be one tone played at a time. :reactivity: float = 0.1 Return ------ None """ # Creates a dictionary correlating the index in the button list to a # dictionary key containing values representing evenly spaced intervals # between the minimum and maximum tone for the provided buzzer tones_to_listen_for = { k: (k * (my_buzzer.max_tone.frequency - my_buzzer.min_tone) / len(my_buttons)) + my_buzzer.min_tone.frequency for k, v in enumerate(my_buttons) } # Infinite loop that sets the buzzer to the tone of the # button that is first pressed while True: for i, button in enumerate(my_buttons): if button.is_pressed: my_buzzer.play(Tone(tones_to_listen_for[i])) break else: my_buzzer.play(None) print(my_buzzer.tone) sleep(reactivity)
def music(): b.play(Tone("C4")) sleep(0.2) b.play(Tone("C4")) sleep(0.2) b.play(Tone("G4")) sleep(0.2) b.play(Tone("G4")) sleep(0.8) b.play(Tone("A4")) sleep(0.2) b.play(Tone("A4")) sleep(0.2) b.play(Tone("G4")) sleep(0.2) b.stop()
from gpiozero import DistanceSensor from time import sleep from gpiozero import TonalBuzzer from gpiozero.tones import Tone b = TonalBuzzer(14) b.play(Tone("A4")) sleep(.1) b.play(Tone("C4")) sleep(.1) b.stop() sensorleft = DistanceSensor(echo=24, trigger=23, max_distance=3) sensorright = DistanceSensor(echo=6, trigger=5, max_distance=3) while True: print( f'DistanceLeft: {sensorleft.distance * 100:.2f} DistanceRight: {sensorright.distance * 100:.2f}' ) sleep(1.0) exit(0)
from gpiozero import TonalBuzzer from gpiozero.tones import Tone from signal import pause from time import sleep b = TonalBuzzer(25) b.play(Tone(220)) sleep(.1) b.play(Tone(500)) sleep(.1)
def Noise4(): buzzer.play(Tone('C4')) sleep(.1) buzzer.play(Tone('B4')) sleep(.15)