official skill

Draw square

draw_square.py

Plot a square by alternating the X and Y axis motors.

creativearm
Author
MyRoboBrick
Build
Doodler
Language
MicroPython · SPIKE Prime
draw_square.py
1from spike import Motor2 3x = Motor("A")4y = Motor("C")5pen = Motor("D")6 7def line(motor, degrees):8    motor.run_for_degrees(degrees, 25)9 10def square(side=200):11    pen.run_to_position(0)  # pen down12    # Trace four legs: +X, +Y, -X, -Y so the path closes back to the start.13    for axis, degrees in ((x, side), (y, side), (x, -side), (y, -side)):14        line(axis, degrees)15    pen.run_to_position(90)  # pen up16 17square()

Read every line before running it on real hardware.

Have a skill worth sharing?

Submit your own MicroPython skill. Everything is reviewed for safety before it shows up for other builders.