Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
group project 2025
Manage
Activity
Members
Plan
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Deploy
Releases
Container registry
Model registry
Analyze
Contributor analytics
Repository analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Evan Jones
group project 2025
Commits
711ef7eb
Commit
711ef7eb
authored
4 months ago
by
Evan Jones
Browse files
Options
Downloads
Patches
Plain Diff
Replace main.py
parent
37071e85
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
main.py
+19
-20
19 additions, 20 deletions
main.py
with
19 additions
and
20 deletions
main.py
+
19
−
20
View file @
711ef7eb
...
@@ -5,11 +5,12 @@ import datetime
...
@@ -5,11 +5,12 @@ import datetime
# Variables
# Variables
light_port
=
1
# A0
light_port
=
1
# A0
pir_port
=
2
# D2
pir_port
=
4
# D4
button_port
=
3
# D3
button_port
=
3
# D2
#FOR SOME REASON THIS BOARD THINKS 3 IS D2
buzzer_port
=
7
# D7
buzzer_port
=
7
# D7
preferences
{
"
Thingsboard
"
:
True
,
preferences
=
{
"
Thingsboard
"
:
True
,
"
Visual
"
:
True
,
"
Visual
"
:
True
,
"
Audio
"
:
True
}
"
Audio
"
:
True
}
...
@@ -30,19 +31,19 @@ def notify_thingsboard(message):
...
@@ -30,19 +31,19 @@ def notify_thingsboard(message):
print
(
"
message
"
)
print
(
"
message
"
)
return
return
def
notify_audio
(
duration
=
0.5
):
def
notify_audio
(
duration
):
digitalWrite
(
buzzer_port
,
1
)
digitalWrite
(
buzzer_port
,
1
)
time
.
sleep
(
duration
)
time
.
sleep
(
duration
)
digitalWrite
(
buzzer_port
,
0
)
digitalWrite
(
buzzer_port
,
0
)
return
return
def
notify
(
preferences
,
message
=
"
visitor
"
):
def
notify
(
preferences
,
message
=
"
visitor
"
,
duration
=
0.2
):
if
preferences
.
get
(
"
Thingsboard
"
):
if
preferences
.
get
(
"
Thingsboard
"
):
notify_thingsboard
(
message
)
notify_thingsboard
(
message
)
el
if
preferences
.
get
(
"
Visual
"
):
if
preferences
.
get
(
"
Visual
"
):
notify_visual
()
notify_visual
()
el
if
preferences
.
get
(
"
Audio
"
):
if
preferences
.
get
(
"
Audio
"
):
notify_audio
()
notify_audio
(
duration
)
# === Main Reaction Loop ===
# === Main Reaction Loop ===
...
@@ -53,39 +54,37 @@ def main_loop():
...
@@ -53,39 +54,37 @@ def main_loop():
try
:
try
:
while
True
:
while
True
:
# Check Button Press
# Check Button Press
button
=
grovepi
.
digitalRead
(
button_port
)
button
=
digitalRead
(
button_port
)
if
button
==
0
:
if
button
==
0
:
print
(
"
[EVENT] Button Pressed
"
)
print
(
"
[EVENT] Button Pressed
"
)
setText
(
"
RINGING
"
)
setText
(
"
RINGING
"
)
notify
_visual
(
)
notify
(
preferences
)
time
.
sleep
(
2
)
time
.
sleep
(
2
)
setText
(
"
Smart Doorbell
\n
Ready
"
)
setText
(
"
Smart Doorbell
\n
Ready
"
)
# Check PIR
# Check PIR
motion
=
grovepi
.
digitalRead
(
pir_port
)
motion
=
digitalRead
(
pir_port
)
if
motion
:
if
motion
:
print
(
"
[EVENT] Motion Detected
"
)
print
(
"
[EVENT] Motion Detected
"
)
notify_thingsboard
(
f
"
[EVENT](
{
now
}
): Movement Detected
"
)
notify_thingsboard
(
f
"
[EVENT](
{
now
}
): Movement Detected
"
)
time
.
sleep
(
1
)
#
time.sleep(1)
# Check Light Level
# Check Light Level
light
=
analogRead
(
light_port
)
light
=
analogRead
(
light_port
)
if
light
<
light_dark_threshold
:
if
light
<
light_dark_threshold
:
print
(
"
[INFO] Night Mode Active
"
)
#
print("[INFO] Night Mode Active")
#
You can dim screen, enable night light, etc.
#
Activate lights
# Or change color subtly to indicate night mode
print
()
else
:
else
:
#
Daytime color
#
print("daytime")
print
()
time
.
sleep
(
0.2
)
time
.
sleep
(
0.2
)
except
KeyboardInterrupt
:
except
KeyboardInterrupt
:
print
(
"
Smart doorbell shutdown.
"
)
print
(
"
Smart doorbell shutdown.
"
)
setText
(
"
System halted
"
)
setText
(
"
System halted
"
)
setRGB
(
0
,
0
,
0
)
# Run
# Run
if
__name__
==
"
__main__
"
:
if
__name__
==
"
__main__
"
:
I
nitialise_
S
ensors
()
i
nitialise_
s
ensors
()
main_loop
()
main_loop
()
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment