Bapt G
Published © GPL3+

Recognizing numbers with MARK

After my previous project, I decided to go a step further and make MARK follow some numbers on the ground

BeginnerProtip2 hours40
Recognizing numbers with MARK

Things used in this project

Hardware components

seeed MARK
×1

Software apps and online services

Codecraft from Tinkergen
IDE for graphical coding that generates Python code for several products, such as M.A.R.K

Story

Read more

Code

Python code generated by the graphical IDE

Python
# generated by Codecraft for cyberEye
# codes make you happy
from maix_motor import Maix_motor
from gpio import *
from modules import ws2812
import time
from camera import *
from number import *
import utime

class globalvals:
    currentDetected = 0
    CurrentAngle = 0

ws2812_13 = ws2812(fm.board_info.D[13],5,2,3)

def definition_fun():
    pass
    Maix_motor.servo_angle(2, 70)
    globalvals.CurrentAngle = 20
    if globalvals.currentDetected == 0:
        ws2812_13.set_led(1, (255, 0, 0))
        ws2812_13.display()
        ws2812_13.set_led(0, (255, 0, 0))
        ws2812_13.display()
        while not Number.get_number_probabily("1", 50):
            time.sleep(0.02)
            Maix_motor.servo_angle(1, globalvals.CurrentAngle)
            globalvals.CurrentAngle += 10
            if globalvals.CurrentAngle > 150:
                globalvals.CurrentAngle = 20
            utime.sleep_ms(1000);
        globalvals.currentDetected = 1
        ws2812_13.set_led(1, (0, 0, 0))
        ws2812_13.display()
        ws2812_13.set_led(0, (0, 0, 0))
        ws2812_13.display()
    else:
        if globalvals.currentDetected == 1:
            ws2812_13.set_led(1, (255, 233, 0))
            ws2812_13.display()
            ws2812_13.set_led(0, (255, 233, 0))
            ws2812_13.display()
            while not Number.get_number_probabily("2", 50):
                time.sleep(0.02)
                Maix_motor.servo_angle(1, globalvals.CurrentAngle)
                globalvals.CurrentAngle += 10
                if globalvals.CurrentAngle > 150:
                    globalvals.CurrentAngle = 20
                utime.sleep_ms(1000);
            globalvals.currentDetected = 2
            ws2812_13.set_led(1, (0, 0, 0))
            ws2812_13.display()
            ws2812_13.set_led(0, (0, 0, 0))
            ws2812_13.display()
        else:
            if globalvals.currentDetected == 2:
                ws2812_13.set_led(1, (42, 255, 0))
                ws2812_13.display()
                ws2812_13.set_led(0, (42, 255, 0))
                ws2812_13.display()
                while not Number.get_number_probabily("3", 50):
                    time.sleep(0.02)
                    Maix_motor.servo_angle(1, globalvals.CurrentAngle)
                    globalvals.CurrentAngle += 10
                    if globalvals.CurrentAngle > 150:
                        globalvals.CurrentAngle = 20
                    utime.sleep_ms(1000);
                globalvals.currentDetected = 3
                ws2812_13.set_led(1, (0, 0, 0))
                ws2812_13.display()
                ws2812_13.set_led(0, (0, 0, 0))
                ws2812_13.display()
            else:
                if globalvals.currentDetected == 3:
                    ws2812_13.set_led(1, (0, 131, 255))
                    ws2812_13.display()
                    ws2812_13.set_led(0, (0, 131, 255))
                    ws2812_13.display()
                    while not Number.get_number_probabily("4", 50):
                        time.sleep(0.02)
                        Maix_motor.servo_angle(1, globalvals.CurrentAngle)
                        globalvals.CurrentAngle += 10
                        if globalvals.CurrentAngle > 150:
                            globalvals.CurrentAngle = 20
                        utime.sleep_ms(1000);
                    globalvals.currentDetected = 4
                    ws2812_13.set_led(1, (0, 0, 0))
                    ws2812_13.display()
                    ws2812_13.set_led(0, (0, 0, 0))
                    ws2812_13.display()
                else:
                    if globalvals.currentDetected == 4:
                        ws2812_13.set_led(1, (255, 0, 233))
                        ws2812_13.display()
                        ws2812_13.set_led(0, (255, 0, 233))
                        ws2812_13.display()
                        while not Number.get_number_probabily("5", 50):
                            time.sleep(0.02)
                            Maix_motor.servo_angle(1, globalvals.CurrentAngle)
                            globalvals.CurrentAngle += 10
                            if globalvals.CurrentAngle > 150:
                                globalvals.CurrentAngle = 20
                            utime.sleep_ms(1000);
                        globalvals.currentDetected = 5
                        ws2812_13.set_led(1, (0, 0, 0))
                        ws2812_13.display()
                        ws2812_13.set_led(0, (0, 0, 0))
                        ws2812_13.display()
                    else:
                        lcd_display_string_row("fini !!", 1)
                        Maix_motor.motor_run(0, 0, 0)

def definition_fun2():
    pass
    if globalvals.CurrentAngle > 90:
        while not globalvals.CurrentAngle < 90:
            time.sleep(0.02)
            globalvals.CurrentAngle += -5
            Maix_motor.motor_motion(1, 4, 0)
            Maix_motor.servo_angle(1, globalvals.CurrentAngle)
            utime.sleep_ms(100);
    else:
        while not globalvals.CurrentAngle > 90:
            time.sleep(0.02)
            globalvals.CurrentAngle += 5
            Maix_motor.motor_motion(1, 3, 0)
            Maix_motor.servo_angle(1, globalvals.CurrentAngle)
            utime.sleep_ms(100);
    Maix_motor.motor_run(0, 0, 0)
    Maix_motor.motor_motion(1, 1, 0)
    while not get_ultrasonic_distance(4) < 5:
        time.sleep(0.02)
    Maix_motor.motor_run(0, 0, 0)

def start_handler_0():
    pass
    globalvals.currentDetected = 0
    globalvals.CurrentAngle = 0
    while True:
        time.sleep(0.02)
        ws2812_13.set_led(1, (0, 0, 0))
        ws2812_13.display()
        ws2812_13.set_led(0, (0, 0, 0))
        ws2812_13.display()
        definition_fun()
        ws2812_13.set_led(1, (255, 255, 255))
        ws2812_13.display()
        ws2812_13.set_led(0, (255, 255, 255))
        ws2812_13.display()
        definition_fun2()

lcd.clear()
start_handler_0()

Credits

Bapt G

Bapt G

2 projects • 0 followers

Comments