def Run(command): thresh = 5 while (True): if (command == 1): api.PlayAction(52) buzzer = Buzzer() buzzer.play(4) print('Plank') command = 0 thresh = 5 elif (command == 0): api.PlayAction(55) print('Crawl') cry = random.randint(1, thresh) thresh -= 1 print(cry) if (cry == 1): command = 2 print('Cry') FB = api.passAccelData(1) print(FB) if (FB > 440 or FB < 350): command = 4 elif (command == 2): FB = api.passAccelData(1) print('crying: ') print(FB) buzzer = Buzzer() buzzer.play(1) if (FB > 420 or FB < 360): command = 3 elif (command == 3): api.PlayAction(52) FB = api.passAccelData(1) buzzer = Buzzer() buzzer.play(2) while (FB > 420 or FB < 360): buzzer = Buzzer() buzzer.play(3) FB = api.passAccelData(1) print(FB) command = 1 elif (command == 4): for i in range(0, 10): buzzer = Buzzer() buzzer.play(1) print('Sorry...') command = 3
def main(): gpio_classes = [ ] # Add any GPIO class we use, so we can clean up at the end try: buzzerController = Buzzer() ledController = LED() gpio_classes.append(buzzerController) gpio_classes.append(ledController) sensor = UltraSonic() socket = ServerSocket() socket.setLightsUpdated(ledController.setState) sensor.setHandDetectedCallback(lambda: (buzzerController.playSound( ) or True) and socket.sendFlameState(True)) sensor.setHandRemovedCallback(lambda: socket.sendFlameState(False)) sensor.start() while True: time.sleep(1) except KeyboardInterrupt: print("Program stopped...") for g in gpio_classes: g.cleanup()
def start_beeping(self, key): if self.alarms.get(key) is not None: self.alarms[key]["is_beeping"] = True self.buzzer = Buzzer(manage_gpio=False) self.buzzer.start() log.info(f"Start beeping for key: {key}.") else: log.error(f"No alarm found for key {key}.")
def __init__(self, serial_port, baudrate): # App start moment in millis self.start_time = int(round(time.time() * 1000)) # Create smart grid table self.smart_grid_table = SmartGridTable() # Create buzzer self.buzzer = Buzzer() # Message buffer self.message_buffer = [] # Define message functions self.message_functions = { MessageTypes.TABLE_CONNECTED: self.table_connected, MessageTypes.MODULE_PLACED: self.module_placed, MessageTypes.NEIGHBOR_CHANGED: self.table_neighbor_changed, MessageTypes.CONFIG_CHANGED: self.module_config_changed, MessageTypes.FLOW_DISABLED: self.flow_disabled, MessageTypes.FLOW_CONFIG: self.send_flow_config, MessageTypes.COLOR_CHANGED: self.send_flow_color, MessageTypes.TIME_SYNC: self.send_time_sync, MessageTypes.RESET_TABLES: self.reset_table_sections, MessageTypes.BUZZER_ENABLE: self.buzzer_enabled, MessageTypes.POWER_BOUNDARIES_CHANGED: self.power_boundaries_changed, MessageTypes.SHUTDOWN_APP: self.shutdown_app } # Define send config and time sync timers self.send_flow_config_timer = start_daemon_timer(0, None, start=False) self.time_sync_timer = start_daemon_timer(SYNC_DELAY, self.need_time_sync_msg) # Create and start gateway connection (threaded) self.gateway_conn = GatewayConnector(self.add_message, serial_port, baudrate) start_daemon_thread(self.gateway_conn.start_serial_read, ()) log('--------GW CONN STARTED') # Create and start flask server (threaded) self.api = ApiServer(self.smart_grid_table, self.add_message) start_daemon_thread(self.api.run, ()) log('--------API STARTED') # Create and start GUI (threaded) self.gui = Gui(self.smart_grid_table, self.add_message) start_daemon_thread(self.gui.run, ()) log('--------GUI STARTED') log('--------RESETTING Table SectionS') self.need_reset_table_sections() # Start message handler in main thread log('--------START MESSAGE HANDLING') self.handle_messages()
def main(): GPIO_TRIGGER = 66 #P8.7 GPIO_ECHO = 67 #P8.8 PWM_PORT = 6 #P8.13 LPF_A = 0.5 MIN_DIST = 50.0 MAX_DIST = 150.0 DIST_RANGE = MAX_DIST - MIN_DIST MIN_FREQ = 220 MAX_FREQ = 880 FREQ_RANGE = MAX_FREQ - MIN_FREQ try: print("Press Ctrl+C to finish") meter = Ultrasonic(GPIO_TRIGGER, GPIO_ECHO) buzz = Buzzer(6) dist = meter.read() time.sleep(0.5) while True: distRead = meter.read() if distRead != Ultrasonic.OUT_OF_RANGE: dist += (distRead - dist) * LPF_A print("~ {0:.3f} cm".format(dist)) if dist > MIN_DIST and dist < MAX_DIST: freq = (((dist - MIN_DIST) / DIST_RANGE) * FREQ_RANGE) + MIN_FREQ buzz.playNote(freq, 0.5) else: time.sleep(0.5) else: print("Out of range!") time.sleep(0.5) except KeyboardInterrupt: print("\nCtrl+C pressed.") finally: print("Bye!") meter.cleanup() buzz.cleanup()
def test_alarm(self): d1 = datetime.date.today() t1 = datetime.datetime.today() for i, a in enumerate(self.config['Alarmas']): d2 = datetime.datetime.strptime(str(a["Last"]), "%Y-%m-%d").date() if d1 > d2: if t1.weekday() in a['Dias']: if t1.hour == a["Hora"] and t1.minute == a["Minuto"]: print("Es el momento de " + a["Nombre"]) self.config["Alarmas"][i]["Last"] = str( datetime.date.today()) print(self.config["Alarmas"][i]["Last"]) self.buzzerActivo = Buzzer(a, self)
def setup(config): # Comment the config entries you don't have/need config['temp_humidity'] = AdafruitTempHumidity(Adafruit_DHT.AM2302, '4') config['temp_humidity_save_file'] = '/home/pi/temp_humidity.csv' config['temp_humidity_save_interval'] = 30 #serial = spi(port=0, device=0, gpio=noop()) #device = max7219(serial) #seg = sevensegment(device) #config['led_display'] = LumaLedMatrix(seg) serial = spi(device=0, port=0, gpio_DC=23, gpio_RST=24) oled_device = sh1106(serial) config['oled'] = OLed(oled_device) config['oled'].contrast(0) config['oled'].start_loop() config['buzzer'] = Buzzer(PassiveBuzzer(16))
def main(): """Main setup and loop""" buzzer = Buzzer() logger = Logger(buzzer, 1) logger.info("Initialising reader") config = Config(logger) scanner = Scanner(config, logger) buzzer.ready() # Loop until either config is successfully downloaded, or a config card is # scanned err = True while err and not config.ready: buzzer.ready() err, _ = scanner.scan() if err: err = config.update_config() handler = Handler(logger, config) handler.get_assignments() logger.info("Ready") while True: scanner.wait() err, data = scanner.scan() if err: continue if data is True: handler.get_assignments() else: handler.send(data)
import json import requests import threading import time from pprint import pprint import paho.mqtt.client as mqtt from dataLoader import serverData, DANGER_THRESHOLD from detector import Detector from buzzer import Buzzer buzzer = Buzzer() detector = Detector() lock = threading.Lock() readings = [] def detector_callback(client, userdata, message): print("detector_callback: " + message.topic + " " + "\"" + str(message.payload, "utf-8") + "\"") with lock: if str(message.payload, "utf-8") == "ON": # Set the internal flag to start the detector print("starting the sensor") detector.stop_sensing = False elif str(message.payload, "utf-8") == "OFF": # Set the detector's internal flag to stop sensing detector.stop_sensing = True
from flask import Blueprint, redirect, url_for from buzzer import Buzzer from GPIO import GPIO_initialize bp_buzzer = Blueprint('buzzer', __name__, url_prefix='/buzzer') GPIO_initialize() buzz = Buzzer(22) @bp_buzzer.route('/on/<buzzer_name>') def buzzer_on(buzzer_name): buzz.on() return redirect(url_for('index')) @bp_buzzer.route('/off/<buzzer_name>') def buzzer_off(buzzer_name): buzz.off() return redirect(url_for('index'))
from buzzer import Buzzer from temperature import TemperatureSensor from light import LightSensor from movement import MovementSensor from morse import convertStrToMorse import RPi.GPIO as GPIO from threading import Thread app = Flask(__name__) socketio = SocketIO(app) #Utilisation d'une norme de nommage pour les broches GPIO.setmode(GPIO.BCM) GPIO.setwarnings(False) redLed = Led(18) greenLed = Led(24) buzzer = Buzzer(22) tempSensor = TemperatureSensor('28-01131a4f0da1') lightSensor = LightSensor(27) @app.route('/') def home(): temp = tempSensor.read_temp() return render_template('home.html', temp=temp) @app.route('/temp') def temp(): temp = tempSensor.read_temp() return str(temp)
import RPi.GPIO as GPIO import time from buzzer import Buzzer from button import Button Button(18) b = Buzzer(12) while 1: if GPIO.input(18): b.beep()
""" test_buzzer_notes.py - Exemple d'utilisation de Buzzer sur PYBStick Fiche produit: ---> https://shop.mchobby.be/fr/micropython/1830-pybstick-lite-26-micropython-et-arduino-3232100018303-garatronic.html ------------------------------------------------------------------------ History: 26 june 2020 - Meurisse D. - initial code """ from buzzer import Buzzer, NOTES from time import sleep bz = Buzzer() tempo = 300 # Play tempo note_duration = 2 # Duration of the note # Display available notes (space is for silent) print( ", ".join(NOTES.keys()) ) for note in NOTES.keys(): print( "Play note: %s " % note ) bz.note( note, tempo*note_duration ) # 600*1000uS per note sleep( 0.3 ) # Wait 300ms to ear each note # Silent bz.tone()
GPIO.cleanup() GPIO_PIR = 7 GPIO_BUTT = 19 GPIO_LED = 18 GPIO_BUZZ = 24 GPIO_TEMP = 4 TEMP_THRESH = 30 loop = True e1 = eventListener(0.05) e2 = eventListener(5) pir = PIR_sensor(GPIO_PIR) pir.initialize() temp_s = Temp_sensor() buzzer = Buzzer(GPIO_BUZZ) L22 = None times = 0 def pirCallback(): global times, buzzer times += 1 if (times >= 3): buzzer.stop() # print("motion") pass def buttCallback(pressed):
reflow_profiles = LoadProfiles(config['default_alloy']) temp_sensor = Sensor(hwspi=config['sensor_pins']['hwspi'], cs=config['sensor_pins']['cs'], miso=config['sensor_pins']['miso'], sck=config['sensor_pins']['sck'], offset=config['sensor_offset'], cache_time=int(1000 / config['sampling_hz'])) heater = machine.Signal(machine.Pin(config['heater_pins']['heater'], machine.Pin.OUT), invert=config['heater_pins']['heater_active_low']) heater.off() buzzer = Buzzer(config['buzzer_pin']) def measure_temp(): global TEMP_GUI_LAST_UPDATE while True: try: t = temp_sensor.get_temp() except Exception as e: t = str(e) gui.temp_update(t) gc.collect() utime.sleep_ms(int(1000 / config['display_refresh_hz'])) def buzzer_activate(): while True: if buzzer.song:
from gpiozero import LED, MotionSensor from buzzer import Buzzer leds = red, green, blue = [LED(pin) for pin in (18, 23, 24)] green.on() pir = MotionSensor(25) buzzer = Buzzer(8) try: while True: pir.wait_for_motion() buzzer.buzz(200, .2) green.off() while pir.motion_detected: for n in range(10): red.blink(.1, 0, 1, background=False) blue.blink(.1, 0, 1, background=False) green.on() except KeyboardInterrupt: pass for led in leds: led.off()
import sys sys.path.append('../src') from tact import Tact from led import Led from buzzer import Buzzer from time import sleep mybuzzer = Buzzer(18) mytact0 = Tact(21) mytact1 = Tact(20) myled = Led(16) song = [['c', 'c', 'g', 'g', 'a', 'a', 'g', 'f', 'f', 'e', 'e', 'd', 'd', 'c'], ['c', 'd', 'e', 'c', 'd', 'e', 'g', 'e', 'd', 'c', 'd', 'e', 'd']] index = 0 push = False scale = 2 count = 0 select = 0 switch = False scount = 0 try: while True: if select == 1: myled.on() else: myled.off()
return signals[index] class SonyBuzzMock(): @staticmethod def get_devices(): return [DeviceMock()] ## ## ## try: devices = SonyBuzzer.get_devices() #devices = SonyBuzzMock.get_devices() buzzer = Buzzer(devices) teams = ['A', 'B', 'C', 'D'] index = None for i, team in enumerate(teams): controller = buzzer.get_controller(0, i) print 'Team ', team controller.light_on(i) r = buzzer.read( 0, i, 0, timeout=4) # accepts read for controller i and button 0 controller.light_off(i) if r is not None: index = i print "Player OK" else:
#!/usr/bin/env python3 # -*- coding: utf-8 -*- from sound import Sound from buzzer import Buzzer from dc import DC from pumpe import Pumpe from barometer import Barometer soundModul = Sound('testSoundModul') soundModul.test() buzzerModul = Buzzer('testBuzzer') buzzerModul.test() #dualColorModul = DC('test dual Color') #dualColorModul.test() pumpe = Pumpe() pumpe.test() barometer = Barometer() barometer.test()
from temperature import TemperatureSensor from light import LightSensor from movement import MovementSensor from morse import convertStrToMorse import RPi.GPIO as GPIO from threading import Thread app = Flask(__name__) socketio = SocketIO(app) #Utilisation d'une norme de nommage pour les broches GPIO.setmode(GPIO.BCM) GPIO.setwarnings(False) redLed = Led(16) blueLed = Led(12) buzzer = Buzzer(14) tempSensor = TemperatureSensor('28-01131a3de1fd') lightSensor = LightSensor(27) @app.route('/') def home(): temp = tempSensor.read_temp() return render_template('home.html', temp=temp) @app.route('/temp') def temp(): temp = tempSensor.read_temp()
from board import Board from led import Led from rgb import RGB_led from button import Button from buzzer import Buzzer from pir import Pir from temp import Temperature from time import sleep rpi = Board() led = Led(rpi, 13) rgb = RGB_led(rpi, 20, 21, 16) button = Button(rpi, 22) buzzer = Buzzer(rpi, 24) button2 = Button(rpi, 7) pir = Pir(rpi, 14) ''' light = False while True: if button.pressed: if not light: led.led_on() light = True button.pressed = False elif light: led.led_off() light = False button.pressed = False ''' buz = False while True:
def main(): buz = Buzzer(6, S / 2.0) notes = [ # (B4,H), # (C5,Q), # (D5,Q), # (D5,Q), # (C5,Q), # (B4,Q), # (A4,Q), # (G4,Q), # (G4,Q), # (A4,Q), # (B4,Q), # (B4,H), # (A4,H), # (B4,H), # (C5,Q), # (D5,Q), # (D5,Q), # (C5,Q), # (B4,Q), # (A4,Q), # (G4,Q), # (G4,Q), # (A4,Q), # (B4,Q), # (A4,Q+E), # (G4,E), # (G4,H), # (A4,H), # (B4,Q), # (G4,Q), # (A4,Q), # (B4,E), # (C5,E), # (B4,Q), # (G4,Q), # (A4,Q), # (B4,E), # (C5,E), # (B4,Q), # (A4,Q), # (G4,Q), # (A4,Q), # (D4,H), # (B4,H), # (C5,Q), # (D5,Q), # (D5,Q), # (C5,Q), # (B4,Q), # (A4,Q), # (G4,Q), # (G4,Q), # (A4,Q), # (B4,Q), # (A4,Q+E), # (G4,E), # (G4,H), # # (M, W), # # (D4, H), # (G4, H), # (B4, H), # (D4, H), # (B4, H), # (G4, H), # (D4, H), # # (M, W), # # (G4, H), # (A4, H), # (F4, H), # (F3, H), # (C4, H), # # (M, W), # # (As4, H), # (C4, H), # (Gs4, H), # (Gs3, H), # (Ds4, H), # # (M, W), # (C5, H), (B4, Q), (A4, Q), (G4, Q), (F4, Q), (E4, Q), (D4, Q), (C4, W), # (M, W), # (C4, H), (D4, Q), (E4, Q), (F4, Q), (G4, Q), (A4, Q), (B4, Q), (C5, W) ] try: for note in notes: buz.playNote(note[0], note[1]) finally: buz.cleanup()
def print_file(filename): print "printing" os.system("lpr %s" % filename) buzzer = Buzzer(True) buzzer.buzz()
TRIG = 16 ECHO = 18 WARNINGLED = 38 DANGERLED = 40 GPIO.setup(12, GPIO.OUT) GPIO.setup(16, GPIO.OUT) GPIO.setup(18, GPIO.IN) GPIO.setup(38, GPIO.OUT) GPIO.setup(40, GPIO.OUT) # initialize components sensor = HCRS(TRIG, ECHO, 2) warningLed = LED(WARNINGLED) dangerLed = LED(DANGERLED) buzz = Buzzer(BUZZER, 1) # start all def buzzing(buzz): while buzz.status == "ON": buzz.blink() else: return try: thread.start_new_thread(buzzing, (buzz, )) while True: distance = sensor.read() if distance == -1:
class HelpPage(tk.Frame): def __init__(self, parent, controller): tk.Frame.__init__(self, parent) label = tk.Label(self, text="help page for all the penises: ") button_page = tk.Button(self, text="Home", anchor="sw", command=lambda: controller.show_frame(HomePage)) button_quit = tk.Button(self, text="quit", anchor="sw", command=self.quit) label.grid(row=0, column=0, pady=10, padx=10, sticky="w") button_page.grid(row=3, column=1, pady=10, padx=10, sticky="se") button_quit.grid(row=4, column=1, pady=10, padx=10, sticky="se") rpi = Board() sense = _SenseHat(rpi) pir = PIR(rpi, 6) # passing in board object and pin number of the pir buzz = Buzzer(rpi, 20) ldr = LDR(rpi, 21) app = App() app.mainloop() # buzzer pin = 20 # pir pin = 6 # ldr pin = 21
from max31855 import MAX31855 from oven_control import OvenControl reflow_profiles = LoadProfiles(DEFAULT_ALLOY) gui = GUI(reflow_profiles, config) temp_sensor = MAX31855(hwspi=TEMP_HWSPI, cs=TEMP_CS, miso=TEMP_MISO, sck=TEMP_SCK, offset=TEMP_OFFSET) oven = machine.Pin(OVEN_PIN, machine.Pin.OUT, value=0) buzzer = Buzzer(BUZZER_PIN) timer = machine.Timer(0) def measure_temp(): while True: try: temp_sensor.read_temp() except Exception: print('Error occurs when measuring temperature.') gui.temp_update(temp_sensor.get_temp()) utime.sleep_ms(500) def buzzer_activate(): while True: if buzzer.song:
compare = Signal(bool(0)) alarm_toggle = Signal(bool(1)) alarm_act = Signal(bool(0)) alarm_out = Signal(bool(0)) sev_seg_digit = Signal(intbv(0, min=0, max=128)) select_digit = Signal(intbv(0, min=0, max=64)) clkDriver = ClkDriver(clk1us) clock = Clock(clk1s, clk500ms, clk1ms, clk1us, reset) timblk = Timer(tim_secs1, tim_secs10, tim_mins1, tim_mins10, tim_hrs1, tim_hrs10, clk1s, clk500ms, set_time, set_hrs, set_mins, reset) alarm = Alarm(ala_mins1, ala_mins10, ala_hrs1, ala_hrs10, clk500ms, set_ala, set_hrs, set_mins, reset) compblk = AlarmCompare(tim_mins1, tim_mins10, tim_hrs1, tim_hrs10, ala_mins1, ala_mins10, ala_hrs1, ala_hrs10, compare) buz = Buzzer(alarm_act, alarm_out, clk1ms, alarm_toggle, compare, reset) outmux = Outmux(sev_seg_digit, select_digit, tim_secs1, tim_secs10, tim_mins1, tim_mins10, tim_hrs1, tim_hrs10, ala_mins1, ala_mins10, ala_hrs1, ala_hrs10, set_ala, clk1ms, reset) sim = Simulation(clkDriver, clock, timblk, alarm, compblk, buz, outmux) toVHDL(Clock, clk1s, clk500ms, clk1ms, clk1us, reset) toVHDL(Timer, tim_secs1, tim_secs10, tim_mins1, tim_mins10, tim_hrs1, tim_hrs10, clk1s, clk500ms, set_time, set_hrs, set_mins, reset) toVHDL(Alarm, ala_mins1, ala_mins10, ala_hrs1, ala_hrs10, clk500ms, set_ala, set_hrs, set_mins, reset) toVHDL(Buzzer, alarm_act, alarm_out, clk1ms, alarm_toggle, compare, reset) toVHDL(Outmux, sev_seg_digit, select_digit, tim_secs1, tim_secs10, tim_mins1, tim_mins10, tim_hrs1, tim_hrs10, ala_mins1, ala_mins10, ala_hrs1, ala_hrs10, set_ala, clk1ms, reset) #toVerilog(Timer, tim_secs1, tim_secs10, tim_mins1, tim_mins10, tim_hrs1, tim_hrs10, clk1s, clk500ms, set_time, set_hrs, set_mins, reset) #toVerilog(Clock, clk1s, clk500ms, clk1ms, clk1us, reset) #traceSignals(Clock, clk1s, clk500ms, clk1ms, clk1us, reset)
import sys sys.path.append('../src') from buzzer import Buzzer from time import sleep mybuzzer = Buzzer(12) scale = ['c', 'd', 'e', 'f', 'g', 'a', 'b'] for i in range(2,4): for tone in scale: mybuzzer.softtonewrite(tone, i) sleep(1)
def wrapper(*args, **kwargs): try: return func(*args, **kwargs) except Exception as e: log_and_restart(e) return wrapper try: logger.info('Initialize hardware') # init time RTC().datetime(tuple(now() + [0])) # init buzzer buzzer = Buzzer(pin=settings.PINS['buzzer']) # init sensors and fan tempsensor = Tempsensor(pin=settings.PINS['tempsensor']) tempsensor_aux = Tempsensor(pin=settings.PINS['tempsensor_aux']) fan = PWMFan(pin=settings.PINS['fan'], led_pin=settings.PINS['fan_led']) fan_controller = PIDFanTempController(fan, tempsensor, buzzer, settings.TARGET_TEMPERATURE) # init buttons # full throttle Toggle(pin=settings.PINS['full_throttle_toggle'], action=fan.full_throttle, cancel_action=fan.auto) # test Toggle(pin=settings.PINS['test_toggle'], action=buzzer.test_on, cancel_action=buzzer.test_off) try: # mount sd card
def __init__(self): self.beacon = Beacon() self.view = View(self) self.bluetoothThread = threading.Thread(target=self.refreshDataInView) self.alarmeThread = threading.Thread(target=self.manageAlarme) self.buzzer = Buzzer()