B4R Question Stepper motor stuck in program

Cesar_Morisco

Active Member
Olá pessoal,
Alguém poderia me dizer por que meu motor de passo está preso neste programa de digitalização rada.
Já usei timer, CallSubPlus
Ele continua falhando neste programa.
Obrigado desde já

B4R:
Sub Process_Globals
    Public Serial1 As Serial
    'Private Wifi As ESP8266WiFi
    Private ESP As D1Pins
    Private TrigPin, echoPin As Pin
    Private Timer1 As Timer
    Public Led As Pin
    Public angle As Byte
    Public Ultra As SRF04
    Public TargetSpace As Int
    Public maxSpace As Int=80
    Public RadarDelay As Byte=10
    Public TargetDetect As Boolean
    'Motor de Psso
    Public stepper As A4988
    Public MOTOR_STEPS As UInt = 1000 'ANGLOR
    Public RPM As UInt = 12'120
    Public MICROSTEPS As UInt = 1
    Public PIN_DIR As UInt = 04'PINO
    Public PIN_STEP As UInt = 00'PINO
End Sub

Private Sub AppStart
    Serial1.Initialize(115200)
    Log("AppStart")
    
    stepper.Initialize(MOTOR_STEPS,PIN_DIR,PIN_STEP)
    stepper.begin(RPM,MICROSTEPS)

    TrigPin.Initialize(ESP.D6, TrigPin.MODE_OUTPUT)
    echoPin.Initialize(ESP.D5, echoPin.MODE_INPUT)
    Led.Initialize(ESP.D4,Led.MODE_OUTPUT)
    Ultra.Initialize(ESP.D6,ESP.D5)
    Timer1.Initialize("Start_all",1000)
    Timer1.Enabled=True
    Motor_passo(1)
End Sub

Sub Motor_passo(tag As Byte)
    Log("start loop")
    stepper.enable
    stepper.rotate(360)
    stepper.move(-MOTOR_STEPS*MICROSTEPS)
    stepper.disable
    CallSubPlus("Motor_passo",10000,1)
End Sub

Sub Start_all
    Normal
    Do While True
        angle=45
        Do While angle<=135 And angle>=45
        TargetDetect=False
            TargetSpace=Ultra.GetDistance
            Log("D=",angle, "-R=",TargetSpace)
            If TargetSpace<maxSpace Then
                TargetDetect=True
            End If
            angle=angle+1
            Delay(RadarDelay)
        Loop
        If TargetDetect=True Then
            Star
        Else
            Normal
        End If
    Loop
End Sub

public Sub Star
    Led.DigitalWrite(False)
End Sub

public Sub Normal
    Led.DigitalWrite(True)
End Sub
 

Attachments

  • 66860253-d91a8600-ef5a-11e9-9195-c816e329abb8.jpg
    66860253-d91a8600-ef5a-11e9-9195-c816e329abb8.jpg
    105.6 KB · Views: 32
Last edited:
Top