Exemple #1
0
def ledAndSound(index):
	#print("Enter at ", index)
	GPIO.output(Led_Array[index], 1)
	wiringpi.softToneWrite(gpioSound,mapping[index][1])
	time.sleep(0.5)
	wiringpi.softToneWrite(gpioSound,0)
	GPIO.output(Led_Array[index],0)
Exemple #2
0
def light_led(led):
            GPIO.output(led, GPIO.HIGH)
            wiringpi.softToneWrite(speaker, dSounds[led])
            sleep(0.5)
            wiringpi.softToneWrite(speaker, 0)
            GPIO.output(led, GPIO.LOW)
            sleep(0.5)
            GPIO.output(led, GPIO.LOW)
Exemple #3
0
def siren():
    for freq in range(440, 880, 20):
        wiringpi.softToneWrite(speaker, freq)
        sleep(0.05)

    for freq in range(880, 440, -20):
        wiringpi.softToneWrite(speaker, freq)
        sleep(0.05)
Exemple #4
0
def playFreq(freq, light):
    print("play {0} frequency\n".format(freq))
    wiringpi.softToneWrite(speaker, freq)
    GPIO.output(light, GPIO.HIGH)
    sleep(speedFreq)
    GPIO.output(light, GPIO.LOW)
    wiringpi.softToneWrite(speaker, 0)
    sleep(0.3)
Exemple #5
0
 def writePwm(self, pin, state, freq=None, duty=None):
     # TODO duty
     if freq:
         self._pwmfreq = freq
     if state:
         wpi.softToneWrite(pin, self._pwmfreq)
     elif state is False:
         wpi.softToneWrite(pin, 0)
Exemple #6
0
def button_light_led(led):
    buttonState = GPIO.input(dButtons[led])
    if (not buttonState):
        GPIO.output(led, GPIO.HIGH)
        wiringpi.softToneWrite(speaker, dSounds[led])
        sleep(0.5)
        wiringpi.softToneWrite(speaker, 0)
        GPIO.output(led, GPIO.LOW)
        sleep(0.5)
    else:
        GPIO.output(led, GPIO.LOW)
Exemple #7
0
def all_leds_sound():
    GPIO.output(greenLED, GPIO.HIGH)
    GPIO.output(redLED, GPIO.HIGH)
    GPIO.output(blueLED, GPIO.HIGH)
    GPIO.output(yellowLED, GPIO.HIGH)
    for freq in list(sound_dic.values()):
        wiringpi.softToneWrite(soundPIN, freq)
        sleep(0.1)
    GPIO.output(greenLED, GPIO.LOW)
    GPIO.output(redLED, GPIO.LOW)
    GPIO.output(blueLED, GPIO.LOW)
    GPIO.output(yellowLED, GPIO.LOW)
    wiringpi.softToneWrite(soundPIN,0)
Exemple #8
0
def make_sound(color, pin):
    wiringpi.softToneCreate(sound_gpiopin)
    freq = 0
    if color == 4:
        freq = 659
    elif color == 17:
        freq = 440
    elif color == 27:
        freq = 784
    elif color == 22:
        freq = 523
    elif color == 0:
        freq = 900
    wiringpi.softToneWrite(pin, freq)
    time.sleep(0.5)
    wiringpi.softToneStop(sound_gpiopin)
Exemple #9
0
def game_over(leds, listOfcolors):
    #if the player failed, light all the leds 3 times and make a sound
    for i in range(3):
        GPIO.output(leds[0], GPIO.HIGH)
        GPIO.output(leds[1], GPIO.HIGH)
        GPIO.output(leds[2], GPIO.HIGH)
        GPIO.output(leds[3], GPIO.HIGH)
        wiringpi.softToneWrite(speaker, dSounds[led])
        sleep(1)
        wiringpi.softToneWrite(speaker, 0)
        GPIO.output(leds[0], GPIO.LOW)
        GPIO.output(leds[1], GPIO.LOW)
        GPIO.output(leds[2], GPIO.LOW)
        GPIO.output(leds[3], GPIO.LOW)
        sleep(1)

    print("Game Over! Your score is:", len(listOfcolors) - 1)
def performe(tag):
    tag_str = str(tag)
    matched = id_pattern.search(tag_str)
    if matched:
        id = matched.group(1)
        print("id: " + id)
        res = post(id)
        if res == 'no-user':
            led(True, False, False)
            wiringpi.softToneWrite(beep_pin, E)
            sleep(1)
            wiringpi.softToneWrite(beep_pin, 0)
            time.sleep(0.1)
        else:
            led(False, False, True)
    time.sleep(2)
    led(False, False, False)
