how can i add dc motor to this?
Hi so I'm pretty new to arduino but I think you could add this code to work also
#define IDLE 0
#define INFLATING 1
#define DEFLATING 2
#define OFF false
#define ON true
byte state = IDLE ;
void start_inflation ()
{
state = INFLATING ;
motor_control (ON) ;
}
void start_deflation ()
{
state = DEFLATING ;
motor_control (OFF) ;
deflate_valve_control (ON) ;
}
void stop_deflation ()
{
state = IDLE ;
deflate_valve_control (OFF) ;
}
void loop ()
{
switch (state)
{
case IDLE:
if (start_button_active ())
start_inflation () ;
break ;
case INFLATING:
if (read_pressure () > MAX_PRESSURE_LIMIT)
start_deflation () ;
break ;
case DEFLATING:
if (read_pressure () < MIN_PRESSURE_LIMIT)
stop_deflation () ;
break ;
}
}
P.S for the experts out there, tell me if there's an error
Your other topic on the same subject deleted.
Please do not duplicate your questions as doing so wastes the time and effort of the volunteers trying to help you as they are then answering the same thing in different places.
Please create one topic only for your question and choose the forum category carefully. If you have multiple questions about the same project then please ask your questions in the one topic as the answers to one question provide useful context for the others, and also you won’t have to keep explaining your project repeatedly.
Repeated duplicate posting could result in a temporary or permanent ban from the forum.
Could you take a few moments to Learn How To Use The Forum
It will help you get the best out of the forum in the future.
Thank you.
Not an error, but my preference for state change would be to have it in the switch statement, not in the functions called from the switch statement. IMO that would make the state machine easier to read, without having to go and check the functions called from it.
Why no stop_inflation();? That would cause a race condition between indlation and deflation.
Where are these functions?
What does this code have to do with the original post?
Do not hijack topics. Start your own topic.
I’m sorry.
I’m pretty new to coding and arduino but thank you for telling me!
Hi, I want to make a 6V dc motor that is powered based on the pressure input by the pressure sensor.
Also I want to include an LCD display that shows the pressure input by MPa unit.
Thank you.
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.
