Skip to content

Instantly share code, notes, and snippets.

@jan-martinek
Created November 3, 2017 13:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jan-martinek/2b240b1527e4ace438a70cc621652e15 to your computer and use it in GitHub Desktop.
Save jan-martinek/2b240b1527e4ace438a70cc621652e15 to your computer and use it in GitHub Desktop.
Simple turtle graphics script for use with STS-Pi and explorerhat (no pen logic)
#!/usr/bin/env python
# Explorer HAT/pHAT https://shop.pimoroni.com/search?type=product&q=explorer+hat
# STS-Pi https://shop.pimoroni.com/products/sts-pi
import time
import explorerhat
speed = 100
turnCoef = 0.57
def forward(dist):
motorL(speed)
motorR(speed)
time.sleep(dist)
def back(dist):
motorL(-speed)
motorR(-speed)
time.sleep(dist)
def right(deg):
motorL(speed)
motorR(-speed)
time.sleep(deg / 90 * turnCoef)
def left(deg):
motorL(-speed)
motorR(speed)
time.sleep(deg / 90 * turnCoef)
def motorL(speed):
explorerhat.motor.one.speed(speed)
def motorR(speed):
explorerhat.motor.two.speed(speed)
while True:
forward(2);
right(90);
explorerhat.pause()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment