From acb098e1839d5dce4a20d7a14d12e96c9d064197 Mon Sep 17 00:00:00 2001 From: angoosh Date: Tue, 27 Feb 2024 21:07:09 +0100 Subject: [PATCH] added code for timer pushbutton --- SW/PC/Alkator.json | 100 +++++++++++++ SW/PC/Alkator_count_results.py | 37 +++++ SW/PC/main.py | 4 +- SW/RPi_Pico_Button/main.py | 140 ++++++++++++++++++ SW/{RPi_Pico => RPi_Pico_Reader}/NFC_PN532.py | 0 SW/{RPi_Pico => RPi_Pico_Reader}/main.py | 0 Vysledky.txt | 11 ++ 7 files changed, 290 insertions(+), 2 deletions(-) create mode 100644 SW/PC/Alkator.json create mode 100644 SW/PC/Alkator_count_results.py create mode 100644 SW/RPi_Pico_Button/main.py rename SW/{RPi_Pico => RPi_Pico_Reader}/NFC_PN532.py (100%) rename SW/{RPi_Pico => RPi_Pico_Reader}/main.py (100%) create mode 100644 Vysledky.txt diff --git a/SW/PC/Alkator.json b/SW/PC/Alkator.json new file mode 100644 index 0000000..93a3afe --- /dev/null +++ b/SW/PC/Alkator.json @@ -0,0 +1,100 @@ +{ + "1": { + "name": "Michal_Dolezal", + "time": 59686.214496, + "laps": 3, + "lap_time": { + "0": 1570.6283019999973, + "1": 1714.182087000001, + "2": 1446.9299450000035 + } + }, + "2": { + "name": "David_Hubalek", + "time": 61285.385381, + "laps": 3, + "lap_time": { + "0": 1378.498722999997, + "1": 1902.1900959999984, + "2": 2436.201885000002 + } + }, + "9": { + "name": "Lucie_Ponocna", + "time": 60148.765882, + "laps": 3, + "lap_time": { + "0": 1481.6570529999954, + "1": 1371.9764339999965, + "2": 1392.5671650000004 + } + }, + "8": { + "name": "Jan_Cada", + "time": 60218.945151, + "laps": 3, + "lap_time": { + "0": 1293.8216450000036, + "1": 1341.646053000004, + "2": 1402.6441269999996 + } + }, + "10": { + "name": "Jenda", + "time": 61880.872883, + "laps": 3, + "lap_time": { + "0": 1365.9300070000027, + "1": 1959.2283549999993, + "2": 1957.2417010000063 + } + }, + "4": { + "name": "Vojta_Flekr", + "time": 61567.55196, + "laps": 3, + "lap_time": { + "0": 1447.2361820000006, + "1": 1654.6209919999965, + "2": 1696.5821589999978 + } + }, + "7": { + "name": "Lukas_Bouchal", + "time": 61356.658114, + "laps": 3, + "lap_time": { + "0": 1456.207137999998, + "1": 1405.8979709999985, + "2": 1365.8517150000043 + } + }, + "3": { + "name": "Adam_Krejsa", + "time": 61475.209162, + "laps": 3, + "lap_time": { + "0": 1313.4791200000036, + "1": 1358.869869999995, + "2": 1402.3635040000008 + } + }, + "6": { + "name": "David_Bedrnicek", + "time": 62894.44809, + "laps": 3, + "lap_time": { + "0": 1480.398721999998, + "1": 1721.0690019999965, + "2": 1939.8222899999964 + } + }, + "11": { + "name": "Nacelnik", + "time": 64679.27699, + "laps": 1, + "lap_time": { + "0": 2533.054164000001 + } + } +} \ No newline at end of file diff --git a/SW/PC/Alkator_count_results.py b/SW/PC/Alkator_count_results.py new file mode 100644 index 0000000..e27fe46 --- /dev/null +++ b/SW/PC/Alkator_count_results.py @@ -0,0 +1,37 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +Created on Sat Oct 21 17:19:11 2023 + +@author: angoosh +""" + +import json + +FILE = './Alkator.json' + +data_dict = '' +results = {} + +with open(FILE,'r') as f: + file_content = f.read() + data_dict = json.loads(file_content) + +for id in data_dict: + laps = int(data_dict[id]['laps']) + time = 0 + for i in range(0,laps): + time += float(data_dict[id]['lap_time'][str(i)]) + time = (time - (600*laps)) / 60 + print(data_dict[id]['name'],time) + data_dict[id]['total_time'] = time + results[data_dict[id]['name']] = time + +print(results) +dict(sorted(results.items(), key=lambda item: item[0])) +print(results) + + + + + \ No newline at end of file diff --git a/SW/PC/main.py b/SW/PC/main.py index c451672..e08a551 100755 --- a/SW/PC/main.py +++ b/SW/PC/main.py @@ -75,7 +75,7 @@ def write(ser): break def main(): - s = serial.Serial(port="/dev/ttyACM0", parity=serial.PARITY_EVEN, stopbits=serial.STOPBITS_ONE, timeout=1) + s = serial.Serial(port="/dev/ttyACM3", parity=serial.PARITY_EVEN, stopbits=serial.STOPBITS_ONE, timeout=1) s.flush() rw = input('Read or Write tags? [R/w]') @@ -98,4 +98,4 @@ def main(): if __name__ == "__main__": - main() \ No newline at end of file + main() diff --git a/SW/RPi_Pico_Button/main.py b/SW/RPi_Pico_Button/main.py new file mode 100644 index 0000000..85efc76 --- /dev/null +++ b/SW/RPi_Pico_Button/main.py @@ -0,0 +1,140 @@ +import neopixel +import time +import sys +import select +from machine import Pin, SPI + +#neopixel +ws_pin = 2 +led_num = 10 +BRIGHTNESS = 0.2 # Adjust the brightness (0.0 - 1.0) + +led_strip = neopixel.NeoPixel(Pin(ws_pin), led_num) + +push_button = Pin(24,Pin.IN,Pin.PULL_UP) + +pushbutton_pressed = 0 +blink_interrupted = 0 + +def set_neopixel_brightness(color): + r, g, b = color + r = int(r * BRIGHTNESS) + g = int(g * BRIGHTNESS) + b = int(b * BRIGHTNESS) + return (r, g, b) + +def set_neopixel_color(r,g,b): + color = (r,g,b) + color = set_neopixel_brightness(color) + led_strip.fill(color) + led_strip.write() + +set_neopixel_color(0,0,0) + + + +def loop_neopixel(): + # Display red + color = (255, 0, 0) # Red color + color = set_neopixel_brightness(color) + led_strip.fill(color) + led_strip.write() + time.sleep(1) + + # Display green + color = (0, 255, 0) # Green color + color = set_neopixel_brightness(color) + led_strip.fill(color) + led_strip.write() + time.sleep(1) + + # Display blue + color = (0, 0, 255) # Blue color + color = set_neopixel_brightness(color) + led_strip.fill(color) + led_strip.write() + time.sleep(1) + +neopix_loop_dot_pos = 0 +def neopixel_loop_dot(): + global neopix_loop_dot_pos + color = (255, 0, 0) + black = (0, 0, 0) + + color = set_neopixel_brightness(color) + led_strip[neopix_loop_dot_pos] = black + neopix_loop_dot_pos += 1 + if neopix_loop_dot_pos > 9: + neopix_loop_dot_pos = 0 + led_strip[neopix_loop_dot_pos] = color + led_strip.write() + time.sleep(0.2) + +def lightup_led(index, color): + led_strip[index] = color + led_strip.write() + +def blink_and_beep(times): + global pushbutton_pressed, blink_interrupted + + blink_delay = 0.2 + + #insert beep + for i in range(0, times): + set_neopixel_color(255, 0, 0) + time.sleep(blink_delay) + set_neopixel_color(0, 0, 0) + time.sleep(blink_delay) + if pushbutton_pressed == 1: + pushbutton_pressed = 0 + blink_interrupted = 1 + i = times + return + +ten_min_timer = 0 +ten_min_timer_led_index = 0 +def count_10_min(): + global ten_min_timer, ten_min_timer_led_index, pushbutton_pressed, blink_interrupted + + red = (255, 0, 0) + red = set_neopixel_brightness(red) + green = (0, 255, 0) + green = set_neopixel_brightness(green) + + if ten_min_timer_led_index == 11: + return + + if (ten_min_timer % 60) == 0: + if ten_min_timer_led_index == 10: + pushbutton_pressed = 0 + blink_and_beep(60) + if blink_interrupted == 1: + blink_interrupted = 0 + return + ten_min_timer_led_index = 11 + led_strip[0] = green + led_strip[2] = green + led_strip[4] = green + led_strip[6] = green + led_strip[8] = green + led_strip.write() + return + lightup_led(ten_min_timer_led_index, red) + ten_min_timer_led_index += 1 + + ten_min_timer += 1 + +def button_callback(push_button): + global ten_min_timer, ten_min_timer_led_index, pushbutton_pressed + pushbutton_pressed = 1 + ten_min_timer = 0 + ten_min_timer_led_index = 0 + set_neopixel_color(0,0,0) + count_10_min() + +set_neopixel_color(0,0,0) +push_button.irq(trigger=Pin.IRQ_FALLING, handler=button_callback) + +while True: + count_10_min() + time.sleep(1) \ No newline at end of file diff --git a/SW/RPi_Pico/NFC_PN532.py b/SW/RPi_Pico_Reader/NFC_PN532.py similarity index 100% rename from SW/RPi_Pico/NFC_PN532.py rename to SW/RPi_Pico_Reader/NFC_PN532.py diff --git a/SW/RPi_Pico/main.py b/SW/RPi_Pico_Reader/main.py similarity index 100% rename from SW/RPi_Pico/main.py rename to SW/RPi_Pico_Reader/main.py diff --git a/Vysledky.txt b/Vysledky.txt new file mode 100644 index 0000000..3acc2ec --- /dev/null +++ b/Vysledky.txt @@ -0,0 +1,11 @@ +Jan_Cada 37.30186375000012 +Adam_Krejsa 37.911874899999994 +Lukas_Bouchal 40.46594706666668 +Lucie_Ponocna 40.77001086666654 +Michal_Dolezal 48.86233890000003 +Vojta_Flekr 49.97398888333325 +David_Bedrnicek 55.68816689999985 +David_Hubalek 65.28151173333329 +Jenda 78.040001050000136 + +Nacelnik 31.216666667