Exemple #11
0
def ledOn(color, tone):
    GPIO.output(color, GPIO.HIGH)
    wiringpi.softToneWrite(speaker, tone)
    GPIO.output(color, GPIO.HIGH)
    wiringpi.softToneWrite(speaker, tone)
    sleep(0.5)
    GPIO.output(color, GPIO.LOW)
    wiringpi.softToneWrite(speaker, 0)
    sleep(0.1)
def play_note(note, length=BEAT):
    wiringpi.softToneWrite(PIN, note)
    time.sleep(length)
    wiringpi.softToneWrite(PIN, 0)
    time.sleep(DELAY)
Exemple #13
0
import wiringpi
from time import sleep
pin = 18
frequencies = {
    'c': 262,
    'd': 294,
    'e': 330,
    'f': 349,
    'g': 392,
    'a': 440,
    'b': 494
}
notes = 'ccggaag ffeeddc ggffeed ggffeed ccggaag ffeeddc'

wiringpi.wiringPiSetupGpio()

try:
    wiringpi.softToneCreate(pin)
    for i in notes:
        if i != ' ':
            wiringpi.softToneWrite(pin, frequencies[i])
        else:
            wiringpi.softToneWrite(pin, 0)
        sleep(0.3)
finally:
    wiringpi.pinMode(pin, 0)
Exemple #14
0
def right_left_sound(led):
    GPIO.output(led, GPIO.HIGH)
    wiringpi.softToneWrite(soundPIN, sound_dic[led])
    sleep(0.3)
    GPIO.output(led, GPIO.LOW)
    wiringpi.softToneWrite(soundPIN, 0)
Exemple #15
0
 def setFrequency(self, frequency):
     self.frequency = frequency
     wiringpi.softToneWrite(self.gpio, self.frequency)
Exemple #16
0
def led_sound(freq):
    wiringpi.softToneWrite(soundPIN, freq)
    sleep(sleep_tone)
    wiringpi.softToneWrite(soundPIN, 0)
Exemple #17
0
import wiringpi
from time import sleep
pin = 18

wiringpi.wiringPiSetupGpio()

try:
    wiringpi.softToneCreate(pin)
    while True:
        wiringpi.softToneWrite(pin, 392)
        sleep(0.5)
        wiringpi.softToneWrite(pin, 523)
        sleep(0.5)
finally:
    wiringpi.pinMode(pin, 0)
Exemple #18
0
 def play(self, melody):
     """ ソフトウェアトーン再生"""
     for v, play_time in melody:  # 指定されたメロディーの再生
         wiringpi.softToneWrite(self.pin, v)  # トーン発生
         time.sleep(play_time)  # 同じ音を出力するために処理を遅延
     self.play_stop()
Exemple #19
0
def changeFreq(freq):
	wp.pwmWrite(BUZZER_PIN, freq)
	wp.softToneWrite(BUZZER_PIN, freq)
Exemple #20
0
import wiringpi  
from time import sleep  
PIN_BUZ = 18

wiringpi.wiringPiSetupGpio()  
  
try:
    wiringpi.softToneCreate(PIN_BUZ)
    while True:
        wiringpi.softToneWrite(PIN_BUZ, 392)
        sleep(0.5)
        wiringpi.softToneWrite(PIN_BUZ, 523)
        sleep(0.5)
finally:
    wiringpi.pinMode(PIN_BUZ, 0)
Exemple #21
0
def stopFreq():
	wp.softToneWrite(BUZZER_PIN, 0)
Exemple #22
0
import RPi.GPIO as GPIO
import wiringpi

GPIO.setmode(GPIO.BCM)  #Setting the Mode to use. I am using the BCM setup
GPIO.setwarnings(False)

#Declaring the GPIO Pins that the motor controller is set with
m0Right = 8
m1Right = 7
m2Right = 20
sleepPinRight = 16
stepRight = 12
directionRight = 21
GPIO.setup(sleepPinRight, GPIO.OUT)
# GPIO.setup(stepRight, GPIO.OUT)
GPIO.setup(directionRight, GPIO.OUT)
GPIO.setup(m0Right, GPIO.OUT)
GPIO.setup(m1Right, GPIO.OUT)
GPIO.setup(m2Right, GPIO.OUT)
# PWM1 = GPIO.PWM(stepRight, 50)
# PWM1.start(0)

