int ledPin = 13;
float val1, val2;
int x = 0b00000000;
int i = 0;
int analogValue;
void setup() {
Serial.begin(9600);
// Set pin 13 as an output
pinMode(ledPin, OUTPUT);
// Set pin A0 as an input
pinMode(A0, INPUT);
noInterrupts();
// Set the PWM frequency to 980 Hz
TCCR3B = (TCCR3B & 0b11111000) | 0x02;
// Set up Timer 3 with a prescaler of 64
TCCR3B |= (1 << CS31) | (1 << CS30);
TIMSK3 |= (1 << TOIE3);
OCR3A = 249;
interrupts();
}
void loop() {
// Wait 2 seconds
if (x == 256) {
x = 0;
}
analogWrite(ledPin, x);
val1 = analogRead(A0) * 5.0 / 1023.0 ; // convert to volts
val2 = analogRead(ledPin) * 5.0 / 1023.0; // convert to volts
// Serial.print("Voltage across Photocell resistor: ");
// Serial.print(val1, 3);
// Serial.println("V");
// Serial.print("Voltage across LED resistor: ");
// Serial.print(val2, 3);
// Serial.println("V");
// Serial.print("Voltage across Photocell: ");
// Serial.print(analogRead(A6) * 5.0 / 1023.0, 3);
// Serial.println("V");
// Serial.print("Duty Cycle %: ");
// Serial.print(x * 100 / 255.0);
// Serial.println("%\n");
x++;
delay(2000);
}
ISR(TIMER3_OVF_vect) {
// Read the analog input from pin A0
if (i >= 0 && i <= 1000) {
analogValue = analogRead(A0);
i++;
Serial.println(i);
} else if (i > 1000 && i <= 2000) {
i++;
} else {
i = 0;
}
}