I have a problem with my project . In this project I should stop my program through a button in a 'for' cycle . In my particular case I have to control the switching on and off a LED with a 'for' cycle . But my problem isn't the switching a led but stop the program whenever I want with a button . In the end when I push the button the program go out to the 'for' cycle . I push the button but the 'for' cycle cycling once again before stop moving I should stopped the cycle immediatly .
void loop() {
if(y==0){
digitalWrite(homing, HIGH);
delay(1000);
digitalWrite(homing, LOW);
delay(1000);
}
if (x==0)
{
delay(5000);
}
pinMode(homingm,INPUT); //homing manuale attraverso un pulsante
pinMode(start,INPUT); // start manuale attraverso pulsante
pinMode(st,INPUT); // stop manuale attraverso un pulsante
pinMode(pausa,INPUT); // pausa manuale attraverso un pulsante
x=1;
y=1;
if(digitalRead(i)!=0){
ilmn=ilmn+1;
}
if(digitalRead(l)!=0){
ilmn=ilmn+2;
}
if(digitalRead(m)!=0){
ilmn=ilmn+4;
}
if(digitalRead(n)!=0){
ilmn=ilmn+8;
}
if(digitalRead(o)!=0){
opqr=opqr+1;
}
if(digitalRead(p)!=0){
opqr=opqr+2;
}
if(digitalRead(q)!=0){
opqr=opqr+4;
}
if(digitalRead(r)!=0){
opqr=opqr+8;
}
ncicli= ilmn && opqr;
if(digitalRead(a)!=0){
abcd=abcd+1;
}
if(digitalRead(b)!=0){
abcd=abcd+2;
}
if(digitalRead(c)!=0){
abcd=abcd+4;
}
if(digitalRead(d)!=0){
abcd=abcd+8;
}
if(digitalRead(e)!=0){
efgh=efgh+1;
}
if(digitalRead(f)!=0){
efgh=efgh+2;
}
if(digitalRead(g)!=0){
efgh=efgh+4;
}
if(digitalRead(h)!=0){
efgh=efgh+8;
}
temperatura= abcd && efgh;
if((digitalRead(homingm)==HIGH) && (digitalRead(start)==LOW))
{
digitalWrite(homing, HIGH);
delay(1000);
digitalWrite(homing, LOW);
delay(1000);
}
if(digitalRead(start)==HIGH)
{
delay(1000);
if(digitalRead(st)==LOW)
{
for (int i=0; i <=5; i++){
if(digitalRead(st)==HIGH)//stop
{
ncicli=0;
i=5;
}
else
{
digitalWrite(homing, LOW);
digitalWrite(pos, HIGH);
delay(del);
digitalWrite(pos, LOW);
delay(del);
}
while(digitalRead(pausa)==HIGH)
{
delay(1000);
}
if(digitalRead(st)==HIGH) //stop
{
ncicli=0;
i=5;
}
}
}
}
}
void loop(1) {
if (del=5000){
{
digitalWrite(homing, HIGH);
delay(1000);
}
}