Mon Mar 28, 2016 2:48 pm
one more thing i am not new to programing but i am new to python's such type of programs
i have designed a program but i am not sure it will run i have followed the same logic of what we do if we interface accelerometer to arduino. If the program is correct then how to execute it on Rpi.
import RPi.GPIO as GPIO
import adx1345
import subprocess
GPIO.setwarnings(False)
accel = adxl345.ADXL345()
axes = accel.getAxes(True)
def setup():
GPIO.setmode(GPIO.BCM)
GPIO.setup(A1,GPIO.IN)
GPIO.setup(A2,GPIO.IN)
GPIO.setup(10,GPIO.OUT)
GPIO.setup(11,GPIO.OUT)
GPIO.setup(12,GPIO.OUT)
GPIO.setup(13,GPIO.OUT)
Serial.begin(9600)
print"start"
def loop():
while(1):
X = axes['x']
Y = axes['y']
Z = axes['z']
if X>330 and X<343 and Y>390 and Y<410:
print"forward"
GPIO.output(10,GPIO.HIGH)
GPIO.output(11,GPIO.LOW)
GPIO.output(12,GPIO.HIGH)
GPIO.output(13,GPIO.LOW)
elif X>260 and X<280 and Y>340 and Y<360:
print"left"
GPIO.output(10,GPIO.HIGH)
GPIO.output(11,GPIO.LOW)
GPIO.output(12,GPIO.LOW)
GPIO.output(13,GPIO.HIGH)
elif X>390 and X<410 and Y>340 and Y<360:
print"right"
GPIO.output(10,GPIO.LOW)
GPIO.output(11,GPIO.HIGH)
GPIO.output(12,GPIO.HIGH)
GPIO.output(13,GPIO.LOW)
elif X>335 and X<360 and Y>270 and Y<290:
print"back"
GPIO.output(10,GPIO.LOW)
GPIO.output(11,GPIO.HIGH)
GPIO.output(12,GPIO.LOW)
GPIO.output(13,GPIO.HIGH)
elif X>330 and X<350 and Y>325 and Y<355:
print"stop"
GPIO.output(10,GPIO.HIGH)
GPIO.output(11,GPIO.HIGH)
GPIO.output(12,GPIO.HIGH)
GPIO.output(13,GPIO.HIGH)