
SunFounder TS-10 10.1-inch Touch Screen
Code Explanation
RedPin
=
13
GreenPin
=
11
GPIO
.
setmode(GPIO
.
BOARD)
GPIO
.
setup(RedPin, GPIO
.
OUT, initial
=
GPIO
.
HIGH)
GPIO
.
setup(GreenPin, GPIO
.
OUT, initial
=
GPIO
.
HIGH)
Set 2 LEDs as output and set the initial value to high.
def
get_time
():
time
.
time()
year
=
str
(time
.
strftime(
'%Y'
,time
.
localtime(time
.
time())))
month
=
str
(time
.
strftime(
'%m'
,time
.
localtime(time
.
time())))
day
=
str
(time
.
strftime(
'
%d
'
,time
.
localtime(time
.
time())))
hour
=
str
(time
.
strftime(
'%H'
,time
.
localtime(time
.
time())))
minute
=
str
(time
.
strftime(
'%M'
,time
.
localtime(time
.
time())))
second
=
str
(time
.
strftime(
'%S'
,time
.
localtime(time
.
time())))
present_time
=
year
+
'.'
+
month
+
'.'
+
day
+
'.'
+
hour
+
'.'
+
minute
˓
→
+
'.'
+
second
present_date
=
year
+
'.'
+
month
+
'.'
+
day
return
present_date, present_time
Use the
get_time()
function to get the current timestamp and return two values. Where
present_date
is
accurate to the day and
present_time
is accurate to the second.
attendance
=
False
GPIO
.
output(GreenPin, GPIO
.
LOW)
GPIO
.
output(RedPin, GPIO
.
HIGH)
(
"Reading...Please place the card..."
)
id
, text
=
reader
.
read()
(
"ID:
%s
\n
Text:
%s
"
%
(
id
,text))
GPIO
.
output(RedPin, GPIO
.
LOW)
GPIO
.
output(GreenPin, GPIO
.
HIGH)
First, we set
attendance
to False, which means that no one is clocked in.
Then set GreenPin to low level to light it, and RedPin to high level to keep it off, indicating that the current attendance
system is working normally.
When someone punches in, the id and text information of the card will be printed. If the red LED is on and the green
LED is off, it means that the check-in is successful and the result is sent to Cloud4RPi.
During this period, the attendance system is in sleep state until the next cycle starts (the green light is on).
if not
id
in
attendance_list:
attendance
=
True
attendance_list
.
append(
id
)
present_date, present_time
=
get_time()
attendance_statistics[
id
]
=
present_time
with
open
(
'attendance_sheet.'
+
present_date
+
'.csv'
,
'w'
)
as
f:
[f
.
write(
'{0}
{1}
\n
'
.
format(key, value))
for
key, value
in
˓
→
attendance_statistics
.
items()]
First determine if the id is duplicated in
attendance_list
by an if statement, if not, it means the punch-in is valid
and pass the id information into
attendance_list
. Then we get the current timestamp and use the id as the key
100
Chapter 5. PROJECTS AND ACTIVITIES
Содержание TS-10
Страница 1: ...SunFounder TS 10 10 1 inch Touch Screen www sunfounder com Nov 19 2021 ...
Страница 2: ......
Страница 6: ...SunFounder TS 10 10 1 inch Touch Screen 2 CONTENTS ...
Страница 9: ...SunFounder TS 10 10 1 inch Touch Screen 5 ...
Страница 10: ...SunFounder TS 10 10 1 inch Touch Screen 6 Chapter 1 HARDWARE DESCRIPTION ...
Страница 16: ...SunFounder TS 10 10 1 inch Touch Screen 12 Chapter 2 INSTALL THE RASPBERRY PI OS ...
Страница 21: ...SunFounder TS 10 10 1 inch Touch Screen pi 3 Step 5 17 ...
Страница 53: ...SunFounder TS 10 10 1 inch Touch Screen Now you have entered OctoPrint 5 3 3D Printer Monitor 49 ...
Страница 123: ...SunFounder TS 10 10 1 inch Touch Screen Also let it appear at the right time 5 7 Scratch Projects 119 ...
Страница 130: ...SunFounder TS 10 10 1 inch Touch Screen Set the balloon to a random position 126 Chapter 5 PROJECTS AND ACTIVITIES ...
Страница 131: ...SunFounder TS 10 10 1 inch Touch Screen Let it change the color and size randomly 5 7 Scratch Projects 127 ...
Страница 141: ...SunFounder TS 10 10 1 inch Touch Screen 5 7 Scratch Projects 137 ...
Страница 160: ...SunFounder TS 10 10 1 inch Touch Screen Copy out the second Trees 156 Chapter 5 PROJECTS AND ACTIVITIES ...
Страница 165: ...SunFounder TS 10 10 1 inch Touch Screen 5 7 Scratch Projects 161 ...
Страница 167: ...SunFounder TS 10 10 1 inch Touch Screen 5 7 Scratch Projects 163 ...
Страница 171: ...SunFounder TS 10 10 1 inch Touch Screen Then we add the Pen extension function 5 7 Scratch Projects 167 ...
Страница 181: ...SunFounder TS 10 10 1 inch Touch Screen 5 7 Scratch Projects 177 ...
Страница 209: ...SunFounder TS 10 10 1 inch Touch Screen 205 ...
Страница 210: ...SunFounder TS 10 10 1 inch Touch Screen 206 Chapter 7 3D PRINTED SUPPORT ...
Страница 212: ...SunFounder TS 10 10 1 inch Touch Screen 208 Chapter 8 FAQ ...