#!/usr/bin/env python # Author: Andrea Stagi <*****@*****.**> # Description: play a melody # Dependencies: None from nanpy import Tone melody = [[Tone.NOTE_C4, 4], [Tone.NOTE_G3, 8], [Tone.NOTE_G3, 8], [Tone.NOTE_A3, 4], [Tone.NOTE_G3, 4], [0, 4], [Tone.NOTE_B3, 4], [Tone.NOTE_C4, 4]] tone = Tone(4) for note in melody: tone.play(note[0], 1000 / note[1])
#!/usr/bin/env python # Author: Andrea Stagi <*****@*****.**> # Description: play a melody # Dependencies: None from nanpy import Tone melody = [[Tone.NOTE_C4, 4], [Tone.NOTE_G3, 8], [Tone.NOTE_G3, 8], [Tone.NOTE_A3, 4], [Tone.NOTE_G3, 4], [0, 4], [Tone.NOTE_B3, 4], [Tone.NOTE_C4, 4]] tone = Tone(4) for note in melody: tone.play(note[0] , 1000/note[1])
def run(self): tone = Tone(4) for i in range(5): tone.play(Tone.NOTE_C4, 250) time.sleep(0.1)
#Converting the time to distance inches = duration.get_distance() print(inches, end='') print(" inch") if inches < distance: print("DANGER, PLEASE REVERT BACK NOW!") board.digitalWrite(greenLed, board.LOW) board.digitalWrite(yellowLed, board.LOW) board.digitalWrite(redLed, board.HIGH) sleep(0.01) board.digitalWrite(redLed, board.LOW) sleep(0.01) board.digitalWrite(redLed, board.HIGH) Danger() sleep(0.01) tone.play(3000, 1) elif inches < (distance + 10): print("APPROACHING DANGER, PLEASE REVERT BACK") board.digitalWrite(greenLed, board.LOW) board.digitalWrite(redLed, board.LOW) board.digitalWrite(yellowLed, board.HIGH) YellowAnimation() sleep(0.01) board.digitalWrite(yellowLed, board.LOW) sleep(0.01) board.digitalWrite(yellowLed, board.HIGH) tone.stop() else: print("GOOD, STAY SAFE")
#Info on Tone function and pitches library: #https://www.arduino.cc/en/Tutorial/ToneMelody?from=Tutorial.Tone #Range CAN be approx. 0-5000 from nanpy import (ArduinoApi, SerialManager, Tone) from time import sleep #Connect to Arduino. Automatically finds serial port. connection = SerialManager() speaker = 5 tone = Tone(speaker, connection) a = ArduinoApi(connection) a.pinMode(speaker, a.OUTPUT) #Setup speaker pin while True: for i in range(300, 1650[, 50]): #For ever 50 tones from 300 to 1650 (forwards) tone.play(i, 1) #Play tone i sleep(0.1) for i in range(1650, 300[, 50]): #For ever 50 tones from 1650 to 30 (backwards) tone.play(i, 1) #Play tone i sleep(0.1)
buttonE = 7 #Definitions for notes are in tone library in Nanpy, can easily change names to simply "c", "d", etc. if needed c = Tone.NOTE_C6 d = Tone.NOTE_D6 e = Tone.NOTE_E6 a.pinMode(speaker, a.OUTPUT) #Setup speaker pin a.pinMode(buttonC, a.INPUT) #Setup buttonC a.pinMode(buttonD, a.INPUT) #Setup buttonD a.pinMode(buttonE, a.INPUT) #Setup buttonE while True: bc = a.digitalRead(buttonC) #Reading at buttonC bd = a.digitalRead(buttonD) #Reading at buttonD be = a.digitalRead(buttonE) #Reading at buttonE #If buttonC is pressed: if (bc == 1): tone.play(c, 1) #Play note c #If buttonD is pressed: elif (bd == 1): tone.play(d, 1) #Play note d #If buttonE is pressed: elif (be == 1): tone.play(e, 1) #Play note e tone.stop( #Stop note
def beep(): duration = request.json['duration'] tone = Tone(boardconfig.beep_pin) tone.play(Tone.NOTE_FS1, duration) return jsonify({'status': 'success'}), 200
def beep(): duration = request.json['duration'] tone = Tone(boardconfig.beep_pin) tone.play(Tone.NOTE_FS1 , duration) return jsonify({ 'status' : 'success' }), 200