Hi,I am a student in ME. Right now I am doing my capstone. We use chipkit uno32 to control our engine. But now I have some problems using arduino.
Here is my code, just simple one.
int rev=0;
int counter=0;
int Ai=3;
int Ao=4;
int Bi=5;
int Bo=6;
int time;
int time1;
int time2;
const int timemin=100 ;
const int timemax=600;
int a;
int b;
void setup(){
Serial.begin(9600);
attachInterrupt(0,outercounter,FALLING);
attachInterrupt(1,intercounter,RISING);
pinMode(Ai,OUTPUT);
pinMode(Ao,OUTPUT);
pinMode(Bi,OUTPUT);
pinMode(Bo,OUTPUT);
}
void loop(){
int sensorValue=digitalRead(2);
Serial.println(sensorValue);
}
void intercounter(){
counter=0;
rev++;
time=millis();
}
void outercounter()
{
counter=counter+1;
}
When interrupt 1, which is pin 2, rising, it should interrupt the program and reset counter to 0. But now counter only goes up to 1 and back 0. When I Serial print the rev, it looks like how counter it should work.
I also digital read the pin 2. It is good. And also I delete the intercounter, serial print the counter. The counter also works. So I believe it is the code’s problem.
Anyone can help me? Thanks.
Moderator edit:
</mark> <mark>[code]</mark> <mark>
</mark> <mark>[/code]</mark> <mark>
tags added.