int a=180;
int b=50;
int c=0;
void setup()
{
TCCR5A = 0; // Init Timer1A
TCCR5B = 0; // Init Timer1B
TCCR5B |= B00000111; // External Clock on T1 Pin (RISING)
TCNT5 = 0;
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
pinMode(8, OUTPUT);
TCCR2A = _BV(COM2A1) | _BV(COM2B1) | _BV(WGM21) | _BV(WGM20);
TCCR2B = _BV(CS22);
//TCCR2B |= (1 << CS12) | (1 << CS10);
//TCCR2B = 0x05;
OCR2A = 0;
OCR2B = b;
TCCR4B = 0;
TCCR4A = 0;
// Set the clock prescale to 1
TCCR4B |= (1<<CS10);
// Set TOP to 3999.
// Frequency is 16 MHz / (prescale * (TOP+1)) == 4 kHz.
ICR4 = 200;
// Start at 50% Duty Cycle
OCR4A = 180;
// Set mode to 14: FastPWM using ICR for TOP
TCCR4A |= 1<<WGM41;
TCCR4B |= (1<<WGM42) | (1<<WGM43);
// Select non-inverting FastPWM (higher numbers give higher duty cycle)
TCCR4A |= (1<<COM4A1);
Serial.begin(9600);
}
void loop()
{
//for (int i=0; i<4000; i=i+200)
//OCR4A = i;
delay(1);
b= analogRead(A0);
//c=digitalRead(6);
//delay(5000);
Serial.print("Counter Ticks = ");
Serial.println(TCNT2);//TCNT5
//delay(250);
//a=a+20;
//b=b+20;
//OCR2A = a;
OCR2B =b;
//OCR2A =b;
}