Error when using test code for rotary encoder

Tryin to use arduino to program my trinket mo with a rotary encoder to control 2 16 pixel rings. I keep getting error on a test code i copied from Arduino Examples | Adafruit Rotary Trinkey | Adafruit Learning System

'NUM_NEOPIXEL' was not declared in this scope

Heres the code

#include <Adafruit_NeoPixel.h>
#include "Adafruit_FreeTouch.h"
#include <RotaryEncoder.h>

// Create the neopixel strip with the built in definitions NUM_NEOPIXEL and PIN_NEOPIXEL
Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUM_NEOPIXEL, PIN_NEOPIXEL, NEO_GRB + NEO_KHZ800);
int16_t neo_brightness = 20; // initialize with 20 brightness (out of 255)

RotaryEncoder encoder(PIN_ENCODER_A, PIN_ENCODER_B, RotaryEncoder::LatchMode::FOUR3);
// This interrupt will do our encoder reading/checking!
void checkPosition() {
  encoder.tick(); // just call tick() to check the state.
}

uint8_t wheel_offset = 99;
int last_rotary = 0;

void setup() {
  Serial.begin(115200);
  //while (!Serial);

  // start neopixels
  strip.begin();
  strip.setBrightness(neo_brightness);
  strip.show(); // Initialize all pixels to 'off'

  attachInterrupt(PIN_ENCODER_A, checkPosition, CHANGE);
  attachInterrupt(PIN_ENCODER_B, checkPosition, CHANGE);
  
  // set up the encoder switch, which is separate from the encoder
  pinMode(PIN_ENCODER_SWITCH, INPUT_PULLDOWN);
}


void loop() {
  // read encoder
  int curr_rotary = encoder.getPosition();
  RotaryEncoder::Direction direction = encoder.getDirection();
  
  if (curr_rotary != last_rotary) {
    Serial.print("Encoder value: ");
    Serial.print(curr_rotary);
    Serial.print(" direction: ");
    Serial.print((int)direction);

    // behavior differs if switch is pressed
    if (!digitalRead(PIN_ENCODER_SWITCH)) {
      // update color
      if (direction == RotaryEncoder::Direction::CLOCKWISE) {
        wheel_offset++;
      }
      if (direction == RotaryEncoder::Direction::COUNTERCLOCKWISE) {
        wheel_offset--;
      }
    } else {
      // update brightness
      if (direction == RotaryEncoder::Direction::CLOCKWISE) {
        neo_brightness += 10;
      }
      if (direction == RotaryEncoder::Direction::COUNTERCLOCKWISE) {
        neo_brightness -= 10;
      }
      // ranges between 0 and 255
      if (neo_brightness > 255) neo_brightness = 255;
      if (neo_brightness < 0) neo_brightness = 0;
    }
    Serial.print(" wheel color: ");
    Serial.print(wheel_offset);
    Serial.print(" brightness: ");
    Serial.println(neo_brightness);

    last_rotary = curr_rotary;

    // update pixels!
    strip.setBrightness(neo_brightness);
    strip.setPixelColor(0, Wheel(wheel_offset));
    strip.show();
  }
}

// Input a value 0 to 255 to get a color value.
// The colours are a transition r - g - b - back to r.
uint32_t Wheel(byte WheelPos) {
  if(WheelPos < 85) {
   return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
  } else if(WheelPos < 170) {
   WheelPos -= 85;
   return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
  } else {
   WheelPos -= 170;
   return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
  }
}

'NUM_NEOPIXEL' was not declared in this scope

Declare and assign a value.

If you are getting started, do so with a code example from the library.

This is because you have no definition of his variable at all. It is up to you to define this, or at least set it a number.

The same goes for PIN_NEOPIXEL As well as a lot of other variables you try and use before you have defined them.

There is no need for pages and pages of compiler output, just the error message would do.

Edit - I see they are gone now.

Yea I deleted it when I realized I messed up entering it. So what’s the correct way to word it? I tried
“Pin 0, 32 Neopixel”. And still got a error

const int LED_COUNT = 108; //total number of leds in the strip
////
// When we setup the NeoPixel library, we tell it how many pixels, and which pin to use to send signals.
Adafruit_NeoPixel leds = Adafruit_NeoPixel( LED_COUNT, 26, NEO_GRB + NEO_KHZ800 );

seems that place holder is the LED count.

so what would be the correct way to word this?

use words such as "adafruit neopixel library" in an internet search thingy.

you could read the documentation, Adafruit NeoPixel - Arduino Reference

I got them working without the rotary encoder. Just trying to add it is what i cant figure out.

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