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
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
}
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
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.
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.
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:
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.
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?