#include "TimerHelpers.h" int led_pin = 6; //// output OC0B pin 11 (D5) const byte timer0OutputA = 6; // output OC0B pin 11 (D5) const byte timer0OutputB = 5; void setup() { //4mhz //pinMode (timer0OutputA, OUTPUT); // TIMSK0 = 0; // no interrupts // Timer0::setMode (2, Timer0::PRESCALE_1, Timer0::TOGGLE_A_ON_COMPARE); // OCR0A = 1; // count to 2 //4mhz? //pinMode (timer0OutputB, OUTPUT); // TIMSK0 = 0; // no interrupts // Timer0::setMode (7, Timer0::PRESCALE_1, Timer0::CLEAR_B_ON_COMPARE); // OCR0A = 3; // count to 4, zero-relative // OCR0B = 0; // duty cycle // pinMode(11, OUTPUT); // OCR2A = 7; // 19 -> 400kHz, 7 -> 1MHz, 10 -> 727.72kHz // TCCR2A = _BV(COM2A0) | _BV(WGM21) | _BV(WGM20); // Fast PWM mode, OC2A toggle on compare match + =TOP // TCCR2B = _BV(WGM22) | 1; // start timer //100 khz // pinMode (3, OUTPUT) ; // TCCR2A = 0x23 ; // TCCR2B = 0x09 ; // mode 7, clock prescale by 1 // OCR2A = 160-1 ; // 160 clock periods = 10us per cycle // OCR2B =0 ; // TCNT2 =0 ; // analogWrite(3, 127); //others pinMode(led_pin, OUTPUT); //NOTE: Changing this timer 0 affects millis() and delay! TCCR0B = TCCR0B & B11111000 | B00000001; // set timer 0 divisor to 1 for PWM frequency of 62500.00 Hz //TCCR0B = TCCR0B & B11111000 | B00000010; // set timer 0 divisor to 8 for PWM frequency of 7812.50 Hz //TCCR0B = TCCR0B & B11111000 | B00000011; // set timer 0 divisor to 64 for PWM frequency of 976.56 Hz (The DEFAULT) //TCCR0B = TCCR0B & B11111000 | B00000100; // set timer 0 divisor to 256 for PWM frequency of 244.14 Hz //TCCR0B = TCCR0B & B11111000 | B00000101; // set timer 0 divisor to 1024 for PWM frequency of 61.04 Hz analogWrite(led_pin, 127); } void loop() { //analogWrite(led_pin, 127); //analogWrite(3, 50); //analogWrite(timer0OutputB, 60); //Fading the LED // for(int i=0; i<255; i++){ // analogWrite(led_pin, i); // delay(5); // } // for(int i=255; i>0; i--){ // analogWrite(led_pin, i); // delay(5); // } }