Beispiel #1
0
def _tone(freq, _time):
    try:
        wiringpi2.softToneWrite(port, freq)
        time.sleep(_time)
    finally:
        wiringpi2.softToneWrite(port, 0)
    time.sleep(0.02)
Beispiel #2
0
def _tone(freq, _time):
    try:
        wiringpi2.softToneWrite(port, freq)
        time.sleep(_time)
    finally:
        wiringpi2.softToneWrite(port, 0)
    time.sleep(0.02)
Beispiel #3
0
def init_PWM(_redPin = 23, _greenPin = 24, _bluePin = 25, _flashPin= 22, initDutyCycle = [100]*3, flashRate = 0): 
   global colorPins, colors, flashActive, flashPin 
 
   colorPins = [_redPin, _greenPin, _bluePin] #list for pins used in raspberry pi

   wiringpi2.wiringPiSetup() # Initialize using wiringPi pin numbering scheme   

   for dc in initDutyCycle: #Check for valid initial duty cycle
      if dc < 0 or dc > 255: return -1

   #Create intial PWM signals for input to LED strip
   for i in range(3):
      wiringpi2.softPwmCreate(colorPins[i], int(initDutyCycle[i]*100.0/255.0), 100)

   #Current RGB values of LED strip
   colors = list(initDutyCycle)

   #Create square wave for flashing beat
   flashPin = _flashPin
   wiringpi2.softToneCreate(flashPin)
   if flashRate != 0:
      wiringpi2.softToneWrite(flashPin, flashRate)
      flashActive = True
   else:
      wiringpi2.softToneStop(flashPin)
      flashActive = False

   #Use Colors.txt file to create list of preset color options
   readColorsFile()

   return 0
Beispiel #4
0
def setBPM(flashRate):
   global flashActive

   if flashRate != 0:
      if not flashActive:
         wiringpi2.softToneCreate(flashPin)
         flashActive = True
      wiringpi2.softToneWrite(flashPin, flashRate)

   else:
      if flashActive:
         wiringpi2.softToneStop(flashPin)
         flashActive = False
Beispiel #5
0
    def execute_event(self, event):
        #print("event type : " + str(type(event)))

        waitSecond = event.tick * (float(self.tempo) /
                                   self.mididata.resolution) / 1000000

        #print("test : " + str(float(event.tick)/self.mididata.resolution))
        #print("event.tick : " + str(event.tick))
        #print("resolution: " + str(self.mididata.resolution))
        #print("tempo : " + str(self.tempo))
        #print("wait second : " + str(waitSecond))
        sleep(waitSecond)

        if (isinstance(event, midi.EndOfTrackEvent)):
            return False

        elif (isinstance(event, midi.SetTempoEvent)):
            ms = event.data[0] * pow(16, 4)
            ms += event.data[1] * pow(16, 2)
            ms += event.data[2]
            self.tempo = ms
            print("tempo = " + str(ms) + " ms")

        elif (isinstance(event, midi.NoteOnEvent)):
            velocity = event.data[0]
            pitch = event.data[1]
            wiringpi.softToneWrite(outpin, pitch)
            print("pitch : " + str(pitch))

        elif (isinstance(event, midi.NoteOffEvent)):
            wiringpi.softToneWrite(outpin, 0)

        else:
            print("ignore this event : " + str(type(event)))

        return True
Beispiel #6
0
def playTone():
    wiringpi2.softToneWrite(PIN,FREQUENCY1)
    time.sleep(0.1)
    wiringpi2.softToneWrite(PIN,FREQUENCY2)
    time.sleep(0.2)
    wiringpi2.softToneWrite(PIN,0)

#while True:
#  playTone()
#  time.sleep(1)
Beispiel #7
0
#!/usr/bin/env python

import wiringpi2
from time import sleep

wiringpi2.wiringPiSetupGpio()

SPEAKER = 18

# Escala da 5° oitava
C = 523
D = 587
E = 659
F = 698
G = 783
A = 880
B = 987

C6 = 1046

wiringpi2.softToneCreate(SPEAKER)

