#define pinOut 22
//const int pwmChannel = 0;
const int frequency = 500;
const int resolution = 12;
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
ledcAttach(pinOut, frequency, resolution);
}
void loop() {
if (Serial.available()) {
int x = Serial.parseInt();
Serial.println(x);
while (Serial.available()) {
Serial.read();
}
if (x>=0 && x<=4095) {
ledcWrite(pinOut, x);
}
else if (x<0){
ledcWrite(pinOut, 0);
}
else {
ledcWrite(pinOut, 4095);
}
}
delay(10); // this speeds up the simulation
}