//Prepare sketch to control LED brightness connected on data pins D0, D1 and D2 after delay of 1 second on alternate basis using NodeMCU
int switchmode=0;
const int freq = 5000;
const int ledChannel = 0;
const int resolution = 8;
void setup() {
// initialize digital pin LED_BUILTIN as an output.
pinMode(21, OUTPUT);//red
pinMode(19, OUTPUT);//yellow
pinMode(18, OUTPUT);//green
pinMode(12,INPUT);
}
void setup(){
// configure LED PWM functionalitites
ledcSetup(ledChannel, freq, resolution);
// attach the channel to the GPIO to be controlled
ledcAttachPin(ledPin, ledChannel);
}
void loop(){
// increase the LED brightness
for(int dutyCycle = 0; dutyCycle <= 255; dutyCycle++){
// changing the LED brightness with PWM
ledcWrite(ledChannel, dutyCycle);
delay(15);
}
// decrease the LED brightness
for(int dutyCycle = 255; dutyCycle >= 0; dutyCycle--){
// changing the LED brightness with PWM
ledcWrite(ledChannel, dutyCycle);
delay(15);
}
}
// the loop function runs over and over again forever
void loop() {
{
//R-Y-G
digitalWrite(21, HIGH);
delay(1000);
digitalWrite(21, LOW);
delay(1000);
digitalWrite(19, HIGH);
delay(1000);
digitalWrite(19, LOW);
delay(1000);
digitalWrite(18, HIGH);
delay(1000);
digitalWrite(18, LOW);
delay(1000);
//G-Y-R
digitalWrite(18, HIGH);
delay(1000);
digitalWrite(18, LOW);
delay(1000);
digitalWrite(19, HIGH);
delay(1000);
digitalWrite(19, LOW);
delay(1000);
digitalWrite(21, HIGH);
delay(1000);
digitalWrite(21, LOW);
delay(1000); }
}
// the number of the LED pin
const int ledPin = 16; // 16 corresponds to GPIO16
// setting PWM properties