def scope(cv, x, step_x, id): global cvjob global durchgang global linedrop def measure_point(): while not GPIO.input(11): GPIO.output(9, 1) u1 = 0 u2 = 0 for i in range(10000): if GPIO.input(11): GPIO.output(9, 0) u1 = u1 + faktor #u1=u1+1 else: GPIO.output(9, 1) u2 = u2 + faktor #u2=u2+1 GPIO.output(9, 0) spannung = (nulloffset + u1 - u2) / 2000 #print("Spannung: ", spannung, " u0: ",(((u1 - u2) * 1000 / 100000) + 100)) return spannung #ende measure_point() def dbv_coordinate(V): Unull = 1 if V <= 0: V = 0.0001 dBV = 20 * math.log10(V / Unull) if dBV < -20: dBV = -19.9 elif dBV > 20: dBV = 19.9 #print("Spannung: ", V," dBV: ",dBV," Coord: ",(h/2-(dBV*20))) return (h / 2 - (dBV * 20)) #ende dbv_coordiante(dBV) def frequenz_koord(freq): #Dekade feststellen lfreq = 0 m = 0 if freq < 100: m = 0 lfreq = freq / 10 elif freq < 1000: m = 1 lfreq = freq / 100 elif freq < 10000: m = 2 lfreq = freq / 1000 elif freq <= 20000: m = 3 lfreq = freq / 10000 try: logwert = math.log10(lfreq) except: print("freq: ", freq, " lfreq: ", lfreq, " m: ", m, " logwert: ", logwert, " xwert: ", xwert) raise xwert = wh * logwert + (wh * m) #print ("freq: ",freq," lfreq: ",lfreq," m: ",m," logwert: ",logwert," xwert: ",xwert) return round(xwert) #ende frequenz_koord(freq) korr_faktor = 1.0 try: korr_faktor = float(korr_var.get()) except: print("Keine gültige Zahl: ", korr_var.get()) korr_faktor = 1.0 korr_var.set("1.0") if korr_faktor > 4 or korr_faktor <= 0: print("Keine gültige Zahl: ", korr_var.get()) korr_faktor = 1.0 korr_var.set("1.0") if x < len(freqliste): if id: last_y = cv.coords(id)[-1] else: if linedrop == 1: cv.delete("line_point" + str(durchgang)) #Linie wieder löschen linedrop = 0 last_y = h / 2 #x += step_x #Hier Ton erzeugen und dann Messen anschließend Frequenz erhoehen step_x entsprechend erhoehen # id = cv.create_line(x-step_x, last_y , x, measure_point()*2, fill = "black", tag="line_point", width=2) counter.set("Frequenz: " + str(freqliste[x])) old_x = 0 try: SoundPlayer.playTone(freqliste[x], 2, False, dev) #hier auch Zeit einstellen #SoundPlayer.playTone(300, 2, False, dev) mp = 0 messcounter = 0 #Mittelwert mess_liste = [] #Liste while SoundPlayer.isPlaying(): #print("Warte:..",SoundPlayer.isPlaying()) #mp += measure_point() #Mittelwert messcounter += 1 #Mittelwert mess_liste.append(measure_point()) #print("Sound ",freqliste[x]," Hz") #mp=mp/messcounter #Mittelwert bilden #mess_liste.remove(max(mess_liste)) #mess_liste.remove(min(mess_liste)) #messcounter -= 2 mp = median(mess_liste) #DEBUG Ausgaben #print("Listenlänge: ",len(mess_liste)," Max: ",max(mess_liste)," Min: ",min(mess_liste), "Mid: ",mp) old_x = x - step_x if old_x < 0: old_x = 0 messwert.set("Messwert: " + str(round(mp, 2)) + "V") messpunkte.set("Messpunke: " + str(messcounter)) id = cv.create_line(frequenz_koord(freqliste[old_x]), last_y, frequenz_koord(freqliste[x]), dbv_coordinate(mp * korr_faktor), fill=linienfarbe[durchgang], tag="line_point" + str(durchgang), width=2) x += step_x except: print("Exception x:", x, "old_x: ", old_x) raise else: # hier auch Frequenz zurücksetzen x = 0 id = None durchgang += 1 # cv.after(20, scope, cv, x, step_x, id) if startstop == 1 and durchgang < len(linienfarbe): cvjob = cv.after(20, scope, cv, x, step_x, id) else: print("Gestoppt!")
# Sound2b.py from soundplayer import SoundPlayer import time # Sine of 1000 Hz during 5 s, non-blocking, device 1 SoundPlayer.playTone(1000, 5, False, 1) n = 0 while SoundPlayer.isPlaying(): print "playing #", n time.sleep(1) n += 1 print "done"
# Sound2b.py from soundplayer import SoundPlayer # Sine tone during 0.1 s, blocking, device 0 dev = 0 SoundPlayer.playTone(900, 0.1, True, dev) # 900 Hz SoundPlayer.playTone(800, 0.1, True, dev) # 600 Hz SoundPlayer.playTone(600, 0.1, True, dev) # 600 Hz print "done"
# Sound2a.py from soundplayer import SoundPlayer import time # Sine tone during 0.1 s, blocking, device 0 dev = 0 SoundPlayer.playTone(900, 0.1, True, dev) # 900 Hz SoundPlayer.playTone(800, 0.1, True, dev) # 600 Hz SoundPlayer.playTone(600, 0.1, True, dev) # 600 Hz time.sleep(1) SoundPlayer.playTone([900, 800, 600], 5, True, dev) # 3 tones together print "done"
] # enter file name name = raw_input('Enter name: ') gender = raw_input('Enter Gender: ') print(gender + ', name: ' + name) # run down while len(freqList) > 0: freqListLength = len(freqList) newTestFreq = random.randint(0, freqListLength - 1) testFreq = freqList[newTestFreq] freqList.pop(newTestFreq) #play Freq SoundPlayer.playTone(testFreq, 1, True, 0) #turn led on GPIO.output(27, GPIO.HIGH) while True: input_state1 = GPIO.input(23) if input_state1 == False: print('Yes ' + testFreq) x = 'yes' #time.sleep(0.4) break input_state2 = GPIO.input(17) if input_state2 == False: print('No ' + testFreq) x = 'no' #time.sleep(0.4) break