Created
April 20, 2019 02:04
-
-
Save vihanb/71e9203bc21a1f60527ca96761260312 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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