- added the hardwarelib to handle all the GPIO stuff

pull/2/head
Trivernis 7 years ago
parent 92efbd87c2
commit 2d11ea18ca

@ -1,12 +0,0 @@
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="PyUnresolvedReferencesInspection" enabled="true" level="WARNING" enabled_by_default="true">
<option name="ignoredIdentifiers">
<list>
<option value="Adafrouit_PCA9685" />
</list>
</option>
</inspection_tool>
</profile>
</component>

@ -0,0 +1,93 @@
from subprocess import call, check_output
from lib import ultrasonic
import RPi.GPIO as GPIO
class Navigator():
"""Forward Motor with relais, Steering with servo"""
def __init__(self, mrelaispin):
self.mrelpin = mrelaispin
self.steer = None
GPIO.setup(self.mrelpin, GPIO.OUT)
self.stop()
def left(self):
if self.steer != 'left':
call(['python', './lib/servolib.py', 'left'])
self.steer = 'left'
def right(self):
if self.steer != 'right':
call(['python', './lib/servolib.py', 'right'])
self.steer = 'right'
def straight(self):
if self.steer:
call(['python', './lib/servolib.py'])
self.steer = None
def forward(self):
GPIO.output(self.mrelpin, False)
def stop(self):
GPIO.output(self.mrelpin, True)
class Light:
"""Light switched with a relais"""
def __init__(self, lightpin):
self.pin = lightpin
GPIO.setup(self.pin, GPIO.OUT)
GPIO.output(self.pin, True)
self.shine = False
def switch(self):
GPIO.output(self.pin, not self.shine)
self.shine = not self.shine
def switch_on(self):
GPIO.output(self.pin, False)
def switch_of(self):
GPIO.output(self.pin, True)
class Ultrasonic:
"""A ultrasonic sensor"""
def __init__(self, trigger, echo):
self.sensor =ultrasonic.Sensor()
self.sensor.init(trigger, echo)
def get_distance(self):
distance = self.sensor.echo()
return distance
def __del__(self):
self.sensor.clean()
class Temperature:
"""A temperature sensor"""
def get_Temperature(self):
outp = check_output(['python','-u','./lib/thermolib.py']).decode('ISO-8859-1')
temp, hum = outp.split('|')
return temp
def get_Humidity(self):
outp = check_output(['python','-u','./lib/thermolib.py']).decode('ISO-8859-1')
temp, hum = outp.split('|')
return hum

@ -1,8 +0,0 @@
import sys
import Adafruit_DHT
while True:
humidity, temperature = Adafruit_DHT.read_retry(11, 14)
print 'Temp: {} C Humidity: {} %'.format(temperature, humidity)

@ -0,0 +1,8 @@
import Adafruit_DHT
def main():
humidity, temperature = Adafruit_DHT.read_retry(11, 14)
print '{}|{}'.format(temperature, humidity)
if __name__ == '__main__':
main()

@ -72,17 +72,17 @@ def reset_dire():
def drive_left():
if not left:
call(['python', './lib/servo_2.py','left'])
call(['python', './lib/servolib.py','left'])
return
def drive_right():
if not right:
call(['python', './lib/servo_2.py','right'])
call(['python', './lib/servolib.py','right'])
return
def reset_turn():
if left or right:
call(['python','./lib/servo_2.py'])
call(['python','./lib/servolib.py'])
return
# ____________________________
# -- special functions

@ -0,0 +1,9 @@
import pygame, time
from lib import ultrasonic
def main():
pygame.display.init()
pass
if __name__ == '__main__':
main()
Loading…
Cancel
Save