Guest User

SimplePwmFrequency.h

a guest
Jun 5th, 2016
108
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×