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 test_tone_midi(A4): assert A4.midi == 69 assert A4.up().midi == 70 assert A4.down().midi == 68 with pytest.raises(ValueError): Tone.from_frequency(2).midi with pytest.raises(ValueError): Tone.from_frequency(15000).midi
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 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 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 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 test_tone_from_note(A4): assert Tone.from_note(b"A4") == A4 assert Tone.from_note("A4") == A4 with pytest.raises(ValueError): Tone.from_note("a4") with pytest.raises(ValueError): Tone.from_note("foo") with pytest.raises(ValueError): Tone.from_note(0)
def red(time): ledR.on() bz.play(Tone(440)) sleep(time) ledR.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 green(time): ledG.on() bz.play(Tone(659.255)) sleep(time) ledG.off() sleep(time) bz.stop() return
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 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 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 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 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 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 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 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 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 test_tone_from_frequency(A4): assert Tone.from_frequency(440) == A4 assert Tone.from_frequency(440.0) == A4 with pytest.raises(ValueError): Tone.from_frequency(-100.0) with pytest.raises(ValueError): Tone.from_frequency(30000.0)
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 getButton(channel, event): global qnum, correct_answers, b print("Got {} on {}".format(event, channel)) eh.light.off() if correct_answers[qnum] == 0: eh.light.blue.on() elif correct_answers[qnum] == 1: eh.light.yellow.on() elif correct_answers[qnum] == 2: eh.light.red.on() else: eh.light.green.on() if (channel - 1) == correct_answers[qnum] and event == "press": b.play(Tone.from_frequency(880)) time.sleep(1) else: b.play(Tone.from_frequency(220)) time.sleep(1) b.stop() time.sleep(1) b.play(Tone.from_frequency(220)) b.stop()
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 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()