wiringpi.wiringPiSetup()
wiringpi.softToneCreate(stepRight)

try:
    while True:
        wiringpi.softToneWrite(stepRight, 100)

except KeyboardInterrupt:
    berhenti()
Exemple #23
0
 def play_stop(self):
     """ 再生終了 """
     wiringpi.softToneWrite(self.pin, 0)  # 再生終了
Exemple #24
0
def loser():
    print("you are a loser!")
    GPIO.output(redLight, GPIO.HIGH)
    wiringpi.softToneWrite(speaker, 800)
    sleep(0.1)
    GPIO.output(redLight, GPIO.LOW)
    GPIO.output(blueLight, GPIO.HIGH)
    wiringpi.softToneWrite(speaker, 1000)
    sleep(0.1)
    GPIO.output(blueLight, GPIO.LOW)
    GPIO.output(yellowLight, GPIO.HIGH)
    wiringpi.softToneWrite(speaker, 900)
    sleep(0.1)
    GPIO.output(yellowLight, GPIO.LOW)
    GPIO.output(greenLight, GPIO.HIGH)
    wiringpi.softToneWrite(speaker, 670)
    sleep(0.1)
    GPIO.output(greenLight, GPIO.LOW)
    wiringpi.softToneWrite(speaker, 700)
    sleep(0.1)
    GPIO.output(redLight, GPIO.LOW)
    GPIO.output(blueLight, GPIO.HIGH)
    wiringpi.softToneWrite(speaker, 1200)
    sleep(0.1)
    GPIO.output(blueLight, GPIO.LOW)
    GPIO.output(yellowLight, GPIO.HIGH)
    wiringpi.softToneWrite(speaker, 800)
    sleep(0.1)
    GPIO.output(yellowLight, GPIO.LOW)
    GPIO.output(greenLight, GPIO.HIGH)
    wiringpi.softToneWrite(speaker, 1250)
    sleep(0.1)
    GPIO.output(greenLight, GPIO.LOW)
    wiringpi.softToneWrite(speaker, 0)
Exemple #25
0
 def __init__(self, gpio=2, frequency=100):
     wiringpi.wiringPiSetup()
     self.frequency = frequency
     self.gpio = gpio
     wiringpi.softToneCreate(self.gpio)
     wiringpi.softToneWrite(self.gpio, self.frequency)
Exemple #26
0
def play(data):
    for i in data:
        time.sleep(i[0])
        wiringpi.softToneWrite(i[1], i[2])
Exemple #27
0
 def play(self):
     for note in self.notes:
         wiringpi.softToneWrite(self.SOUNDER, self.FREQUENCIES[note[0]])
         time.sleep(self.LENGTHS[note[1]])
         if wiringpi.digitalRead(self.SW1) == 0:
             return
 def _play(self, arr):
     for idx in arr:
         wiringpi.softToneWrite(self.PIN, idx)
         wiringpi.delay(50)
Exemple #29
0
import wiringpi
import time

#General Setup
wiringpi.wiringPiSetupGpio()

wiringpi.softToneCreate(25)

# 200Hz frequency on GPIO25
wiringpi.softToneWrite(25, 200)

# Run for 0.7 seconds
time.sleep(0.7)

# Stop the tone
wiringpi.softToneStop(25)
Exemple #30
0
import wiringpi  
from time import sleep  
PIN_BUZ = 18

frequencies = {'c':262, 'd':294, 'e':330, 'f':349, 'g':392, 'a':440, 'b':494}
notes = 'ccggaag ffeeddc ggffeed ggffeed ccggaag ffeeddc'

wiringpi.wiringPiSetupGpio()  
try:
    wiringpi.softToneCreate(PIN_BUZ)
    for i in notes:
        if i != ' ':
            wiringpi.softToneWrite(PIN_BUZ, frequencies[i])
        else:
            wiringpi.softToneWrite(PIN_BUZ, 0)
        sleep(0.3)
finally:
    wiringpi.pinMode(PIN_BUZ, 0)
Exemple #31
0
def play_sound(sound):
    for i in range(1, 10, 2):
        wiringpi.softToneWrite(siren, sound)
        sleep(0.1)
    wiringpi.softToneWrite(siren, 0)