def main(): global lcd global inactivity_timer global motion_sensor global distance_sensor global lcd global buzzer global led global last_pullup_time global pullup_count_alltime global pullups_to_go global storage wiringpi.wiringPiSetupGpio() init_storage() inactivity_timer = InactivityTimer(wakeup, shutdown, config.SHUTDOWN_DELAY) motion_sensor = MotionSensor(wiringpi, config.MOTION, inactivity_timer.trigger) distance_sensor = DistanceSensor(wiringpi, config.SONIC_ECHO, config.SONIC_TRIG) lcd = Display(config.LCD_RS, config.LCD_E, config.LCD_D4, config.LCD_D5, config.LCD_D6, config.LCD_D7, config.LCD_K) buzzer = Buzzer(wiringpi, config.BUZZER) led = Led(wiringpi, config.LED_PIN) distance_resetted = True shutdown() while True: if inactivity_timer.is_active(): distance = distance_sensor.measure() distance_str = "{:13.2f}".format(distance) if config.DEBUG: print(distance_str + " cm") # if wiringpi.millis() % 5 == 0: # lcd.message(0, 0, distance_str + " cm") # only count a pullup if: # - distance is smaller than 5cm # - distance was resetted (athlete moved more than 20 cm away from sensor) # - last pullup was done more than 1 second ago if 0 < distance < config.COUNT_DISTANCE and distance_resetted and wiringpi.millis() > (last_pullup_time + config.RESET_TIME): buzzer.beep(5000) distance_resetted = False cnt = count_pullup() lcd.clear() lcd.message(0, 0, "Pullups: " + str(cnt).rjust(5)) lcd.message(0, 1, "2do2day: " + str(pullups_to_go).rjust(5)) elif distance > config.RESET_DISTANCE: distance_resetted = True delay_milli(100) inactivity_timer.loop() motion_sensor.sense() if config.DEBUG and inactivity_timer.is_active() == 1: print("shutting down in " + inactivity_timer.get_seconds_till_shutdown() + " seconds")
def count_pullup(): global pullup_count_today global pullups_to_go global pullup_count_alltime global last_pullup_time global storage storage.count_pullup() pullup_count_today += 1 pullup_count_alltime += 1 pullups_to_go -= 1 last_pullup_time = wiringpi.millis() return pullup_count_today
import wiringpi2 import sys OUTPUT = 1 PIN_TO_PWM = 1 # pin 1 to output pwm # wiringpi2.wiringPiSetup() wiringpi2.wiringPiSetupPhys() wiringpi2.pinMode(PIN_TO_PWM, OUTPUT) wiringpi2.softPwmCreate(PIN_TO_PWM, 0, 100) time = wiringpi2.millis() print "----------milliseconds-------------" print time print "-----------------------------------" time = wiringpi2.micros() print "----------microseconds-------------" print time print "-----------------------------------"
def getMsTicks(): """ Get number of milliseconds """ return wiringpi2.millis()
def await_dispenser_done(): timeout_time = millis() + dispenser_finish_wait_ms while GPIO.input(dispenser_busy_pin) == 0 and millis() < timeout_time: pass return GPIO.input(dispenser_busy_pin)
def await_dispenser_start(): timeout_time = millis() + dispenser_start_wait_ms while GPIO.input(dispenser_busy_pin) and millis() < timeout_time: pass return not GPIO.input(dispenser_busy_pin)
def main(): noleds = False noservos = False noimage = False nothreshold = False next_servo_update = 0 try: opts, args = getopt.getopt( sys.argv[1:], None, ["help", "noservos", "noleds", "noimage", "nothreshold"]) except getopt.GetoptError as err: usage() sys.exit(2) for option, value in opts: if option == "--noleds": noleds = True elif option == "--noservos": noservos = True elif option == "--noimage": noimage = True elif option == "--nothreshold": nothreshold = True elif option == "--help": usage() sys.exit(0) #setup camera capture print('Setting up webcam'), capture = cv2.VideoCapture(-1) #capture.set(cv2.CAP_PROP_FRAME_HEIGHT, 320); #capture.set(cv2.CAP_PROP_FRAME_WIDTH, 240); if (capture is not None): print('... OK') else: return # setup wiring pi and leds if noleds == False: print('Setting up wiring pi'), wiringpi.wiringPiSetup() wiringpi.pinMode(GREEN_PIN, 1) wiringpi.pinMode(RED_PIN, 1) print('... OK') else: print "Wiringpi setup skipped" # setup serial if noservos == False: print("Setting up serial connection to Arduino"), port = serial.Serial("/dev/ttyUSB0", baudrate=115200, timeout=3.0) if (port is not None): print('... OK') else: return else: print "Serial setup skipped" wiringpi.delay(16000) print "Starting object tracking" frames = 0 start_time = time.time() while True: diagonal, center_x, center_y = find_ball(capture, noimage, nothreshold) if noservos == False: update_servos(diagonal, center_x, center_y) if (read_servo_update(port)): next_servo_update = wiringpi.millis() + 100 if wiringpi.millis() > next_servo_update: send_servo_update(port) if noleds == False: update_leds(diagonal) frames += 1 currtime = time.time() numsecs = currtime - start_time fps = frames / numsecs sys.stdout.write("Found ball at: (%d, %d) " % (center_x, center_y) + " Deviation %d " % (90 - panServoAngle) + "Current FPS: %d \t\t\r\n" % fps) sys.stdout.flush() return
import wiringpi2 import sys OUTPUT = 1 PIN_TO_PWM = 1 #pin 1 to output pwm #wiringpi2.wiringPiSetup() wiringpi2.wiringPiSetupPhys() wiringpi2.pinMode(PIN_TO_PWM, OUTPUT) wiringpi2.softPwmCreate(PIN_TO_PWM, 0, 100) time = wiringpi2.millis() print "----------milliseconds-------------" print time print "-----------------------------------" time = wiringpi2.micros() print "----------microseconds-------------" print time print "-----------------------------------"
def main(): noleds = False noservos = False noimage = False nothreshold = False next_servo_update = 0 try: opts, args = getopt.getopt(sys.argv[1:], None, ["help","noservos","noleds","noimage","nothreshold"]) except getopt.GetoptError as err: usage() sys.exit(2) for option, value in opts: if option == "--noleds": noleds = True elif option == "--noservos": noservos = True elif option == "--noimage": noimage = True elif option == "--nothreshold": nothreshold = True elif option == "--help": usage() sys.exit(0) #setup camera capture print('Setting up webcam'), capture = cv2.VideoCapture(-1) #capture.set(cv2.CAP_PROP_FRAME_HEIGHT, 320); #capture.set(cv2.CAP_PROP_FRAME_WIDTH, 240); if (capture is not None): print('... OK') else: return # setup wiring pi and leds if noleds == False: print('Setting up wiring pi'), wiringpi.wiringPiSetup() wiringpi.pinMode(GREEN_PIN, 1) wiringpi.pinMode(RED_PIN, 1) print('... OK') else: print "Wiringpi setup skipped" # setup serial if noservos == False: print("Setting up serial connection to Arduino"), port = serial.Serial("/dev/ttyUSB0", baudrate=115200, timeout=3.0) if (port is not None): print('... OK') else: return else: print "Serial setup skipped" wiringpi.delay(16000) print "Starting object tracking" frames = 0 start_time = time.time() while True: diagonal, center_x, center_y = find_ball(capture, noimage, nothreshold) if noservos == False: update_servos(diagonal, center_x, center_y) if (read_servo_update(port)): next_servo_update = wiringpi.millis()+100; if wiringpi.millis() > next_servo_update: send_servo_update(port) if noleds == False: update_leds(diagonal) frames += 1 currtime = time.time() numsecs = currtime - start_time fps = frames / numsecs sys.stdout.write("Found ball at: (%d, %d) "%(center_x,center_y) + " Deviation %d " %(90-panServoAngle)+"Current FPS: %d \t\t\r\n" %fps) sys.stdout.flush() return
def main(): pid = pidlib.PID(0.03, 0, 0.001) pid.setPoint(0) noleds = False noarduino = False noimage = False nothreshold = False next_servo_update = 0 try: opts, args = getopt.getopt(sys.argv[1:], None, ["help", "noarduino", "noleds", "noimage", "nothreshold"]) except getopt.GetoptError as err: usage() sys.exit(2) for option, value in opts: if option == "--noleds": noleds = True elif option == "--noarduino": noarduino = True elif option == "--noimage": noimage = True elif option == "--nothreshold": nothreshold = True elif option == "--help": usage() sys.exit(0) # setup camera capture print ("Setting up webcam"), capture = cv2.VideoCapture(-1) if capture is not None: print ("... OK") else: return # setup wiring pi and leds if noleds == False: print ("Setting up wiring pi"), wiringpi.wiringPiSetup() wiringpi.pinMode(GREEN_PIN, 1) wiringpi.pinMode(RED_PIN, 1) print ("... OK") else: print "Wiringpi setup skipped" # setup serial if noarduino == False: print ("Setting up serial connection to Arduino"), port = serial.Serial("/dev/ttyUSB0", baudrate=115200, timeout=3.0) if port is not None: print ("... OK") else: return else: print "Serial setup skipped" print "Starting object tracking" frames = 0 start_time = time.time() while True: diagonal, center_x, center_y = find_ball(capture, noimage, nothreshold) if diagonal > 0: pid_value = pid.update(SCREEN_WIDTH / 2 - center_x) if noarduino == False: update_servos(diagonal, pid_value) if read_servo_update(port): next_servo_update = wiringpi.millis() + 100 send_servo_update(port) if noleds == False: update_leds(diagonal) frames += 1 currtime = time.time() numsecs = currtime - start_time fps = frames / numsecs sys.stdout.write( "Found ball at: (%d, %d) diag=%d " % (center_x, center_y, diagonal) + " Deviation %d " % (90 - panServoAngle) + "Current FPS: %d \t\t\r" % fps ) sys.stdout.flush() return
for jm in range(0, 4): text[im * length + jm + cursor] = eval(letters + '[' + str(jm + im * 4) + ']') if letters == 'm' or letters == 'w': text[im * length + 4 + cursor] = 1 else: text[im * length + 4 + cursor] = 0 cursor += 5 cursor += 1 while True: for i in range(0, 6): for j in range(0, 11): if text[i * length + j + startIndex] == 1: wiringpi.digitalWrite(cols[j], 1) wiringpi.digitalWrite(rows[i], 1) wiringpi.delay(1) wiringpi.digitalWrite(cols[j], 0) wiringpi.digitalWrite(rows[i], 0) if wiringpi.millis() - elapsed > speed * 1000: elapsed += speed * 1000 if startIndex == length - 11: startIndex = 0 wiringpi.delay(250) else: startIndex += 1 if startIndex == 0 and wiringpi.millis() - elapsed > speed * 1000: elapsed += speed * 10000 if startIndex == length - 15 and wiringpi.millis() - elapsed > speed * 1000: elapsed += speed * 10000