Tuesday, October 25, 2011

Timer0 First Program- Polling

/*
  Timer 0 Experiment
 */
int state = 1;
byte ticks, tocks;
long loopCounter;
long popCounter;
unsigned long time;
void setup() {                
  // initialize the digital pin as an output.
  // Pin 13 has an LED connected on most Arduino boards:
  pinMode(13, OUTPUT); 
  TIMSK0 = 0;     //turn off Interrupt for Timer0
  TCCR0B = 5; //Prescaler divieds by 1024 
  Serial.begin(9600);
}

void loop() {

   while(byte(TIFR0 &0x01) ==0){}; // loop til flag goes up
    TIFR0 = 1;      //clear flag
    ticks++;
  
    if (ticks == 60) {
      ticks=0; 
      ToggleLED();
  //    Serial.print("TT ");
    }
}
void ToggleLED(){
  if (state==1) {
    digitalWrite(13,LOW);
    state = 0;
  }
  else {
    digitalWrite(13,HIGH);
    state=1;
 //   Serial.print("I've tohggled");
  } 
} 

No comments:

Post a Comment