-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
55 lines (39 loc) · 1.25 KB
/
main.py
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
from gpiozero import Button, LED
from signal import pause
from smtplib import SMTPRecipientsRefused
from send_email import Email
from email_server import Server
from picroscope import Picroscope
SMTP = "smtp.gmail.com"
SMTP_PORT = 587
from constant import GMAIL_USER, GMAIL_PASSWORD
LED_PIN = 16
LEFT_BUTTON_PIN = 20
RIGHT_BUTTON_PIN = 21
CAPTURE_DIR = "/home/pi/Desktop/picroscope/images"
EMAIL_SUBJECT = "STEM 「語文」同樂日 -- 顯微鏡 DIY"
led = LED(LED_PIN)
left_button = Button(LEFT_BUTTON_PIN)
right_button = Button(RIGHT_BUTTON_PIN)
picroscope = Picroscope(led=led, captureDir=CAPTURE_DIR)
server = Server(SMTP, SMTP_PORT)
server.login(GMAIL_USER, GMAIL_PASSWORD)
print()
print(picroscope.help_text)
def send_image():
filename = picroscope.capture()
if filename is not None:
picroscope.toggle_preview()
email = Email(server)
email.subject = EMAIL_SUBJECT
email.recipient = input("Recipient: ")
email.add_attachment(filename)
print()
try:
print("Please wait ...")
email.send()
except SMTPRecipientsRefused:
print("Invalid email address.")
left_button.when_pressed = picroscope.toggle_preview
right_button.when_pressed = send_image
pause()