I'm using your Motor shield to control two DC motor; on the arduino I've implemented a function which allow to play/pause motor. To do it I've used the attachInterrupt function on pin 2 but it doesn't work; I've tested it without the shield and it works. How can I implement a function that allow me to play/pause the execution of the program?
Tnks!
Motor shield Play/Pause function
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
- adafruit_support_bill
- Posts: 88093
- Joined: Sat Feb 07, 2009 10:11 am
Re: Motor shield Play/Pause function
The shield does not use pin 2. What else is your code doing?
-
- Posts: 4
- Joined: Wed Sep 21, 2011 10:17 am
Re: Motor shield Play/Pause function
The code call the Interrupt function already when the button isn't pressed. May be I've solved the problem with a second connection to pin 2: i've connected it to ground using a 10k resistor and it seems working. It is the right solution?
The function where I stop the code is:
void piatto(unsigned long x)
{ unsigned long t = millis();
int stato = 0;
int save = 0;
Serial.println(x);
while(((millis()-t))<x)
{ if(state==1)
{ Serial.println("Tempo inizio pausa");
Serial.println(millis());
x = x + t - millis();
while(state==1)
{ Serial.println("Pause");
}
t = millis();
Serial.println("Tempo fine pausa");
Serial.println(t);
}
Serial.println(settings.v);
}
}
And the function called from interrupt is:
void pause()
{ state = 1-state;
delay(100);
}
The function where I stop the code is:
void piatto(unsigned long x)
{ unsigned long t = millis();
int stato = 0;
int save = 0;
Serial.println(x);
while(((millis()-t))<x)
{ if(state==1)
{ Serial.println("Tempo inizio pausa");
Serial.println(millis());
x = x + t - millis();
while(state==1)
{ Serial.println("Pause");
}
t = millis();
Serial.println("Tempo fine pausa");
Serial.println(t);
}
Serial.println(settings.v);
}
}
And the function called from interrupt is:
void pause()
{ state = 1-state;
delay(100);
}
- adafruit_support_bill
- Posts: 88093
- Joined: Sat Feb 07, 2009 10:11 am
Re: Motor shield Play/Pause function
That's the right solution. A pull-down resistor keeps the input from 'floating' and giving you false interrupts.i've connected it to ground using a 10k resistor and it seems working. It is the right solution?
Please be positive and constructive with your questions and comments.