1
我嘗試停下來,重新恢復我的Arduino的中斷定時器他算什麼後500 所以,中斷定時器計數到500,然後拖延幾秒鐘,然後再恢復中斷定時器問:如何啓動和停止Arduino上的中斷定時器?
這是我的代碼,我可以停止中斷,但不知道如何延緩和恢復定時器再次
#define ledPin 13
int count=0;
void setup()
{
pinMode(ledPin, OUTPUT);
Serial.begin(9600);
cli();//stop interrupts
//set timer0 interrupt at 2kHz
TCCR1A = 0;// set entire TCCR0A register to 0
TCCR1B = 0;// same for TCCR0B
TCNT1 = 0;//initialize counter value to 0
// set compare match register for 2khz increments
OCR1A = 124;// = (16*10^6)/(2000*64) - 1 (must be <256)
// turn on CTC mode
TCCR1A |= (1 << WGM01);
// Set CS01 and CS00 bits for 64 prescaler
TCCR1B |= (1 << CS01) | (1 << CS00);
// enable timer compare interrupt
TIMSK1 |= (1 << OCIE1A);
sei();
}
ISR(TIMER1_COMPA_vect) // timer compare interrupt service routine
{
count++;
if(count%2==0)digitalWrite(ledPin,HIGH);
if(count%2==1)digitalWrite(ledPin,LOW);
if(count>=500)
{
count=0;
TCCR1B=0;
digitalWrite(ledPin,LOW);
//TCCR1B |= (1 << CS01) | (1 << CS00);
}
}
void loop()
{
// your program here...
Serial.println(count);
delay(1000);
}
void berhenti()
{
cli();//stop interrupts
digitalWrite(ledPin,LOW);
count=0;
delay(3000);
sei();
}
名爲「berhenti()」的例程的目的是什麼?你有沒有把這個例程叫做? – mhopeng