//
// capacitor.ino - written by Ted Burke - 30-Nov-2022
//
// Generates a 0.05 Hz square wave (T = 20 s) on D3
// to periodically charge and discharge an RC network.
// The capacitor voltage v_c is sampled on A0 (f_s ≈ 10 Hz)
// and printed for plotting in the Serial Plotter.
//
void setup()
{
Serial.begin(9600);
pinMode(3, OUTPUT);
}
void loop()
{
float v_c; // capacitor voltage in volts
// Square wave output on D3, T = 20 s, f = 0.05 Hz
digitalWrite(3, millis() % 20000 > 10000);
// Sample v_c on analog input A0, convert from du to volts and print
v_c = analogRead(0) * (5.0 / 1023.0);
Serial.println(v_c);
delay(100); // 100 ms delay
}