Trouble programming a variable

hey guys i have just a problem and i don't know how to resolve my problem so i will ask here;
I want to make a variable increase and decrease to a maximun and a minimun value, i will use it to the delay parameter, i explain:

int t = 0 // this is the parameter of the delay time

void loop(){
...
...
delay (t) //now its when appears de t parameter

Now my problem is that for example i want to increase t every loop on 50 until it reaches 1000 and then i want to decrease t(whith 1000 value) every loop on 50 until it reaches 0 and it start again increasing. Im new on this so i dont know how to do this, but i want to learn and i have stock on this part please help me :confused:

che_fntsico.ino (654 Bytes)

if anyone want to see the program i will upload

Yes

there it is take a look i have marked the variable i want to change

Why can't I see it?

int pin1 = 1;
int pin2 = 2;
int pin3 = 3;
int pin4 = 4;
int pin5 = 5;
int out = HIGH;
int A = 1;
int B = 1;
int retraso = 50; //here is my problem
int out2 = !out;
void setup() {
pinMode (pin1, OUTPUT);
pinMode (pin2, OUTPUT);
pinMode (pin3, OUTPUT);
pinMode (pin4, OUTPUT);
pinMode (pin5, OUTPUT);
}

void loop() {
for (int A = 1; A<6; A++){
digitalWrite(A, out);
delay(retraso); // here is the problem
digitalWrite(A, out2);
}
for (int A = 5; A>0; A--){
digitalWrite(A, out);
delay (retraso); //here it's too
digitalWrite (A, out2);
} //how i make it increase and decrease to a max-min value
}

this is the program

Tel us what you think is happening here.

for (int A = 1; A<6; A++)
{
 digitalWrite(A, out);
 delay(retraso);           // here is the problem
 digitalWrite(A, out2);
}

no no i just need to ad code, i dont know the code i have to insert to do the increase amd decrease; the program do this, light led in pin 1 waits x seconds and turn of led in pin 1 and lights leed in pin 2 etc
what i want its to make a code that modify x which its the time that take to light unlight and light next pin. thats my trouble, what should i use:
if/else
for
...
And how i do it

retraso = retraso + 50; this will increase retraso by 50
You can use the 'if()' function to check when retraso >= 1000
etc.

.

The goal here is for you to learn how to write the code...most of us already know how to solve this. So, it would seem to me you need to write a plan (algorithm) that has step-by-step instructions of exactly what you want to do. To do that, you probably should look at the following programming terms:

increment, decrement
if, if-else
for
while

Also, please read Nick Gammon's post at the top of this Forum on the proper was to post here, especially using code tags. Also, use Ctrl-T in the IDE before you post your code. It will help us help you.

the problem is this wht should i put; this?

if (retraso<1001){
retraso=retraso+50;
}
else if(retraso=1000){
retraso=retraso-50;
}

if(retraso=1000){You should know that that doesn't do what you think.

encojack th problem is that i just have read all of the references and i already don't know how to do it i just only want anyone that say me the solution of my problem and explains me the programming terms it has use it and why have it used it like that, if you like i can tlk in spanish, i will explain better my problem.

i read the increment reference, but it only adds 1, y want to add more than one to retraso:
i dont know if it will work but it should be like that?

for (B=1; B<26; B++){
while(retraso<1001){
retraso+50;
}
}
for(B=25; B>0; B--){
while(retraso>0){
retraso-50;
}
}

aletnerdi:
i read the increment reference, but it only adds 1, y want to add more than one to retraso

You did say:
"Now my problem is that for example i want to increase t every loop on 50 until it reaches 1000 "

aletnerdi:
encojack th problem is that i just have read all of the references and i already don't know how to do it i just only want anyone that say me the solution of my problem and explains me the programming terms it has use it and why have it used it like that, if you like i can tlk in spanish, i will explain better my problem.

No, your English is much better than my Spanish. What you need to do is develop the algorithm and then write the code as you think it should work...which I think you have done. Then you need to find out why the result is different than what you think. For example, you can see what is going on better with some debugging statements:

if (retraso<1001){
retraso=retraso+50;
}
else if(retraso=1000){
retraso=retraso-50;
}
Serial.print("retraso = ");
Serial.println(retraso);

AWOL has already given you one hint. Also, look at some examples of using an if statement online by doing a google search on "Arduino C if statement block". Also, start looking at "weird" code and see what it does, again using Serial.print() statements. For example, most C programmers would write:

   retraso += 50;    // instead of retraso=retraso+50;
// and
   retraso -= 50;    // instead of retraso=retraso-50;

I would also encourage you to put spaces before and after operators and expressions; it's makes them easier to read.

LarryD:
You did say:
"Now my problem is that for example i want to increase t every loop on 50 until it reaches 1000 "

Yeah thats what i want to do

aletnerdi:
i read the increment reference, but it only adds 1, y want to add more than one to retraso:
i dont know if it will work but it should be like that?

for (B=1; B<26; B++){
while(retraso<1001){
retraso+50;
}
}
for(B=25; B>0; B--){
while(retraso>0){
retraso-50;
}
}

I think that this is what i'm looking for pleas can anyone check it, an tell me if it's good or either is posible to optimize the code?

please anyone help give me solution pls i'm gonna get crazy

I haven't looked at you code but you should be able to use this in some form -

// <http://forum.arduino.cc/index.php?topic=445638.0>

#include <Arduino.h>

unsigned int next()
{
    static int          inc     = -50;
    static unsigned int value   = 0;
    int                 result  = value;

    inc = ((value <= 0) || (value >= 1000)) ? -inc : inc;
    
    value += inc;

    return result;
}

void loop()
{
    Serial.println(next());
}

void setup()
{
    Serial.begin(9600);
}