Professional Documents
Culture Documents
thebluepotatoyt@gmail.com
continue.
Set up GPIO pins
GPIO.setmode(GPIO.BCM)
GPIO.setup(STEP_PIN, GPIO.OUT)
GPIO.setup(DIR_PIN, GPIO.OUT)
GPIO.setup(BUTTON_PIN, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
GPIO.setup(LED_PIN, GPIO.OUT)
GPIO.setup(POT_PIN, GPIO.IN)
Start timer
start_timer()
Main loop
while True:
# Change direction if at end of travel
if (direction == CW and GPIO.input('A') == GPIO.HIGH) or (direction == CCW and
GPIO.input('B') == GPIO.HIGH):
reverse_direction(direction)
update_display()
lua
Copy code
# Move stepper motor
if step_count > 0:
GPIO.output(DIR_PIN, direction)
step_count -= 1
else:
time.sleep(0.1)
GPIO.cleanup()
This code should display the time and distance values on an OLED display using the
Adafruit SSD1306 library. You will need to install this library before running the
code by running the following command in the terminal:
Copy code
sudo pip3 install adafruit-circuitpython-ssd1306