Turtle python code

Here’s the Python code so far for driving the LEDs representing the two stepper motors’ incremental steps. It starts up the system with the first three GPIO ports as outputs (to drive the 74HC595), with the remaining four set to outputs.

Then it has a “for” loop, lighting up LED 1,2,3,4 in a repeating sequence. Those inputs of 1,2,3,4 are then mapped to setting bits 1-4 (i.e. 1, 2, 4, 8), and then the results for “left” and “right” wheels are combined to make (left + 16 x right). This is “fed” bitwise into the 74HC595 data port (GPIO pin 11). Each bit update is then accepted by toggling the GPIO port 12 (a “chew” event), before finally “swallowing” (GPIO port 13) which lights up the LEDs to match the 8 bits (4 each per wheel) previously fed in.

Finally the code sleeps for a second, so I can check LEDs against the prints on screen, before moving on again.

My apologies for lack of comments in the code. I’ll get round to adding this once I stop adding this first batch of features.

Virtual Turtle python code

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.