I'am getting a little PWM signal when my potentiometer is at zero and OCR2B always reads zero on the serial monitor. My LED has low forward voltage but I still get a little PWM on the pin when I prob it. I use timer 1 and it works good. I have a picture of the scope.
#include "RTClib.h"
RTC_DS3231 rtc;
#include <ResponsiveAnalogRead.h>
ResponsiveAnalogRead analog0(A0, true, .001);
unsigned int nowHour;
int analogOutPin3 = 3;
int sensorValueTimer2Pin3;
long z;
int analogOutPin9 = 9;
int analogOutPin10 = 10;
void setup() {
Serial.begin(9600);
//===============mode 5 pin 3,11==================//
TCCR2A |= (1 << COM2A1);
TCCR2A |= (1 << COM2B1);
TCCR2A |= (1 << WGM21);
TCCR2A |= (1 << WGM20);
TCCR2B |= (1 << WGM22);
TCCR2B |= (1 << CS22);
OCR2A = 249; //1KHz frequency
TCNT2 = 0;
//====================mode 5 pin 3,11==============//
pinMode(3, OUTPUT);
rtc.adjust(DateTime(2014, 1, 21, 7, 0, 0));
}
void loop() {
DateTime now = rtc.now();
nowHour = now.hour();
analogWrite(9, LOW);
analogWrite(10, LOW);
analog0.update();
sensorValueTimer2Pin3 = ((analog0.getValue() * 249L) / 1024);
if (nowHour >= 7 && nowHour <= 21) {
z = sensorValueTimer2Pin3;
OCR2B = z;
Serial.println(OCR2B);
}
}