prjbrook

arduino timer play

Jul 22nd, 2019
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. int temp;
  2. void setup() {
  3. // put your setup code here, to run once:
  4.  
  5. }
  6.  
  7. void loop() {
  8. // put your main code here, to run repeatedly:
  9. temp = TIFR0; //TIFR0 "timer interrupt flag register 0". Bit 0 of which is TOV0
  10. temp = temp&&0xb00000001;
  11. temp = temp&(1<<TOV0);//Same as temp&0xb00000001;temp now contains either 1 or 0 depending on TOV0 flag.
  12. if (temp == 1) { //we have overflow
  13. }
  14. //maybe better is
  15. if ( TIFR0 & (1 << TOV0) ){
  16.  
  17. // timer 0 overflowed
  18. //Write a 1 to TOV0 to push it down. Test.
  19. }
  20. TCNT1=0;
  21. TCCR1B = 5;// start timer with /1024 prescale
  22. if (TIFR1 & (1<< TOV1)) {
  23. //timer 1 has overflowed
  24. }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment