def main(): # Instantiate an MMA7660 on I2C bus 0 myDigitalAccelerometer = upmMMA7660.MMA7660( upmMMA7660.MMA7660_I2C_BUS, upmMMA7660.MMA7660_DEFAULT_I2C_ADDR) ## Exit handlers ## # This function stops python from printing a stacktrace when you hit control-C def SIGINTHandler(signum, frame): raise SystemExit # This function lets you run code on exit, including functions from myDigitalAccelerometer def exitHandler(): print "Exiting" sys.exit(0) # Register exit handlers atexit.register(exitHandler) signal.signal(signal.SIGINT, SIGINTHandler) # place device in standby mode so we can write registers myDigitalAccelerometer.setModeStandby() # enable 64 samples per second myDigitalAccelerometer.setSampleRate(upmMMA7660.MMA7660.AUTOSLEEP_64) # place device into active mode myDigitalAccelerometer.setModeActive() x = upmMMA7660.new_intp() y = upmMMA7660.new_intp() z = upmMMA7660.new_intp() ax = upmMMA7660.new_floatp() ay = upmMMA7660.new_floatp() az = upmMMA7660.new_floatp() while (1): myDigitalAccelerometer.getRawValues(x, y, z) outputStr = ("Raw values: x = {0}" " y = {1}" " z = {2}").format(upmMMA7660.intp_value(x), upmMMA7660.intp_value(y), upmMMA7660.intp_value(z)) print outputStr myDigitalAccelerometer.getAcceleration(ax, ay, az) outputStr = ("Acceleration: x = {0}" "g y = {1}" "g z = {2}g").format(upmMMA7660.floatp_value(ax), upmMMA7660.floatp_value(ay), upmMMA7660.floatp_value(az)) print outputStr time.sleep(.5)
def alertAcc(message, buffer): global Alert myDigitalAccelerometer.getRawValues(x, y, z) valx = upmMMA7660.intp_value(x) valy = upmMMA7660.intp_value(y) valz = upmMMA7660.intp_value(z) buffer.append(str(valx) + "," + str(valy) + "," + str(valz)) if (valx * valx + valy * valy + valz * valz) < ACTIVITY_TRES: return False else: message.append(Alert.ACTIVE) return True
def alertAcc(message, buffer): global Alert myDigitalAccelerometer.getRawValues(x, y, z) valx = upmMMA7660.intp_value(x) valy = upmMMA7660.intp_value(y) valz = upmMMA7660.intp_value(z) buffer.append(str(valx) + "," + str(valy) + "," + str(valz)) if (valx*valx + valy*valy + valz*valz) < ACTIVITY_TRES: return False else: message.append(Alert.ACTIVE) return True
def main(): signal.signal(signal.SIGINT, SIGINTHandler) # place device in standby mode so we can write registers myDigitalAccelerometer.setModeStandby() # enable 64 samples per second myDigitalAccelerometer.setSampleRate(upmMMA7660.MMA7660.AUTOSLEEP_64) # place device into active mode myDigitalAccelerometer.setModeActive() x = upmMMA7660.new_intp() y = upmMMA7660.new_intp() z = upmMMA7660.new_intp() ax = upmMMA7660.new_floatp() ay = upmMMA7660.new_floatp() az = upmMMA7660.new_floatp() while (1): myDigitalAccelerometer.getRawValues(x, y, z) #print(x,y,z) outputStr = ("Raw values: x = {0}" " y = {1}" " z = {2}").format(upmMMA7660.intp_value(x), upmMMA7660.intp_value(y), upmMMA7660.intp_value(z)) var1 = int(upmMMA7660.intp_value(x)) var2 = int(upmMMA7660.intp_value(y)) var3 = int(upmMMA7660.intp_value(z)) print(output_command(var1, var2, var3))
def main_loop(ioloop, iot_client): ''' Main Loop :param ioloop: Tornado ioloop instance ''' devices = iot_client.getDevices() chord_ind = 0 xyz_count = 0 # check shake for 5 sec for shake_slot in range (0, 15): myDigitalAccelerometer.getRawValues(x, y, z) outputStr = ("Raw values: x = {0}" " y = {1}" " z = {2}").format(upmMMA7660.intp_value(x), upmMMA7660.intp_value(y), upmMMA7660.intp_value(z)) if (abs(upmMMA7660.intp_value(x)) > SHAKE_THRESHOLD) or \ (abs(upmMMA7660.intp_value(y)) > SHAKE_THRESHOLD) or \ (abs(upmMMA7660.intp_value(z)) > SHAKE_THRESHOLD): print "value exceeded" print xyz_count xyz_count = xyz_count + 1 if (xyz_count >= xyz_thresh): print "increasing thresh" missing_devices = check_devices(devices) if len(missing_devices) > 0: print "Missing devices"+"\n" print missing_devices for chord_ind in range (0,15): print myBuzzer.playSound(chords[chord_ind], 100000) print "buzzing" #time.sleep(0.1) chord_ind += 1 data = create_message('Alert!', 'Missing item', True, '10.10.40.3') enqueue_message(data) myBuzzer.stopSound() xyz_count = 0 print outputStr time.sleep(0.05) print "loop over" xyz_count = 0 # Schedule next callback_time = 0 ioloop.call_at(ioloop.time() + callback_time, main_loop, ioloop, iot_client) return
def main_loop(ioloop, iot_client): ''' Main Loop :param ioloop: Tornado ioloop instance ''' devices = iot_client.getDevices() chord_ind = 0 xyz_count = 0 # check shake for 5 sec for shake_slot in range(0, 15): myDigitalAccelerometer.getRawValues(x, y, z) outputStr = ("Raw values: x = {0}" " y = {1}" " z = {2}").format(upmMMA7660.intp_value(x), upmMMA7660.intp_value(y), upmMMA7660.intp_value(z)) if (abs(upmMMA7660.intp_value(x)) > SHAKE_THRESHOLD) or \ (abs(upmMMA7660.intp_value(y)) > SHAKE_THRESHOLD) or \ (abs(upmMMA7660.intp_value(z)) > SHAKE_THRESHOLD): print "value exceeded" print xyz_count xyz_count = xyz_count + 1 if (xyz_count >= xyz_thresh): print "increasing thresh" missing_devices = check_devices(devices) if len(missing_devices) > 0: print "Missing devices" + "\n" print missing_devices for chord_ind in range(0, 15): print myBuzzer.playSound(chords[chord_ind], 100000) print "buzzing" #time.sleep(0.1) chord_ind += 1 data = create_message('Alert!', 'Missing item', True, '10.10.40.3') enqueue_message(data) myBuzzer.stopSound() xyz_count = 0 print outputStr time.sleep(0.05) print "loop over" xyz_count = 0 # Schedule next callback_time = 0 ioloop.call_at(ioloop.time() + callback_time, main_loop, ioloop, iot_client) return
def turn(request): # signal.signal(signal.SIGINT, SIGINTHandler) myDigitalAccelerometer = upmMMA7660.MMA7660( upmMMA7660.MMA7660_I2C_BUS, upmMMA7660.MMA7660_DEFAULT_I2C_ADDR); # place device in standby mode so we can write registers myDigitalAccelerometer.setModeStandby() # enable 64 samples per second myDigitalAccelerometer.setSampleRate(upmMMA7660.MMA7660.AUTOSLEEP_1) # place device into active mode myDigitalAccelerometer.setModeActive() x = upmMMA7660.new_intp() y = upmMMA7660.new_intp() z = upmMMA7660.new_intp() ax = upmMMA7660.new_floatp() ay = upmMMA7660.new_floatp() az = upmMMA7660.new_floatp() if (1): myDigitalAccelerometer.getRawValues(x, y, z) #print(x,y,z) outputStr = ("Raw values: x = {0}" " y = {1}" " z = {2}").format(upmMMA7660.intp_value(x), upmMMA7660.intp_value(y), upmMMA7660.intp_value(z)) var1 = int(upmMMA7660.intp_value(x)) var2 = int(upmMMA7660.intp_value(y)) var3 = int(upmMMA7660.intp_value(z)) print(output_command(var1, var2, var3)) #time.sleep(.5) return HttpResponse("New Value Here")
def run_control_loop(): chord_ind = 0 xyz_count = 0 # check shake for 5 sec for shake_slot in range (0, 15): myDigitalAccelerometer.getRawValues(x, y, z) outputStr = ("Raw values: x = {0}" " y = {1}" " z = {2}").format(upmMMA7660.intp_value(x), upmMMA7660.intp_value(y), upmMMA7660.intp_value(z)) if (abs(upmMMA7660.intp_value(x)) > SHAKE_THRESHOLD) or \ (abs(upmMMA7660.intp_value(y)) > SHAKE_THRESHOLD) or \ (abs(upmMMA7660.intp_value(z)) > SHAKE_THRESHOLD): print "value exceeded" print xyz_count xyz_count = xyz_count + 1 if (xyz_count >= xyz_thresh): print "increasing thresh" devices = [{'id': 0, 'mac': "5C:E8:EB:7B:87:45", 'name': 'cellphone0'}, {'id': 1, 'mac': "00:00:00:00:00:00", 'name': 'cellphone1'}] missing_devices = bluescan.check_devices(devices) if len(missing_devices) > 0: print "Missing devices"+"\n".join(missing_devices) for chord_ind in range (0,15): print myBuzzer.playSound(chords[chord_ind], 100000) print "buzzing" #time.sleep(0.1) #chord_ind = (chord_ind + 1) % 2 chord_ind += 1 myBuzzer.stopSound() xyz_count = 0 print outputStr time.sleep(0.05) print "loop over" xyz_count = 0
myDigitalAccelerometer.setSampleRate(upmMMA7660.MMA7660.AUTOSLEEP_64) # place device into active mode myDigitalAccelerometer.setModeActive() x = upmMMA7660.new_intp() y = upmMMA7660.new_intp() z = upmMMA7660.new_intp() ax = upmMMA7660.new_floatp() ay = upmMMA7660.new_floatp() az = upmMMA7660.new_floatp() while (1): myDigitalAccelerometer.getRawValues(x, y, z) outputStr = ("Raw values: x = {0}" " y = {1}" " z = {2}").format(upmMMA7660.intp_value(x), upmMMA7660.intp_value(y), upmMMA7660.intp_value(z)) print outputStr myDigitalAccelerometer.getAcceleration(ax, ay, az) outputStr = ("Acceleration: x = {0}" "g y = {1}" "g z = {2}g").format(upmMMA7660.floatp_value(ax), upmMMA7660.floatp_value(ay), upmMMA7660.floatp_value(az)) print outputStr time.sleep(.5)
y = upmMMA7660.new_intp() z = upmMMA7660.new_intp() ax = upmMMA7660.new_floatp() ay = upmMMA7660.new_floatp() az = upmMMA7660.new_floatp() while (1): myDigitalAccelerometer.getRawValues(x, y, z) #print(x,y,z) outputStr = ("Raw values: x = {0}" " y = {1}" " z = {2}").format(upmMMA7660.intp_value(x), upmMMA7660.intp_value(y), upmMMA7660.intp_value(z)) var1 = int(upmMMA7660.intp_value(x)) var2 = int(upmMMA7660.intp_value(y)) var3 = int(upmMMA7660.intp_value(z)) print(output_command(var1, var2, var3)) # time.sleep(.5)
# enable 64 samples per second myDigitalAccelerometer.setSampleRate(upmMMA7660.MMA7660.AUTOSLEEP_64) # place device into active mode myDigitalAccelerometer.setModeActive() x = upmMMA7660.new_intp() y = upmMMA7660.new_intp() z = upmMMA7660.new_intp() ax = upmMMA7660.new_floatp() ay = upmMMA7660.new_floatp() az = upmMMA7660.new_floatp() while (1): myDigitalAccelerometer.getRawValues(x, y, z) outputStr = ("Raw values: x = {0}" " y = {1}" " z = {2}").format(upmMMA7660.intp_value(x), upmMMA7660.intp_value(y), upmMMA7660.intp_value(z)) print outputStr myDigitalAccelerometer.getAcceleration(ax, ay, az) outputStr = ("Acceleration: x = {0}" "g y = {1}" "g z = {2}g").format(upmMMA7660.floatp_value(ax), upmMMA7660.floatp_value(ay), upmMMA7660.floatp_value(az)) print outputStr time.sleep(.5)
z = upmMMA7660.new_intp() midi_out = rtmidi.MidiOut() # get midi and open port midi_out.open_port(0) midi_out.send_message([0xC0, 92]) # programme change - bowed glass midi_out.send_message([0xB0, 65, 127]) # portamento on midi_out.send_message([0xB0, 5, 30]) # portamento time can be varied try: while True: myDigitalAccelerometer.getRawValues(x, y, z) rawNote = upmMMA7660.intp_value(x) # reads left to right value rawVol = upmMMA7660.intp_value(z) # reads backwards and forwards value if rawNote < -25: # avoids going out of range rawNote = -25 if rawVol < -25: rawVol = -25 note = int((rawNote + 25) * 2.4) # value ranges from -25 to 25 so this to # convert to midi value on range 0 - 127 vol = int((rawVol + 25) * 2.4) # print 'note', note, 'volume', vol # only if you need to see what's happening midi_out.send_message([0x90, note, vol]) time.sleep(.1) # can be varied to taste