import serial
from time import sleep
#import pigpio
import cv2

ser = serial.Serial("/dev/ttyACM1" ,115200, timeout=1)
ser.readall()
#ser.write("G28\n")

#qp=pigpio.pi()

#while ser.readline() != "ok\n":
#    pass


sleep(5)


ser.write("G91\n")

#ser.write("G1 X 38 F 2500\n")
sleep(5)

for x in range(1,2):
    for y in range(0,7):
        ser.write("G1 Y 21 F 2500\n")
        sleep(4)
        if x == 0 and y == 9:
            ser.write("G1 X -21\n");
            sleep(2)
            ser.write("G1 E {} F {}\n".format(2, 400))
            ser.write("G1 X 21\n");
        if x == 1 and y == 4:
            ser.write("G1 X -40\n");
            sleep(3)
            ser.write("G1 E {} F {}\n".format(4, 400))
            sleep(3)
            ser.write("G1 X 40 \n");
        #ser.write("G1 E -1\n")
        sleep(2)
    ser.write("G1 X 42 Y -147 F 2500\n")
    sleep(5)
    #if x == 1:
    #    ser.write("G1 X 21\n")

ser.write("G92\n")





