// the number of the LED pin
//const int ledPin = 13; // 16 corresponds to GPIO16
// setting PWM properties
const int freq = 5000;
const int ledChannel = 0;
const int ledChannel1 = 1;
const int resolution = 10;
// setting sine parameters
const int ceiling = 1024;
const int bottomlimit = 65;
const int toplimit = 257; // 10 bit resolution=1024
const int timestep = 7; // sine freq period
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
// configure LED PWM functionalitites
ledcSetup(ledChannel, freq, resolution);
ledcSetup(ledChannel1, freq, resolution);
// attach the channel to the GPIO to be controlled
ledcAttachPin(13, ledChannel);
ledcAttachPin(12, ledChannel1);
}
void loop() {
// put your main code here, to run repeatedly
//int timestep = 2;
for (int degree = 1; degree <= 360; degree++)
{
double rads = PI / 180;
double dutycycle = ((ceiling * sin(1 * degree * rads)) + ceiling) / 2;
// ceiling/(toplimit-bottomlimit)
double range = (dutycycle / (ceiling / (toplimit - bottomlimit)) + bottomlimit);
Serial.println(range);
ledcWrite(ledChannel, range);
ledcWrite(ledChannel1, range);
delay(timestep);
//delay(3);
}
}