Need a unique gift idea?
A Pastebin account makes a great Christmas gift
SHARE
TWEET

SimplePwmFrequency.h

a guest Jun 5th, 2016 65 Never
Upgrade to PRO!
ENDING IN00days00hours00mins00secs
 
  1. void setPwmFrequency(int pin, int divisor)
  2. {
  3.     byte mode;
  4.  
  5.     if (pin == 5 || pin == 6 || pin == 9 || pin == 10) {
  6.         switch (divisor) {
  7.             case 1: mode = 0x01; break;
  8.             case 8: mode = 0x02; break;
  9.             case 64: mode = 0x03; break;
  10.             case 256: mode = 0x04; break;
  11.             case 1024: mode = 0x05; break;
  12.             default: return;
  13.         }
  14.  
  15.         if (pin == 5 || pin == 6) {
  16.             TCCR0B = TCCR0B & 0b11111000 | mode;
  17.         } else {
  18.             TCCR1B = TCCR1B & 0b11111000 | mode;
  19.         }
  20.        
  21.     } else if (pin == 3 || pin == 11) {
  22.         switch(divisor) {
  23.             case 1: mode = 0x01; break;
  24.             case 8: mode = 0x02; break;
  25.             case 32: mode = 0x03; break;
  26.             case 64: mode = 0x04; break;
  27.             case 128: mode = 0x05; break;
  28.             case 256: mode = 0x06; break;
  29.             case 1024: mode = 0x7; break;
  30.             default: return;
  31.         }
  32.  
  33.         TCCR2B = TCCR2B & 0b11111000 | mode;
  34.     }
  35. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top