Ejemplo n.º 1
0
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()
Ejemplo n.º 3
0
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)
Ejemplo n.º 4
0
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)
Ejemplo n.º 5
0
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)
Ejemplo n.º 6
0
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()
Ejemplo n.º 7
0
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
Ejemplo n.º 12
0
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)
Ejemplo n.º 13
0
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')
Ejemplo n.º 15
0
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()
Ejemplo n.º 16
0
 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()
Ejemplo n.º 17
0
    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()
Ejemplo n.º 18
0
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)
Ejemplo n.º 19
0
 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 = ""
Ejemplo n.º 20
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)
Ejemplo n.º 21
0
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
Ejemplo n.º 22
0
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
Ejemplo n.º 23
0
 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()
Ejemplo n.º 24
0
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()
Ejemplo n.º 25
0
    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
Ejemplo n.º 26
0
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)
Ejemplo n.º 27
0
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()
Ejemplo n.º 28
0
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)
Ejemplo n.º 29
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)

Ejemplo n.º 30
0
def Noise4():
    buzzer.play(Tone('C4'))
    sleep(.1)
    buzzer.play(Tone('B4'))
    sleep(.15)