Skip to content
Snippets Groups Projects
Commit 6d6c37c8 authored by Evan Jones's avatar Evan Jones
Browse files

Upload New File

parent 7b6d5cc9
No related branches found
No related tags found
No related merge requests found
import time
import grovepi
from grove_rgb_lcd import *
# Define pin mappings
pir_pin = 2
button_pin = 3
led_pin = 4
servo_pin = 5
ultrasonic_pin = 6
light_sensor_pin = 0
def pause():
input("\nPress ENTER to continue to the next test...\n")
# --- PIR Motion Sensor ---
def test_pir():
grovepi.pinMode(pir_pin, "INPUT")
print("[TEST 1] PIR Motion Sensor (D2)")
print("Move in front of the sensor.")
for _ in range(10):
motion = grovepi.digitalRead(pir_pin)
print("Motion Detected!" if motion else "No motion")
time.sleep(1)
# --- Button ---
def test_button():
grovepi.pinMode(button_pin, "INPUT")
print("[TEST 2] Button (D3)")
print("Press the button.")
for _ in range(10):
state = grovepi.digitalRead(button_pin)
print("Button Pressed!" if state else "Waiting...")
time.sleep(0.5)
# --- Buzzer or LED ---
def test_led():
grovepi.pinMode(led_pin, "OUTPUT")
print("[TEST 3] LED or Buzzer (D4)")
print("It should flash/beep.")
for _ in range(5):
grovepi.digitalWrite(led_pin, 1)
time.sleep(0.5)
grovepi.digitalWrite(led_pin, 0)
time.sleep(0.5)
# --- Servo Motor ---
def test_servo():
grovepi.pinMode(servo_pin, "OUTPUT")
print("[TEST 4] Servo Motor (D5)")
print("It should vibrate or move.")
grovepi.analogWrite(servo_pin, 255)
time.sleep(2)
grovepi.analogWrite(servo_pin, 0)
print("Servo test complete.")
# --- Ultrasonic Ranger ---
def test_ultrasonic():
grovepi.pinMode(ultrasonic_pin, "INPUT")
print("[TEST 5] Ultrasonic Ranger (D6)")
print("Move your hand closer/farther.")
for _ in range(10):
try:
distance = grovepi.ultrasonicRead(ultrasonic_pin)
print(f"Distance: {distance} cm")
except Exception as e:
print(f"Error: {e}")
time.sleep(1)
# --- Light Sensor ---
def test_light():
print("[TEST 6] Light Sensor (A0)")
print("Cover and uncover the sensor.")
for _ in range(10):
try:
light = grovepi.analogRead(light_sensor_pin)
print(f"Light Level: {light}")
except Exception as e:
print(f"Error: {e}")
time.sleep(1)
# --- LCD Display ---
def test_lcd():
print("[TEST 7] LCD Display (I2C)")
try:
setRGB(0, 100, 255)
setText("LCD is working!\nAll good :)")
time.sleep(4)
setText("Ready to deploy!")
time.sleep(3)
except Exception as e:
print(f"LCD Error: {e}")
# --- Run All Tests Sequentially ---
def run_all_tests():
print("\nHARDWARE TEST")
print("Press Ctrl+C anytime to exit.\n")
test_pir()
pause()
test_button()
pause()
test_led()
pause()
test_servo()
pause()
test_ultrasonic()
pause()
test_light()
pause()
test_lcd()
print("\nAll tests completed!")
if __name__ == "__main__":
try:
run_all_tests()
except KeyboardInterrupt:
print("\nTest exited.")
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment