def simon(): itr = 1 pattern = [1, 3, 2, 4, 4, 3, 1, 2, 4, 2] timer = 3 while True: for i in range(0, itr): time.sleep(0.3) pl.play_note(False, pattern[i], 0.7) response = ui.user_input_record(timer) note_array = [] for i in range(0, len(response)): if (response[i][0] != 0): note_array.append(response[i][0]) valid = cmp(pattern[0:itr], note_array) print pattern[0:itr] print note_array print valid if(valid == 0): if(itr<4): itr += 1 timer += .75 else: return True else: return False
def do_4(value, timestamp): if (value == 1): pl.play_note(True, 4, True) return [4, 'p', timestamp] else: pl.play_note(True, 4, False) return [4, 'r', timestamp]
def do_3(value, timestamp): if (value == 1): pl.play_note(True, 3, True) return [3, 'p', timestamp] else: pl.play_note(True, 3, False) return [3, 'r', timestamp]
def do_2(value, timestamp): if (value == 1): pl.play_note(True, 2, True) return [2, 'p', timestamp] else: pl.play_note(True, 2, False) return [2, 'r', timestamp]
def do_1(value, timestamp): if (value == 1): pl.play_note(True, 1, True) return [1, 'p', timestamp] else: pl.play_note(True, 1, False) return [1, 'r', timestamp]
def heartbeat_mode(time_interval): initialize_arms() pulse = False initial_time = time.time() while True: timestamp = time.time() - initial_time if (timestamp >= time_interval): print "heartbeat mode terminated." break output = hb.heartBeat(pulse) pulse = output[1] if (output[0] == True): print "heartbeat" play_note(False, 3, 0.1) time.sleep(0.01) initialize_arms() print "debugging::heartbeat_mode ends"
def user_input(timer): button_1 = mraa.Gpio(2) button_2 = mraa.Gpio(4) # virtual buttons button_1_out = mraa.Gpio(7) button_2_out = mraa.Gpio(8) button_1.dir(mraa.DIR_IN) button_2.dir(mraa.DIR_IN) # feed to Edison 2 button_1_out.dir(mraa.DIR_OUT) button_2_out.dir(mraa.DIR_OUT) initial_time = time.time() while True: timestamp = time.time() - initial_time if (timestamp >= timer): print "Manually mode terminated." break if (button_1.read() == 1): pl.play_note(True, 1, True) button_1_out.write(1) else: pl.play_note(True, 1, False) button_1_out.write(0) if (button_2.read() == 1): pl.play_note(True, 2, True) button_2_out.write(1) else: pl.play_note(True, 2, False) button_2_out.write(0) time.sleep(0.0005)
def robot_play(song, spb): initialize_arms() for note in song: play_note(False, note[0], note[1] * spb) initialize_arms()