Exemple #1
0
#!/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])
Exemple #2
0
#!/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)
for b in range(56, 63):
    for x in range(0, 7):
        lineAnim(b, x)

my_led = ResetPixels()

for b in reversed(range(295, 303)):
    for x in range(0, 8):
        lineAnimRev(b, x)

my_led = ResetPixels()

#Taking reading on echo pin
#Initialise Sensor Pins
duration = Ultrasonic(echoPin, trigPin, True, connection=connection)
tone = Tone(alarm, connection=connection)
#Initialise the leds Pins
board.pinMode(greenLed, board.OUTPUT)
board.pinMode(redLed, board.OUTPUT)
board.pinMode(yellowLed, board.OUTPUT)
#Default LED
board.digitalWrite(greenLed, board.HIGH)
board.digitalWrite(yellowLed, board.LOW)
board.digitalWrite(redLed, board.LOW)
while True:
    try:

        #Converting the time to distance
        inches = duration.get_distance()
        print(inches, end='')
        print(" inch")
Exemple #5
0
#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)
Exemple #6
0
from nanpy import (ArduinoApi, SerialManager, Tone)
from time import sleep

#Connect to Arduino. Automatically finds serial port.
connection = SerialManager()

speaker = 14  #AO on Arduino
tone = Tone(speakerpin, connection)     #Setting "tone" to mean using the "speaker" pin on the "connection". See tone library in Nanpy 
a = ArduinoApi(connection)

buttonC = 5
buttonD = 6
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):
Exemple #7
0
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