Timer 1 Arduino - Create 2 Timers

by Neamus   Last Updated September 11, 2019 15:25 PM - source

I’m trying to output 2 separate frequencies using 2 output pins from an Arduino using the Timer 1 library. A snippet of the code is show below.

void setup() 
{
 Serial.begin(9600);
 pinMode(button,INPUT_PULLUP);
 pinMode(button2,INPUT_PULLUP);
 pinMode(sig_out, OUTPUT);
 pinMode(sig_out2, OUTPUT);
Timer1.initialize(1000);
Timer1.pwm(sig_out,512,period);
Timer1.pwm(sig_out2,512,period2); 
}

The issue is the way I’ve wrote this makes sense as I’ve initialised 2 outputs and 2 inputs but the ‘period’ is getting overwritten as there’s 1 timer and I’m not sure how to stop this. I was thinking about storing them in variables (like 'T1=' 'T2=') but it would still use the same timer.

I just wanted to know if there’s a way to use 2 timers so the Arduino outputs the frequencies separately.



Related Questions


Frequency Not Increasing When Button Is Pressed

Updated September 13, 2019 08:25 AM