def do_steps(): global steps_queue if steps_queue.qsize() == 0: return steps = steps_queue.get() if (steps > 0): step_fun = forward_one_step n = steps else: step_fun = backward_one_step n = -steps freq = led.get_frequency(config.LED_PORCH) dc = led.get_duty_cycle(config.LED_PORCH) status = led.get_status(config.LED_PORCH) led.turn_on(config.LED_PORCH, 2, 50) gpio_lock.acquire() for i in range(0, n): step_fun(0.01) set_motor_input(0, 0, 0, 0) gpio_lock.release() if status == 'on': led.turn_on(config.LED_PORCH, freq, dc) else: led.turn_off(config.LED_PORCH) status_notify()
def trigger(self): bus = smbus.SMBus(1) shot = 0 status = True while True: #Parameters for write_byte_data #1. Address of the device #2. Communication data - active mode control register #3. Our data - 0 (standby mode) or 1 (active) bus.write_byte_data(0x1D, 0x2A, 1) #Read from the status register, real-time status register 0x00 #Data returned will be an array #Contents of 7 bytes read and stored in data array represent: #status (ignore), MSBx, LSBx, MSBy, LSBy, MSBz, LSBz data = bus.read_i2c_block_data(0x1D, 0x00, 7) number_of_bits = 16 MSB_z = data[5] LSB_z = data[6] zAccl = (MSB_z * 256 + LSB_z) / number_of_bits if zAccl > 2047: zAccl -= 4096 # if z acceleration changes by some great amount prev_z = 1000 if abs((prev_z - zAccl) / zAccl) >= 1.0: ### Change this bus.write_byte_data(0x1D, 0x2A, 0) # record GPS for 1 second. with open("/home/pi/SeisNode/data/shots.csv" % shot, "a+") as writefile: print("Trigger") led.turn_on() writer = csv.writer(writefile) if shot == 0: writer.writerow([ "Shot", "Time", "Lat", "Lat Err", "Lon", "Lon Err", "Alt", "Alt Err" ]) start = time.time() while time.time() - start < 1: data = self.collect_gps() data = np.concatenate([[shot], data]) writer.writerow(data) time.sleep(0.2) writefile.flush() writefile.close() shot += 1 time.sleep(30) led.turn_off() prev_z = 1000 status = True continue status = False prev_z = zAccl def collect_data(self): pass
def on_socket_connect_ack(self, args): print 'on_socket_connect_ack: ', args if self.first_connect == True: led.turn_on(config.LED_LIVING, 1, 100) #socktio connected self.first_connect = False self.socketIO.emit('connect', {'appkey': config.APPKEY, 'customid': config.CUSTOMID})
def ledOn(x, blink=False): '''to contrl led on or blink for 1 second, x should be within [0,8]''' byte = led.translate_led_to_byte(x) if blink: led.blink(byte) else: led.turn_on(byte)
def do_steps(): global steps_queue if steps_queue.qsize() == 0: return; steps = steps_queue.get() if (steps > 0): step_fun = forward_one_step n = steps else: step_fun = backward_one_step n = -steps freq = led.get_frequency(config.LED_PORCH) dc = led.get_duty_cycle(config.LED_PORCH) status = led.get_status(config.LED_PORCH) led.turn_on(config.LED_PORCH, 2, 50) gpio_lock.acquire() for i in range(0, n): step_fun(0.01) set_motor_input(0, 0, 0, 0) gpio_lock.release() if status == 'on': led.turn_on(config.LED_PORCH, freq, dc) else: led.turn_off(config.LED_PORCH) status_notify()
def on_socket_connect_ack(self, args): print 'on_socket_connect_ack: ', args if self.first_connect == True: led.turn_on(config.LED_LIVING, 1, 100) #socktio connected self.first_connect = False self.socketIO.emit('connect', { 'appkey': config.APPKEY, 'customid': config.CUSTOMID })
def main(): global player global messenger signal.signal(signal.SIGTERM, sig_handler) #signal.signal(signal.SIGINT, sig_handler) led.change_notify = change_notify stepper_motor.change_notify = change_notify led.change_notify = change_notify led.turn_on(config.LED_LIVING, 1, 50) #checking network led.turn_on(config.LED_BEDROOM, 1, 100) led.turn_on(config.LED_PORCH, 1, 100) while True: if is_network_ok(): break time.sleep(2) led.turn_on(config.LED_LIVING, 4, 50) #network is ok, connecting socktio player = Player(change_notify) messenger = Messenger(message_callback) while True: humtem_report() time.sleep(2)
def light_on(name, freq, dc): print('light_on: %s, %d, %d' % (name, freq, dc)) if name == 'living': led.turn_on(config.LED_LIVING, freq, dc) elif name == 'bedroom': led.turn_on(config.LED_BEDROOM, freq, dc) elif name == 'porch': led.turn_on(config.LED_PORCH, freq, dc)
beamheaders = {'Content-Type': "application/json"} response = requests.request("POST", beamurl, data=json.dumps(beampayload), headers=beamheaders) # Beam will pass back the response from the Anomaly Detector API, and we'll save it as JSON. azureresponse = json.loads(response.text) # This will print out isAnomaly: True or False depending on the boolean value returned. print("isAnomaly: ", azureresponse["isAnomaly"]) # If the value is True, and anomaly is detected and the LED will turn on. if azureresponse["isAnomaly"] == True: print("Anomaly detected. Turning on LED.") led.turn_on() # Otherwise, its False, and we'll keep it off. This will turn it off it was true previously as well. else: print("No anomaly detected. LED off.") led.turn_off() except Exception as e: print(e) print("***") # sleep until next loop time_to_wait = loop_start_time + interval - time.time() if time_to_wait > 0: time.sleep(time_to_wait)
def showChecking(): SAKS.digital_display.off() #digital display off led.turn_on(0x0c)
#show the index of the site, +1 offset to make it more readable SAKS.digital_display.show("%04d" % (i + 1)) #use num of leds to show the delay level measured in ms if delay is not None: if delay <= 250: #(<250ms) ledOn(1) elif delay <= 500: #(<500ms) ledOn(2) elif delay <= 1000: ledOn(3) elif delay <= 1500: ledOn(4) elif delay <= 2000: ledOn(5) else: ledOn(6) else: #alarm with a beep and blink all light if (beep_flag): beeper.beep = True led.blink(0xf0) except Exception, e: traceback.print_exc() except KeyboardInterrupt: pass finally: beeper.stop = True beeper.join() SAKS.digital_display.off() #digital display off led.turn_on(0x00)
def on_message(client, userdata, message): print('message received!') payload = json.loads(message.payload) color = payload['value'] led.turn_off_all() led.turn_on(color)