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
36b9d143
Commit
36b9d143
authored
4 months ago
by
Evan Jones
Browse files
Options
Downloads
Patches
Plain Diff
Replace main.py
parent
79da3a4c
No related branches found
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
-26
19 additions, 26 deletions
main.py
with
19 additions
and
26 deletions
main.py
+
19
−
26
View file @
36b9d143
...
...
@@ -72,12 +72,13 @@ def notify_audio(duration):
# === Sensing Functions ===
def
detect_button_press
():
global
last_button_state
button
=
digitalRead
(
button_port
)
#makes sure button only goes once if held down
if
button
==
0
and
last_button_state
==
1
:
log_event
(
"
EVENT
"
,
"
Button Pressed
"
)
set_display
(
"
Ringing
"
,
""
)
set_display
(
"
Ringing
"
)
notify
(
preferences
)
time
.
sleep
(
2
)
set_display
(
"
Smart Doorbell
"
,
"
Ready
"
)
...
...
@@ -86,30 +87,21 @@ def detect_button_press():
return
def
detect_motion
():
motion
=
digitalRead
(
pir_port
)
if
motion
==
1
and
not
motion_detected
:
print
(
"
Motion detected!
"
)
motion_detected
=
True
no_motion_counter
=
0
elif
motion
==
0
:
no_motion_counter
+=
1
if
motion_detected
and
no_motion_counter
>
5
:
print
(
"
motion stopped
"
)
motion_detected
=
False
return
def
detect_light_level
():
global
light_dark_counter
,
light_trigger_delay
,
night_mode
light
=
analogRead
(
light_port
)
if
light
<
light_dark_threshold
:
light_dark_counter
+=
1
if
light_dark_counter
>=
light_trigger_delay
and
not
night_mode
:
log_event
(
"
EVENT
"
,
"
SIGNIFICANT DARKNESS DETECTED
"
)
#
log_event("EVENT", "SIGNIFICANT DARKNESS DETECTED")
adjust_lights
()
else
:
if
night_mode
:
log_event
(
"
EVENT
"
,
"
SIGNIFICANT LIGHT DETECTED
"
)
#
log_event("EVENT", "SIGNIFICANT LIGHT DETECTED")
adjust_lights
()
else
:
return
...
...
@@ -121,11 +113,11 @@ def set_display(message):
if
len
(
message
)
>
32
:
scroll_text
(
message
)
return
# Split and display in 2 lines if it fits
line1
=
message
[:
16
]
line2
=
message
[
16
:
32
]
if
len
(
message
)
>
16
else
""
setText
(
f
"
{
line1
}
\n
{
line2
}
"
)
else
:
# Split and display in 2 lines if it fits
line1
=
message
[:
16
]
line2
=
message
[
16
:
32
]
if
len
(
message
)
>
16
else
""
setText
(
f
"
{
line1
}
\n
{
line2
}
"
)
except
Exception
as
e
:
print
(
f
"
[LCD Error] Could not update display:
{
e
}
"
)
...
...
@@ -147,12 +139,12 @@ def scroll_text(message, delay=0.3, loop_count=2, idle_message="Smart Doorbell R
print
(
f
"
[LCD Scroll Error]
{
e
}
"
)
def
adjust_lights
():
night_mode
=
not
night_mode
#
night_mode = not night_mode
return
# === System Functions ===
def
log_event
(
type
,
message
):
print
(
f
"
[
{
type
}
] (
{
now
}
):
{
message
}
"
)
def
log_event
(
m
type
,
message
):
print
(
f
"
[
{
m
type
}
] (
{
now
}
):
{
message
}
"
)
return
def
self_check
():
...
...
@@ -212,21 +204,22 @@ def self_check():
# === Main Reaction Loop ===
def
main_loop
():
print
(
"
System Starting
"
)
set_display
(
"
Smart Doorbell
"
,
"
Ready
"
)
set_display
(
"
Smart Doorbell
Ready
"
)
try
:
while
True
:
detect_button_press
()
detect_motion
()
detect_light_level
()
print
(
"
[DEBUG]: LOOP
"
)
time
.
sleep
(
0.2
)
except
KeyboardInterrupt
:
print
(
"
Smart doorbell shutdown.
"
)
set_display
(
"
SYSTEM HALTED
"
,
"
KEYBRD INTERRUPT
"
)
set_display
(
"
SYSTEM HALTED
KEYB
OA
RD INTERRUPT
"
)
# Run
if
__name__
==
"
__main__
"
:
initialise_sensors
()
self_check
()
#
self_check()
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