taking input continously while using exit(0)

hi everone I’m Burak.and im newbie.i have a question about programming. i’m trying to get pressure input continously but my void loop turning only 1 times. void loop needs to be turn 1 times beacuse i gave power to motor and then it worked and finally it stopped. i did’nt want it to start to turn again.

how can i get a input which will be indepented from loops. i need to store pressure input everytime even motor stops or work.

#include <Servo.h>//Using servo library to control ESC
Servo esc; //Creating a servo class with name as esc
       // variable to store the value read

void setup()
{
esc.attach(8); //Specify the esc signal pin,Here as D8
Serial.begin(9600);
i
int val;
}
void loop()
{

int analogPin = 3;     // potentiometer wiper (middle terminal) connected to analog pin 3

                      // outside leads to ground and +5V

int pressure = 0;   
 pressure = analogRead(analogPin);
 Serial.println(pressure);

int rpm;
int time;
int minute;
int second;
minute=0;
second=10;
time=(minute*60+second);
rpm=1000;
int val=0;

  for(int x = 0 ; x <= rpm; x=x+50){

val= map(x, 0, 1023,1000,2000); //mapping val to minimum and maximum(Change if needed) 
esc.write(val); //using val as the signal to esc 
delay(500);

Serial.println(x);

if(x>999){
 break;
 }
 }


delay(1000*time);


for(int a = rpm ; a > 0; a=a-100){

val= map(a, 0, 1023,1000,2000); //mapping val to minimum and maximum(Change if needed) 
esc.write(val); //using val as the signal to esc 
delay(500);

Serial.println(a);

if(a<=20){
 break;}
}
exit(0);
}

Hi, Welcome to the forum.

Please read the first post in any forum entitled how to use this forum. http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code. It will be formatted in a scrolling window that makes it easier to read.

Thanks.. Tom.. :)

What is that smiley doing in your code? If you use code tags, that will not happen.

Please edit your post and type [code] before the code and [/code] after the code.

Why do you use exit()?

Hi, esc.write can only be an int that is between 0 and 180. == degrees

Tom... :)

there is smiley beacuse of D8(D-8) im sending data via D-8 pin :D im using brushless motor with esc so i used servo library .

main idea is making a spin coater machine and it needs to start with a acceleration until it reaches the desired rpm than it will stand for a lon time than it will stop with negative acceleration but when this happening i need to check pressure. if pressure is drops dramaticly i will stop the motor. problem is i couldn't take pressure input alltime. when i print the monitor i only see the initial value.

Hi, Please read post #1 and add you code so it can be read properly. And a circuit diagram please.

Tom.... :)

i modified the post for code but i don’t how to make a circuit diagram :frowning:

kahramanburak: but i don't how to make a circuit diagram :(

Just make a pencil drawing and post a photo of the drawing. See this Image Guide

A pencil drawing is usually more informative than a fancy computer diagram.

...R

i uploadted a paint drawing

Hi,
OPs diagram


All looks fine.

You need to develop your code in stages.

  • Get pressure input (potentiometer) reading working and output to Serial.
  • Get pressure threshold level working to turn a variable TRUE if pressure okay, or False if not and output t Serial.
  • Get simple motor control working using Servo library, output to Serial.
  • Get accelerate and decelerate control working. output to Serial.
  • Combine and get TRUE /FALSE of pressure variable to stopf motor.

It sounds long and using Serial tedious, but as you develop your code it will be invaluable in debugging and code structure.

Note Servo,write is 0 to 180, as in degrees.

Tom..... :slight_smile:

Hi, This might be what you want to use

https://www.arduino.cc/en/Reference/ServoWriteMicroseconds

You will have to check if your ESC needs a calibration run.

Tom.... :)

Why is there a connection between the ESC and the Arduino 5v pin?

And it is usual to colour power lines red rather than green. The image of the breadboard is unnecessary.

A simple pencil drawing (without any colour) would be clearer.

...R