Devices & Components
Arduino Uno Rev3
Resistor 220 ohm
LED (generic)
Project description
Code
Internal timer
arduino
1/* 2This program turns on and off a LED on pin 13 each 1 second using an internal timer 3*/ 4 5int timer=0; 6bool state=0; 7void setup() { 8 pinMode(13,OUTPUT); 9 10 TCCR0A=(1<<WGM01); //Set the CTC mode 11 OCR0A=0xF9; //Value for ORC0A for 1ms 12 13 TIMSK0|=(1<<OCIE0A); //Set the interrupt request 14 sei(); //Enable interrupt 15 16 TCCR0B|=(1<<CS01); //Set the prescale 1/64 clock 17 TCCR0B|=(1<<CS00); 18 19 20 21} 22 23void loop() { 24 //in this way you can count 1 second because the nterrupt request is each 1ms 25 if(timer>=1000){ 26 state=!state; 27 timer=0; 28 } 29 30 digitalWrite(13,state); 31 32} 33 34ISR(TIMER0_COMPA_vect){ //This is the interrupt request 35 timer++; 36} 37 38
Downloadable files
schema_jlNkRtLRSE.jpg
schema_jlNkRtLRSE.jpg

schema_jlNkRtLRSE.jpg
schema_jlNkRtLRSE.jpg

Comments
Only logged in users can leave comments