/* Ping Generates a brief burst of 40-kHz square waves 50 times per second. */ int num_cycles = 20; // Number of cycles in a ping unsigned long interval = 50; // Time interval between pings in ms unsigned long t0 = 0; // Starting time of last ping in ms int state = 0; // State of pin 3 /* Produce num_cycles of a 40-kHz square wave on digital pin 2 */ void ping() { int i; for (i = 0; i=interval) { t0 = t; state = 1-state; // Toggle state between 0 and 1 digitalWrite(3, state); // Make digital pin 3 toggle each time a ping is sent on digital pin 2 ping(); } }