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
c1afbb01
Commit
c1afbb01
authored
4 months ago
by
Evan Jones
Browse files
Options
Downloads
Patches
Plain Diff
Upload New File
parent
6d6c37c8
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
test_basic.py
+67
-0
67 additions, 0 deletions
test_basic.py
with
67 additions
and
0 deletions
test_basic.py
0 → 100644
+
67
−
0
View file @
c1afbb01
import
grovepi
import
time
# Pin definitions
PIR_PIN
=
2
ULTRASONIC_PIN
=
4
LIGHT_SENSOR_PIN
=
1
# Analog port A1
BUTTON_PIN
=
3
# Initialise all sensors at startup
def
Initialise_Sensors
():
grovepi
.
pinMode
(
PIR_PIN
,
"
INPUT
"
)
grovepi
.
pinMode
(
BUTTON_PIN
,
"
INPUT
"
)
print
(
"
Sensors initialized
"
)
# Read motion sensor
def
Read_Motion
():
try
:
motion
=
grovepi
.
digitalRead
(
PIR_PIN
)
print
(
f
"
Motion Sensor Reading:
{
motion
}
"
)
return
motion
except
Exception
as
e
:
print
(
f
"
Motion Sensor Error:
{
e
}
"
)
return
None
# Read distance from ultrasonic ranger
def
Read_Distance
():
try
:
distance
=
grovepi
.
ultrasonicRead
(
ULTRASONIC_PIN
)
print
(
f
"
Ultrasonic Distance:
{
distance
}
cm
"
)
return
distance
except
Exception
as
e
:
print
(
f
"
Ultrasonic Ranger Error:
{
e
}
"
)
return
None
# Read light level
def
Read_Light_Level
():
try
:
light_level
=
grovepi
.
analogRead
(
LIGHT_SENSOR_PIN
)
print
(
f
"
Light Sensor Reading:
{
light_level
}
"
)
return
light_level
except
Exception
as
e
:
print
(
f
"
Light Sensor Error:
{
e
}
"
)
return
None
# Handle button press
def
Handle_Button
():
try
:
button_state
=
grovepi
.
digitalRead
(
BUTTON_PIN
)
print
(
f
"
Button State:
{
button_state
}
"
)
return
button_state
except
Exception
as
e
:
print
(
f
"
Button Error:
{
e
}
"
)
return
None
# Test functions individually
if
__name__
==
"
__main__
"
:
Initialise_Sensors
()
# Run each sensor test 5 times
for
i
in
range
(
5
):
print
(
f
"
\n
Test Iteration:
{
i
+
1
}
"
)
Read_Motion
()
Read_Distance
()
Read_Light_Level
()
Handle_Button
()
time
.
sleep
(
1
)
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