# FLASH LIGHT(DAISO) test -2024.2.1- import tkinter as tk import threading as th import RPi.GPIO as GPIO import time # GPIO pin CTL = 26 # SW enable enableSw = True # message TXT = '点灯モードを選択して下さい。' # GPIO initialize GPIO.setwarnings(False) GPIO.setmode(GPIO.BCM) GPIO.setup(CTL, GPIO.OUT, initial=GPIO.LOW) # light on (each mode) def signal_a(mode): global enableSw if enableSw == False: return enableSw = False x = mode tx.set('MODE: ' + str(mode) + 'で点灯します。') while x > -1: GPIO.output(CTL, GPIO.HIGH) time.sleep(0.1) GPIO.output(CTL, GPIO.LOW) time.sleep(0.1) x -= 1 t = th.Timer(5, signal_b, args=(mode,)) t.start() # light off def signal_b(mode): global enableSw x = mode while x < 3: GPIO.output(CTL, GPIO.HIGH) time.sleep(0.1) GPIO.output(CTL, GPIO.LOW) time.sleep(0.1) x += 1 tx.set(TXT) enableSw = True # main root = tk.Tk() root.geometry('300x200') root.title('FLASH LIGHT') tx = tk.StringVar() tx.set(TXT) var = tk.IntVar() var.set(0) label = tk.Label(root, textvariable = tx) label.place(x=90, y=115) button = tk.Button(root, text='SW', command=lambda:signal_a(var.get())) button.place(x=40, y=110) btn1 = tk.Radiobutton(root, value=0, variable=var, text='常時点灯') btn1.place(x=80, y=30) btn2 = tk.Radiobutton(root, value=1, variable=var, text='フラッシュ(速)') btn2.place(x=80, y=50) btn3 = tk.Radiobutton(root, value=2, variable=var, text='フラッシュ(遅)') btn3.place(x=80, y=70) root.mainloop()