def __init__(self): self.client = paho.Client() self.client.on_message = self.on_message self.client.connect("test.mosquitto.org", 1883, 60) self.buzzer = upmBuzzer.Buzzer(5) self.chords = [upmBuzzer.SI, upmBuzzer.SI]
def correct(): # Create the buzzer object using GPIO pin 5 buzz = upmBuzzer.Buzzer(5) buzz.playSound(chords[0], 100000) time.sleep(0.3) buzz.playSound(chords[2], 100000) time.sleep(0.3) del buzz
def play_sound(time, sound=0): # Create the buzzer object using GPIO pin 3 buzzer = upmBuzzer.Buzzer(3) chords = [ upmBuzzer.DO, upmBuzzer.RE, upmBuzzer.MI, upmBuzzer.FA, upmBuzzer.SOL, upmBuzzer.LA, upmBuzzer.SI, upmBuzzer.DO, upmBuzzer.SI ] # Play buzzer for time seconds buzzer.playSound(chords[sound], 1000000 * int(time + 0.5)) buzzer.stopSound()
def setupDev(self): ''' Setup device ''' print "[INFO] Setting up device" try: #@INIT Sensor self.buzzer = upmBuzzer.Buzzer(5) self.productcode = self.getProductCode() if (not self.productcode): return False return True except Exception: traceback.print_exc() self.cleanupDev() return False
def __init__(self): self.buzzer = upmBuzzer.Buzzer(0) self.chords = [ upmBuzzer.DO, upmBuzzer.RE, upmBuzzer.MI, upmBuzzer.FA, upmBuzzer.SOL, upmBuzzer.LA, upmBuzzer.SI, 1900, 1725, 1533, 1361, 1283, 1140, 1011, 952, 845, 748, 663, 624, 552, 488, 458, 405, 357, 314, 294, 258, 226 ] self.chords2 = [ upmBuzzer.DO, upmBuzzer.RE, upmBuzzer.MI, upmBuzzer.FA, upmBuzzer.SOL, upmBuzzer.LA, upmBuzzer.SI, 1900, 1725, 1533, 1361, 1283, 1140, 1011, 952, 845, 748, 663, 624, 552, 488, 458, 405, 357, 314, 294, 258, 226 ] self.buzzer.stopSound() self.buzzer.setVolume(0.01)
def main(): lcd = LCD() lbutton = Button(2) rbutton = Button(3) timesel = TimeSelector() buzzer = pyupm_buzzer.Buzzer(5) buzzer.playSound(0, 200000) lcd.setColor(255, 0, 0) while True: try: ride = look_for_ride(lcd) print ride buzzer.playSound(chords[0], 200000) buzzer.playSound(0, 200000) button = N_BUTTON show_ride((lbutton, rbutton), lcd, ride) while button == N_BUTTON: button = get_button(lbutton, rbutton, 0.2) time.sleep(0.5) if button == L_BUTTON: #They Clicked Accept show_accept_ride(lcd, ride) while True: year = 2015 - int(timesel.abs_deg() / 5) print year send_status(year) button = get_button(lbutton, rbutton, timeout=1) if button == L_BUTTON: #Trip Endded break else: #They Click Decline continue except: pass
import time import pyupm_buzzer as upmBuzzer #Inicializa buzzer en 6 buzzer = upmBuzzer.Buzzer(6) buzzer.stopSound() buzzer.setVolume(0.05) buzzer.playSound(upmBuzzer.RE, 900000) time.sleep(0.1) buzzer.playSound(upmBuzzer.RE, 130000) time.sleep(0.1) buzzer.playSound(upmBuzzer.SOL, 130000) time.sleep(0.1) buzzer.playSound(upmBuzzer.RE, 130000) time.sleep(0.1) buzzer.playSound(upmBuzzer.SI, 500000) time.sleep(0.1)
else: # Stop the buzzer. buzzer.stopSound() # MQTT server address. mqtt_server = "mqtt.relayr.io" # MQTT credentials. mqtt_credentials = { "user": "******", "password": "******", "clientId": "<your client ID>", "topic": "<your MQTT topic>" } # Instantiate a buzzer object with digital pin D5 as an output. buzzer = upm_buzzer.Buzzer(5) buzzer.stopSound() buzzer.setVolume(0.01) # Initialize the MQTT client. client = paho.Client() # Set the MQTT username and password. client.username_pw_set(mqtt_credentials['user'], mqtt_credentials['password']) # Register a 'on_connect' callback. client.on_connect = on_connect # Register a callback for received messages. client.on_message = on_message # Connect to the MQTT broker through port 1883 (no SSL) and timeout of 60s. client.connect(mqtt_server, 1883, 60) # Start a blocking network loop. client.loop_forever()
from datetime import datetime import pytz ###### Setting up at start LcdWidth = 16 myLcd = lcd.Jhd1313m1(0, 0x3E, 0x62) myLcd.clear() myLcd.setColor(0x33, 0x33, 0x33) led = mraa.Gpio(4) led.dir(mraa.DIR_OUT) # using GPIO pin 5, has to be a PWM capable pin buzzer = upmBuzzer.Buzzer(5) buzzerVolume = 0.125 buzzer.setVolume(0) ###### End setting up def getColoursFromText(text): """Calculate RGB value from first three bytes of the hash value of a string (using SHA-256) """ h = hashlib.sha256() h.update(text) r, g, b = int(h.hexdigest()[0:2], 16), int(h.hexdigest()[2:4], 16), int(h.hexdigest()[4:6], 16)
# ------------- GROVE BUZZER ------------- # # Basic sample using UPM module for the # # Grove buzzer v1.2 # # Daniela Plascencia | [email protected] # # The UPM module for this buzzer allows the # user to play chords or frequencies. # Refer to the API for more info # http://iotdk.intel.com/docs/master/upm/python/pyupm_buzzer.html import time import pyupm_buzzer as upmBuzzer buzzer = upmBuzzer.Buzzer(5) # Instances the buzzer and sets it # in digital out 5 # Play a note for one second and then stop print buzzer.playSound(upmBuzzer.DO, 1000000)
def get_actuator(self): return pyupm_buzzer.Buzzer(self.pin)
def config_buzzer(): # Create the buzzer object using GPIO pin 5 buzzer = upmBuzzer.Buzzer(5) buzzer.stopSound() buzzer.setVolume(0) return buzzer
def __init__(self): # self.buzzer = mraa.Pwm(5) self.buzzer = upmBuzzer.Buzzer(5) self.buzzer.stopSound()
import time from flask import Flask import pyupm_buzzer as upm_buzzer from settings import windmill_pin, buzzer_pin, led_pin app = Flask(__name__) windmill = mraa.Gpio(windmill_pin) windmill.dir(mraa.DIR_OUT) buzzer = upm_buzzer.Buzzer(buzzer_pin) buzzer.stopSound() buzzer.setVolume(0.9) led = mraa.Gpio(led_pin) led.dir(mraa.DIR_OUT) @app.route('/windmill/start', methods=['POST']) def start_windmill(): windmill.write(1) return json.dumps({'status': 0}) @app.route('/windmill/stop', methods=['POST']) def stop_windmill():