Skip to content
Arnd edited this page Jan 31, 2021 · 1 revision

set( {value} [, {speed}] [, {delay}] );

The set() function is called to set the PWM value of a pin. The PWM value is an integer between 0 ("OFF") and 256 (100% "ON"). If the second parameter is omitted the pin is set to the PWM value immediately, if the second parameter is specified then the LED will fade/brighten from the current setting to the new setting at the speed specified. The speed is given in milliseconds, e.g. a speed of 5000 would change the LED from the current value to that in the {value} parameter over the course of 5 seconds.

The third parameter is optional and specifies how many milliseconds to pause after the command has finished. This is useful when queuing multiple commands that should run in sequence.

The set() function returns immediately and any fading/brightening happens in the background, letting the program continue processing.

If a "set()" is active and another "set()" command is called, the command is put into the queue and only executed upon completion of the active command. Multiple commands can be queued, each takes 7 bytes of RAM and as many commands as will fit into memory can be queued.

The setNow() command can be used to cancel and queued and active commands and immediately perform the set().


Example:

...    
...    
smoothLED Board;
...    
...    
Serial.print(F("BOARD LED: "));
if (Board.begin(LED_BUILTIN)) // Start the "Board" instance on pin 13
  Serial.println(F("OK"));
else
  Serial.println(F("ERROR!"));
Board.set(0); // set to OFF
Board.set(255,10000); // Slowly brighten the LED over 10 seconds
...    
...    
Clone this wiki locally