Mirror tone() in other pin

Hi, whats up?

I have created a code to generate random frequencies (between 2 values) on pin 9 using tone()

How can I create at same time (i know its not the exact same time, but you know xD) on pin 10 a mirror wave of 9?

I mean, tone() creates for example a 100Hz wave, on pin 9, and what I want is a 100Hz tone, but, moved 180 degrees, when pin 9 is HIGH, pin 10 is LOW, when Pin 9 is LOW, PIN 10 is HIGH.

Its possible? How?

Thanks

Feed pin 9 to an external inverter (common emitter NPN transistor).

Collector will be 180° to input.

1 Like

Yes, i thought about it, i want only know if could be made with programming.

But i seems like a big NO xD

thanks!

Rather than using tone( ), code 100hz in C++.

Toggle pin 9 every 10ms, make pin 10 the compliment of 9.

Hello
Try this

digitalWrite(outPutPin,!digitalRead(tonePin)); 

  if (millis() - toneMillis >= 10)
  {
    //restart the TIMER
    toneMillis = millis();

    //toggle pin 9
    digitalWrite(9, !digitalRead(9));

    //toggle pin 10
    digitalWrite(10, !digitalRead(9));
  }

The tone() function is designed for a single pin. There is no QUICK AND EASY way to have it produce an inverted signal on another pin. The Timer1 hardware in the ATmega328p (UNO, NANO, MINI) can do what you want fairly easily on Pin 9 and Pin 10. Would you like to learn how?

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.