I've been developing a function to simulate a vehicle atuated narrow passage traffic lights and need it to stand on green until recieve an input, then the program continues the cycle until phase 3, when it is on phase 3 and recieves input it increases 3 seconds to that timer with a limit of 20sec max.
Here is the code.
void mod8(void){
policia();
int fase = 0;
int proc = 0;
switch(fase){
case 0:
verde_1_on();
vermelho_2_on();
if(!digitalRead(E0)){
delay(3000);
fase++;
}
break;
case 1:
amarelo_1_on();
vermelho_2_on();
delay(3000);
fase++;
break;
case 2:
vermelho_1_on();
vermelho_2_on();
delay(30000);
fase++;
break;
case 3:
vermelho_1_on();
verde_2_on();
if(!digitalRead(E1) && fase==3){
proc += 3000;
}
delay(3000);
fase++;
break;
case 4:
vermelho_1_on();
amarelo_1_on();
delay(3000);
fase++;
break;
case 5:
vermelho_1_on();
vermelho_2_on();
delay(30000);
fase = 0;
break;
In my experience the easiest way to tidy up the code and add the code tags is as follows
Start by tidying up your code by using Tools/Auto Format in the IDE to make it easier to read. Then use Edit/Copy for Forum and paste what was copied in a new reply. Code tags will have been added to the code to make it easy to read in the forum thus making it easier to provide help.
My project has many files with a lot of code, cant upload it all.
The code doesnt stop on phase 0 and it just runs the whole cicle without pauses specified on my requirements.
Please try and make a state diagram that clearly describes each state, and the condition(s) that make the system go from one state to the next. This may make the text above easier to understand for others, but it will also help you to be clear and consistent in designing your state logic.
Without further information it is going to be difficult to provide help. For instance, where is the fase variable declared, what data type is it, is its value changed elsewhere in the code, does the code use arrays and if so are their bounds being exceeded thus overwriting the value of another variable, etc, etc
While I understand the sentiment the OP has made it clear that his company has created the board. It is up to individual helpers whether they are happy to offer advice in these circumstances, if not then they are under no obligation to help. I don't see any reason to attack the OP for asking for help for a company project, just don't help if you don't want to.