// Arduino Telephone Ring Generator Controller
// Produces 20 Hz square wave for 2 seconds, then 4 seconds off.
// Output pins drive an H-bridge, which drives a transformer.
const int A = 8; // H-bridge input A
const int B = 9; // H-bridge input B
// 20 Hz = 50 ms per half-cycle (25 ms high, 25 ms low)
const int halfCycle = 25; // milliseconds
// Ring cadence: 2 seconds ON, 4 seconds OFF
const int ringOnTime = 2000;
const int ringOffTime = 4000;
void setup() {
pinMode(A, OUTPUT);
pinMode(B, OUTPUT);
digitalWrite(A, LOW);
digitalWrite(B, LOW);
}
void loop() {
// --- RING ON (2 seconds) ---
unsigned long start = millis();
while (millis() - start < ringOnTime) {
// Positive half-cycle
digitalWrite(A, HIGH);
digitalWrite(B, LOW);
delay(halfCycle);
// Negative half-cycle
digitalWrite(A, LOW);
digitalWrite(B, HIGH);
delay(halfCycle);
}
// Turn off output during silent period
digitalWrite(A, LOW);
digitalWrite(B, LOW);
// --- RING OFF (4 seconds) ---
delay(ringOffTime);
}