The lib SmartDrive Makes the motor run for 5 seconds (by default). When I want to stop the motor before that time, I click the stop button it works ok. Or else the motor stops by itself in 5s
But, when I want the motor to run for more than 5 seconds I need to put this routine: smd.Run_Unlimited(SmartDrive_Motor_ID_1, SmartDrive_Dir_Reverse, 90); in While - Loop.
At that moment my issue enters because I am not able to stop the motor through the code below. Does anyone have any tips on how to resolve this? Would I have to use interrupt? Would I have to use another task? How to use?
New ui_events.cpp File with issue:
#include <Arduino.h>
#include "ui.h"
#include <SmartDrive.h>
SmartDrive smd = SmartDrive(SmartDrive_DefaultAddress);
bool STOP01 = true;
#define STOP02 0
void run01right(lv_event_t * e)
{
// Your code here
while (STOP01)
{
smd.Run_Unlimited(SmartDrive_Motor_ID_1, SmartDrive_Dir_Reverse, 90);
}
STOP01 = true;
}
void stopmotor01(lv_event_t * e)
{
// Your code here
STOP01 = false;
smd.StopMotor(SmartDrive_Motor_ID_1, SmartDrive_Action_Brake);
STOP01 = true;
}
void run01left(lv_event_t * e)
{
// Your code here
while (STOP01)
{
smd.Run_Unlimited(SmartDrive_Motor_ID_1, SmartDrive_Dir_Forward, 90);
}
STOP01 = true;
}
Note :1) As the First photo below, it is not possible to implement void loop in this case.
@b707 Thanks for the sugestion. Really, I would have to instantiate the function void stopmotor01(lv_event_t * e)
in an object (variable) and read it inside the while <-> Loop. Is this possible? How to do this?
Why. Because if I put the command smd.Run_Unlimited(SmartDrive_Motor_ID_1, SmartDrive_Dir_Reverse, 90); in a while <-> loop the motor soh spins for 5s. I can stop with 2s. But I want to stop it over 5s too.
According to the ide I use, it was still not possible to put void setup/void loop
Lib has all the possibilities, including this one (SmartDrive::Run_Seconds()) that I've already tried as follows:
smd.SmartDrive.Run_Seconds(int motor_id, int direction, byte speed, byte duration, bool wait_for_completion=STOP01, int next_action )
Unfortunately, it didn't work. Because I imagine that during Run_Seconds function it doesn't read the boolean variables it should read. Only in the beginning.
I stay using: smd.Run_Unlimited(SmartDrive_Motor_ID_1, SmartDrive_Dir_Reverse, 90);
In an approach with kotlin/Android things with this Lib (written there in Java, of course) I use this too (Run_Unlimited)