Can someone of you help me with following problem. I always get an indentation error in line 63 but I cant find the mistake. It would be greate if someone of you could help me.
Code: Select all
import smbus
import math
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BOARD)
from time import sleep
import time
#################################################################### Sensor taking data from register
power_mgmt_1 = 0x6b
power_mgmt_2 = 0x6c
def read_byte(reg):
return bus.read_byte_data(address, reg)
def read_word(reg):
h = bus.read_byte_data(address, reg)
l = bus.read_byte_data(address, reg+1)
value = (h << 8) + l
return value
def read_word_2c(reg):
val = read_word(reg)
if (val >= 0x8000):
return -((65535 - val) + 1)
else:
return val
def dist(a,b):
return math.sqrt((a*a)+(b*b))
def get_y_rotation(x,y,z):
radians = math.atan2(x, dist(y,z))
return -math.degrees(radians)
def get_x_rotation(x,y,z):
radians = math.atan2(y, dist(x,z))
return math.degrees(radians)
bus = smbus.SMBus(1) # bus = smbus.SMBus(0) fuer Revision 1
address = 0x68 # via i2cdetect
# Aktivieren, um das Modul ansprechen zu koennen
bus.write_byte_data(address, power_mgmt_1, 0)
##################################################Motor PWM Contro
motor = 12 # IO pin for Motor PWM
a=7 #IO pin for direction 1
b=16 #IO pin for direction direction 2
GPIO.setwarnings(False)
GPIO.setup(motor,GPIO.OUT) #setting all pins as output
GPIO.setup(b,GPIO.OUT)
GPIO.setup(a,GPIO.OUT)
pi_pwm = GPIO.PWM(motor,500) #Motor as PWM with a Frequency of 500Hz
pi_pwm.start(0) # initialize motor PWM with 0
while True:
gyroskop_xout = read_word_2c(0x43)
gyroskop_yout = read_word_2c(0x45)
gyroskop_zout = read_word_2c(0x47)
GX=(gyroskop_xout / 131)
GY=(gyroskop_yout / 131)
GZ=(gyroskop_zout / 131)
if (Gz>100):
for i in range (0,7):
pi_pwm.start(100)# generate PWM with a dutyCycle of 100%
GPIO.output(b,0)# inverting the direction of the motor by digital IO
GPIO.output(a,1)
start= time.time()# taking aktual time in seconds
while time.time()-start < 0.15: #changing direction after 150 ms
pass
pi_pwm.start(100)# generate PWM with a dutyCycle of 100%
GPIO.output(b,1)
GPIO.output(a,0)
start= time.time()
while time.time()-start < 0.15:
pass
pi_pwm.start(0)#stopping the motor
start= time.time()
while time.time()-start < 1.5:#waiting 1.5 seconds to repeat the while True: Loopp
pass