hi! here i have a code to set the timer 2 for phase correct pwm. i am trying to make a temperature controlled fan circuit. So whenever the temperature increases, duty cycle of timer pin increases and fan speeds up. i want an I2C lcd here to display certain things. but when i use the liquid crystal library in the code, fan( timer pin as well) stops working. here is the code :
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,2,1,0,4,5,6,7,3,POSITIVE);
int temp;
void setup() {
pinMode(11,OUTPUT); // put your setup code here, to run once:
TCCR2A = 0;
TCCR2B = 0;
TCNT2 = 0;
TCCR2A = B10100001 ;
TIMSK2 |= (1<<OCIE2B) ;
OCR2B = 0 ; // for interrupt
TCCR2B = B00000001 ;
sei();
}
void loop() {
temp = analogRead(A4)*0.512;
if( temp > 70)
OCR2A = 255 ;
else if(temp< 70 && temp>60)
OCR2A = 200 ;
else if(temp<60 && temp>40)
OCR2A = 150 ;
else if(temp<40 && temp>30)
OCR2A = 100;
else if(temp < 30)
OCR2A = 50 ; // put your main code here, to run repeatedly:
}
please help me to get this work.