-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy patharduino delay using python
57 lines (49 loc) · 1.14 KB
/
arduino delay using python
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#python code:
import serial #pyserial
from tkinter import *
import datetime
win = Tk()
win.geometry("400x400+1200+300")
bg_color ="gray"
frame = Frame(win,width=400,height=400,bg=bg_color)
frame.place(x=0,y=0)
ser = serial.Serial('COM3', '9600')
SHOW_DATE = Label(frame,font=('Arial',15,'bold'),bg=bg_color,fg="white")
SHOW_DATE.place(x=100,y=10)
def run():
now = datetime.datetime.now()
Date_now = now.strftime("%Y-%m-%d")
Time_now = now.strftime("%H :%M :%S")
SHOW_DATE['text']="date : "+Date_now + "\n"+"time : " + Time_now
m = now.strftime("%M")
if m == "08":
frame['bg']="red"
ser.write('f'.encode('utf-8'))
if m == "09":
frame['bg'] = bg_color
ser.write('x'.encode('utf-8'))
SHOW_DATE.after(10, run)
run()
win.mainloop()
####################
#arduino code:
int leds[4]={11,10,9,3};
void setup() {
for (int i= 0 ;i<=5;i++){
pinMode(leds[i],OUTPUT);
Serial.begin(9600);
}
}
void loop() {
if (Serial.available()>0){
char ch = Serial.read();
if(ch =='f'){
digitalWrite(leds[0],HIGH);
}
else{
for(int i=0;i<=5;i++){
digitalWrite(leds[i],LOW);
}
}
}
}