Skip to content

Instantly share code, notes, and snippets.

@vihanb
Created April 20, 2019 02:04
Show Gist options
  • Save vihanb/71e9203bc21a1f60527ca96761260312 to your computer and use it in GitHub Desktop.
Save vihanb/71e9203bc21a1f60527ca96761260312 to your computer and use it in GitHub Desktop.
import time
import RPi.GPIO as GPIO
light_sensor_pin = 5
fan_pin = 6
wheel_pin_numbers = [1, 2, 3, 4]
for pin_number in wheel_pin_numbers:
GPIO.setup(pin_number, GPIO.OUT)
GPIO.setup(light_sensor_pin, GPIO.IN)
def is_light():
return GPIO.input(light_sensor_pin)
def foward(stop=False):
for pin_number in wheel_pin_numbers:
GPIO.output(pin_number, GPIO.HIGH if not stop else GPIO.LOW)
def run_fan(stop=False):
GPIO.output(fan_pin, GPIO.HIGH if not stop else GPIO.LOW)
def go():
while True:
if not is_light():
forward()
else:
forward(stop=True)
break
run_fan()
time.sleep(2) # amount of seconds to run fan
run_fan(stop=True)
go()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment