Exemplo n.º 1
0
def main():
    #initialize beam falls
    beam1Rise = datetime.datetime.min
    beam2Rise = datetime.datetime.min
    beam1LastRise = datetime.datetime.min
    beam2LastRise = datetime.datetime.min

    firebase = firebase_setup()
    global db
    db = firebase.database()
    print("Firebase is setup")

    global mac
    mac = hex(get_mac())
    print("MAC Address obtained")

    pull_data_config()

    gpio_setup()
    print("GPIO is setup")

    #send now as start of first interval
    asyncSendData(datetime.datetime.now())
    print("Will output/send every " + str(SENDFREQ) + " seconds")

    while True:
        if GPIO.event_detected(BEAM_2):
            #poll to see if this is a rise
            if not GPIO.input(BEAM_2):
                beam2LastRise = beam2Rise
                beam2Rise = datetime.datetime.utcnow()
                print("-----Beam 2 Rise: " + str(beam2Rise))
                if (beam2Rise - beam2LastRise).total_seconds() < RISETHRESH:
                    continue
                #if other beam is not tripped then don't do anything
                if not GPIO.input(BEAM_1):
                    analyze_event(beam1Rise, beam2Rise)

        if GPIO.event_detected(BEAM_1):
            #poll to see if this is a fall
            if not GPIO.input(BEAM_1):
                beam1LastRise = beam1Rise
                beam1Rise = datetime.datetime.utcnow()
                print("-----Beam 1 Rise: " + str(beam1Rise))
                if (beam1Rise - beam1LastRise).total_seconds() < RISETHRESH:
                    continue
                #if other beam is not tripped then don't do anything
                if not GPIO.input(BEAM_2):
                    analyze_event(beam1Rise, beam2Rise)
Exemplo n.º 2
0
last_time = -1

ser = serial.Serial('/dev/ttyS0')
sleep(1)  # wait for channel to open
# hunger = calc_hunger()

# initialize as dreaming
send_serial('d')

startup()  # setting up code to initialize the board/uploads

while True:  # continually in this state, check if channel HI
    # print(GPIO.input(record_channel))
    # record ing
    if GPIO.event_detected(record_channel) and not GPIO.input(record_channel):
        trigger_record()  # on button press, trigger callback
        sleep(10)  # wait 10 secs for debouncing, bad but works.
        # THIS MEANS RECORD FOR AT LEAST 10 seconds please:

    # start sing
    if not recording:
        if not singing and not GPIO.input(sing_channel):
            if last_time is -1:
                last_time = datetime.datetime.now()
            else:
                if datetime.datetime.now() - last_time > timedelta(0, 0, 250):
                    last_time = -1
                    print "singing..."
                    start_singing()
                    sleep(3)  # wait 3 secs for debouncing, bad but works.