Using 1 Arduino to create 2 unique PWM signals (up to 25 kHz)

preview_player
Показать описание
#include PWM.h

// Setup pwm testing variables
int led1 = 9; // timer1 = pins 9 & 10
int led2 = 3;// timer 2 = pins 11 & 3
int32_t frequency = 20000;

void setup() {
//setup setial printing to test millis functionality
//delay(100);


// Setup the initialization for the PWM testing stuff
InitTimersSafe();
bool success1 = SetPinFrequencySafe(led1,frequency);
bool success2 = SetPinFrequencySafe(led2,frequency/2);
// create an indicator if the setup was a success
if(success1 && success2) {
pinMode(13,OUTPUT);
digitalWrite(13,HIGH);
}


}

void loop() {


int sensorValue1 = analogRead(A0);
int sensorValue2 = analogRead(A1);

// put your main code here, to run repeatedly:
pwmWrite(led1,sensorValue1/4);
pwmWrite(led2,sensorValue2/4);

//long secCount = millis()/1000;
//delay(1000);

}
Рекомендации по теме