Sine8 compilation error

I wanted to test sine8(), but I am getting this:

Compilation error: 'sine8' was not declared in this scope

My code:

#include <Adafruit_NeoPixel.h>

#define PIN 6

// Parameter 1 = number of pixels in strip
// Parameter 2 = pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
//   NEO_KHZ800  800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
//   NEO_KHZ400  400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
//   NEO_GRB     Pixels are wired for GRB bitstream (most NeoPixel products)
//   NEO_RGB     Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
Adafruit_NeoPixel strip = Adafruit_NeoPixel(60, PIN, NEO_GRBW + NEO_KHZ800);

void setup() {
  strip.begin();
  strip.setBrightness(50);  // Initial brightness 50
  strip.show(); // 
}

void loop() 
{

int TOTAL_LEDS = 60;

// Make the lights breathe
for (int i = 0; i < 255; i++) {
// Testing sine8
float intensity = sine8(i);
strip.setBrightness(intensity);
// Now set every LED to that color
for (int ledNumber=0; ledNumber<TOTAL_LEDS; ledNumber++) {

strip.setPixelColor(ledNumber, 255, 0, 0);

}

strip.show();


}
}

Sorry, my last computer class was in 1982 in Fortran 77

The compiler is not lying. There is no function named sine8() in your sketch and the one in the Adafruit library takes a byte as its argument rather than an int

  /*!
    @brief   An 8-bit integer sine wave function, not directly compatible
             with standard trigonometric units like radians or degrees.
    @param   x  Input angle, 0-255; 256 would loop back to zero, completing
                the circle (equivalent to 360 degrees or 2 pi radians).
                One can therefore use an unsigned 8-bit variable and simply
                add or subtract, allowing it to overflow/underflow and it
                still does the expected contiguous thing.
    @return  Sine result, 0 to 255, or -128 to +127 if type-converted to
             a signed int8_t, but you'll most likely want unsigned as this
             output is often used for pixel brightness in animation effects.
  */
  static uint8_t sine8(uint8_t x) {
    return pgm_read_byte(&_NeoPixelSineTable[x]); // 0-255 in, 0-255 out
  }

Your code

  for (int i = 0; i < 255; i++)
  {
    // Testing sine8
    float intensity = sine8(i);

Thank you. For my sketch where is the best place to place

static uint8_t sine8(uint8_t x) {
    return pgm_read_byte(&_NeoPixelSineTable[x]); // 0-255 in, 0-255 out
  };

so it looks right.

I am not clear whether you want to use the sine8() function in the library or write your own based on the one in the library

Which is it ?

Are you understood @UKHeliBob explanation of your error? You called the function with wrong argument. Change the argument type and the error goes out.

I miss understood. All is fine now thanks for the help

I am glad that it is working

Note that if you really wanted to you could have 2 different functions with the same name each taking parameters of different types and each with different code. C++ allows this and which version of the function is called depends on the parameter type passed to the function

This is why you got the original error. The function name was OK but the parameter type was wrong, hence "function not defined"

Use Adafruit_NeoPixel::sine8.

This is not the issue. For better or for worse, int is implicitly converted to byte.
Passing an argument of the wrong type would also result in a different error message.

The reason for OP's error is that the sine8 is not a free function, but a static member function: you have to call it as Adafruit_NeoPixel::sine8(i), as mentioned by oqibidipo.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.