Skip to content

begin()

Arnd edited this page Jan 31, 2021 · 2 revisions

begin( {pin number} [, {flags}] );

The begin() function is called by passing the Arduino pin number that the LED is attached to. The second parameter is optional and allows setting of various flags. These flags are additive, e.g. "begin(13,NO_CIE_MODE+INVERT_LED+SOFTWARE_MODE);" to set all 3:

  • NO_INVERT_LED (default)
  • CIE_MODE (default)
  • HARDWARE_MODE (default) - use hardware PWM on pins that support it, ignored on other pins
  • INVERT_LED - used when the LED cathode is connected to + and when the LED is lit when the pin is set low
  • NO_CIE_MODE - do not apply (CIE 1931)[https://github.com/Zanduino/SmoothLED_8bit/wiki/CIE1931-Compensation] compensation
  • SOFTWARE_MODE - use softtware PWM on the pin, even if hardware PWM is supported

Each LED pin needs to have a begin() call in order to be activated.


Example:

...    
...    
smoothLED Board, Red;  // Instantiate 2 LEDs     
const uint8_t RED_PIN{11};
...    
...    
Serial.print(F("BOARD LED: "));
if (Board.begin(LED_BUILTIN,SOFTWARE_MODE)) // Start the "Board" instance on pin 13 in software mode
  Serial.println(F("OK"));
else
  Serial.println(F("ERROR!"));
Board.set(128); // set to 50% duty cycle
Serial.print(F("BOARD LED: "));
if (Red.begin(RED_PIN,INVERT_LED+NO_CIE_MODE)) // Red pin inverted and no CIE adjustment
  Serial.println(F("OK"));
else
  Serial.println(F("ERROR!"));
Red.set(0); // Turn pin off
...    
...    
Clone this wiki locally