pyb.delay(100) tic = pyb.millis() # mark time now in msec # read the characters into a list, intialise stuff movelist = readlist('g7_choreo2.txt') counter = 0 # print(movelist) # for debugging # real-time program loop try: while True: # Main program loop if mic.buffer_full( ): # semaphore signal from ISR - set if buffer is full b_LED.off() # flash off # Get instantaneous energy E = mic.inst_energy( ) # get the instantaneous energy from the microphone # compute moving sum of last 50 energy epochs sum_energy = sum_energy - e_buf[e_ptr] + E e_buf[e_ptr] = E # over-write earliest energy with most recent e_ptr = (e_ptr + 1) % M # increment e_ptr with wraparound - 0 to M-1 # Compute ratio of instantaneous energy/average energy c = E * M / sum_energy # Look for a beat if (pyb.millis() - tic > 500): # if more than 500ms since last beat if (c > BEAT_THRESHOLD) or (pyb.millis() - tic > 600): # look for a beat, or if not found, timeout tic = pyb.millis() # reset tic
u = pidc.get_pwm(pitch, pitch_dot) if u > 0: motor.A_forward( (abs(u)+motor_offset) * mWeight.report('A') ) motor.B_forward( (abs(u)+motor_offset) * mWeight.report('B') ) elif u < 0: motor.A_back( (abs(u)+motor_offset) * mWeight.report('A') ) motor.B_back( (abs(u)+motor_offset) * mWeight.report('B') ) #else: #motor.A_stop() #motor.B_stop() if mic.buffer_full(): # semaphore signal from ISR - set if buffer is full b_LED.off() # flash off # Get instantaneous energy E = mic.inst_energy() # compute moving sum of last 50 energy epochs sum_energy = sum_energy - e_buf[e_ptr] + E e_buf[e_ptr] = E # over-write earlest energy with most recent e_ptr = (e_ptr + 1) % M # increment e_ptr with wraparound - 0 to M-1 # Compute ratio of instantaneous energy/average energy c = E * M / sum_energy # Look for a beat if (pyb.millis() - tic2 > 500): # if more than 500ms since last beat if (c > BEAT_THRESHOLD) or (pyb.millis()-tic1 > 600): # look for a beat # look for a beat, or if not found, timeout tic2 = pyb.millis() # reset tic2 b_LED.on()# beat found, flash blue LED ON REPLACE THIS WITH THE MOVES # execute move function (if=='c' etc)
backward(abs(drive_signal * offset) + 5, move_left, move_right) tic = pyb.micros() if debug: oled.clear() oled.draw_text(0, 10, "Drive Signal: {}".format(drive_signal)) oled.draw_text(0, 40, "Robot pitch: {}".format(current_pitch)) oled.display() if micro.buffer_full: # semaphore signal from ISR - set if buffer is full b_LED.off() # Calculate instantaneous energy E = micro.inst_energy() # compute moving sum of last 50 energy epochs sum_energy = sum_energy - e_buf[e_ptr] + E e_buf[e_ptr] = E # over-write earlest energy with most recent e_ptr = (e_ptr + 1) % M # increment e_ptr with wraparound - 0 to M-1 # Compute ratio of instantaneous energy/average energy c = E * M / sum_energy if (pyb.millis() - tic_detect > 500): # if more than 500ms since last beat print(c) if (c > BEAT_THRESHOLD): # look for a beat print('I made it')