Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

BELOW IS MY CODE USING GPIO. HOW CAN I TRANSLATE MY CODE TO PIGPIO INSTEAD ? import RPi.GPIO as GPIO import time #Python 2.7.13 in

BELOW IS MY CODE USING GPIO. HOW CAN I TRANSLATE MY CODE TO PIGPIO INSTEAD ?  import RPi.GPIO as GPIO import time #Python 2.7.13 in case stuff is cancer GPIO.setmode(GPIO.BOARD) GPIO_TRIGGER = 12 GPIO_ECHO = 18 GPIO.setup(GPIO_TRIGGER, GPIO.OUT) GPIO.setup(GPIO_ECHO, GPIO.IN) GPIO.setup(32, GPIO.OUT) p = GPIO.PWM(32,50) def distance(): # set Trigger to HIGH GPIO.output(GPIO_TRIGGER, True) # set Trigger after 0.01ms to LOW time.sleep(0.00001) GPIO.output(GPIO_TRIGGER, False) StartTime = time.time() StopTime = time.time() # save StartTime while GPIO.input(GPIO_ECHO) == 0: StartTime = time.time() # save time of arrival while GPIO.input(GPIO_ECHO) == 1: StopTime = time.time() # time difference between start and arrival TimeElapsed = StopTime - StartTime # multiply with the sonic speed (34300 cm/s) # and divide by 2, because there and back distance = (TimeElapsed * 34300) / 2 return distance try: while True: p.start(6.5) #MAGICAL MIDDLE VALUE THAT MAY OR MAY NOT CHANGE dist=distance() print ("Distance = %.1f cm" % dist) time.sleep(1.5) if dist < 10: print ("I am god") '''p.ChangeDutyCycle(5.5) time.sleep(.38)''' p.ChangeDutyCycle(7.5) time.sleep(.382) '''p.ChangeDutyCycle(2.5) time.sleep(1) p.ChangeDutyCycle(7.5) time.sleep(1)''' elif dist >= 5: p.ChangeDutyCycle(11.5) except KeyboardInterrupt: pass print ("TEST") p.stop() GPIO.cleanup()

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Databases Illuminated

Authors: Catherine Ricardo

2nd Edition

1449606008, 978-1449606008

More Books

Students also viewed these Databases questions