# how to stop the cycle for reaching the maximum or minimum value.

everything works well I read the potentiometer and I convert it into values from 11 to 125. where I use two IFs. each with established values. What I want you to do is that in order to reach 255 on the rise you will stay ayi and yano return. and the same when decreasing from 255 to 1 is left in 1. the brightness changes when the potentiometer reading changes both in the maximum and minimum value. You are grateful for your time.

``````#define ac 3
#define bc 9
#define pot A0

int tiempo;
int respot;

void setup()
{
Serial.begin(9600);
pinMode(ac, OUTPUT);
pinMode(bc, OUTPUT);
pinMode(pot, INPUT);
}

void loop()
{
tiempo=map(respot,0,1023,11,125);
Serial.print("valor:");
Serial.println( tiempo);
delayMicroseconds(100);

if(tiempo >= 60) //   maximum value established and the plot begins
for(int i =1; i<= 255; i++)
{
analogWrite(ac, i);
analogWrite(bc, i);
delayMicroseconds (12000);
//when you reach 255 you have to stop
}

if(tiempo <= 50)  // minimum value established and the plot begins
for(int i =255; i>= 1; i--)
{
analogWrite(ac, i);
analogWrite(bc, i);
delayMicroseconds(12000);
// when you reach 1 you have to stop
}

}
``````

what do you mean by "stop"? Do you want your program to halt for the rest of time? Do you want it to pause for some fixed amount of time? If you want it to stop for the rest of time, insert

``````while(1);
``````

which will loop forever until to reset the board

if you want the loop() function to run again, simply insert

``````return;
``````

and the loop() will exit and then get called again.

if you want it to stop for some time (a second to two), then you can insert

``````delay(10000); // wait 10 seconds
return;
``````

Do you just want the value to max-out at 255. If so you just need code like this

``````if (myVal > 255) {
myVal = 255;
}
``````

...R

Thank you very much for helping me, it is just what I needed and they took me out of my doubts.