for freq in [C, D, E, F, G, A, B, C6]:
    wiringpi2.softToneWrite(SPEAKER, freq)
    sleep(0.5)

wiringpi2.digitalWrite(SPEAKER, 0)
wiringpi2.pinMode(SPEAKER, 0)
exit(0)
Beispiel #8
0
#!/usr/bin/env python

import wiringpi2
from time import sleep

wiringpi2.wiringPiSetupGpio()

SPEAKER = 18

# Escala da 5° oitava
C = 523
D = 587
E = 659
F = 698
G = 783
A = 880
B = 987

C6 = 1046

wiringpi2.softToneCreate(SPEAKER)

for freq in [ C, D, E, F, G, A, B, C6 ]:
    wiringpi2.softToneWrite(SPEAKER, freq)
    sleep(0.5)

wiringpi2.digitalWrite(SPEAKER, 0)
wiringpi2.pinMode(SPEAKER, 0)
exit(0)
Beispiel #9
0
def buzz(freq, duration):
	wiringpi.softToneWrite(18, freq)
	time.sleep(duration)
	wiringpi.softToneWrite(18, 0)
Beispiel #10
0
def play(pin, scale, delay=0.2):
    wiringpi.softToneWrite(pin, scale)
    sleep(delay*2)
    wiringpi.softToneWrite(pin, 0)
    sleep(delay)
Beispiel #11
0
import RPi.GPIO as gpio
import time
import wiringpi2 as wiringpi

delay = 0.2
outpin = 4

gpio.setmode(gpio.BCM)
gpio.setup(outpin, gpio.OUT)

wiringpi.wiringPiSetupGpio()
wiringpi.softToneCreate(outpin)


wiringpi.softToneWrite(outpin, 523)
time.sleep(0.2)
wiringpi.softToneWrite(outpin, 0)
time.sleep(0.01)
wiringpi.softToneWrite(outpin, 523)
time.sleep(0.2)
wiringpi.softToneWrite(outpin, 0)
time.sleep(0.01)
wiringpi.softToneWrite(outpin, 523)
time.sleep(0.2)
wiringpi.softToneWrite(outpin, 0)
time.sleep(0.01)
wiringpi.softToneWrite(outpin, 523)
time.sleep(0.6)
wiringpi.softToneWrite(outpin, 0)
time.sleep(0.01)
wiringpi.softToneWrite(outpin, 415)
	def stop_warning(self):
		print('stopping warning')
		wiringpi.softToneCreate(GPIOPin.PIN_SOUND.value)
		wiringpi.softToneWrite(GPIOPin.PIN_SOUND.value, self.stop_frequency)
	def start_warning(self, warning_level):
		print('starting warning')
		if warning_level == WarningLevel.DANGEROUS_SITUATION_WARNING.value:
			wiringpi.softToneCreate(GPIOPin.PIN_SOUND.value)
			wiringpi.softToneWrite(GPIOPin.PIN_SOUND.value, self.frequenzy)
Beispiel #14
0
wiringpi2.pullUpDnControl(0, 1) # set pull UP resistor for pin 0 switch
wiringpi2.pinMode(1,1)          # Pin 1 for beeper, OUTPUT
wiringpi2.softToneCreate(3)     # initialize softTone on Pin 3

def beeper(beeps):
	"Beep all of the requested beeps in the beeps list"
	for i in beeps:
		wiringpi2.digitalWrite(1,1)	# beep on
		time.sleep(i)								# length of beep from beeps list
		wiringpi2.digitalWrite(1,0)	# beep off
		time.sleep(0.025)						# interval between beeps

def gotButton():
  "Double beeps after every button press from interrupt call"
  # beeper(twobeeps)
  print("Got a button press")
  return True

# Main Program
wiringpi2.wiringPiISR(0, 2, gotButton)
k=3
while k>0 :
	for i in sequence:
		print(i)
		wiringpi2.softToneWrite(3, i)
		time.sleep(0.5)
	beeper(onebeep)
	k-=1
time.sleep(0.5)
beeper(vbeep)