Neopixel 4 Color Wheel Code

Hi folks,

So I know it's probably a really stupid mistake in there somewhere, but I'm having a bit of trouble with a bit of code I wrote to make four sections of color rotate around a 24 pixel wheel.

This is the code:

#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
  #include <avr/power.h>
#endif

#define PIN 6

int first = 0;
int second = 4;
int third = 8;
int fourth = 12;
Adafruit_NeoPixel strip = Adafruit_NeoPixel(24, PIN, NEO_GRB + NEO_KHZ800);

uint32_t blue1 = strip.Color(0, 0, 255);
uint32_t blue2 = strip.Color(51, 51, 255);
uint32_t blue3 = strip.Color(0, 255, 255);

uint32_t yellow1 = strip.Color(255, 255, 0);
uint32_t yellow2 = strip.Color(255, 201, 51);
uint32_t yellow3 = strip.Color(255, 255, 51);

uint32_t orange1 = strip.Color(255, 128, 0);
uint32_t orange2 = strip.Color(255, 154, 0);

uint32_t purple1 = strip.Color(204, 0, 244);
uint32_t Purple2 = strip.Color(153, 0, 153);
uint32_t Purple3 = strip.Color(153, 51, 255);

void setup() {
  // This is for Trinket 5V 16MHz, you can remove these three lines if you are not using a Trinket
  #if defined (__AVR_ATtiny85__)
    if (F_CPU == 16000000) clock_prescale_set(clock_div_1);
  #endif
  // End of trinket special code

  strip.setBrightness(255);
  strip.begin();
  strip.show(); // Initialize all pixels to 'off'
}

void loop() {
  colorWheel(15);
}

void colorWheel(uint8_t wait){
  for(first<24){
    if(second == 23){
      second = 0;
    }
    if(third == 23){
      third = 0;
    }
    if(fourth == 23){
      fourth =0;
    }

    strip.setPixelColor(first, blue1);
    strip.setPixelColor(second, yellow1);
    strip.setPixelColor(third, purple1);
    strip.setPixelColor(fourth, orange1);
    
    first = first + 1;
    second = second + 1;
    third = third + 1;
    fourth = fourth + 1;

    strip.show();
    delay(wait);
  }
}

And the Errors are (yes I named it Four_score)

Four_Score.ino: In function 'void colorWheel(uint8_t)':
Four_Score:47: error: expected ';' before ')' token
Four_Score:73: error: expected primary-expression at end of input
Four_Score:73: error: expected ';' at end of input
Four_Score:73: error: expected primary-expression at end of input
Four_Score:73: error: expected ')' at end of input
Four_Score:73: error: expected statement at end of input
Four_Score:73: error: expected '}' at end of input
expected ';' before ')' token

What I'm confused about is that the errors and the lines they're referencing make no sense. They talk about a missing semi-colon at 47 and I don't see anywhere I didn't put one.

Any help you guys can give would be greatly appreciated, Thanks!

  for(first<24){

You need to read up on for loops. In general they need 3 arguments. First the starting value of the for loop control variable. Second the limit of the for loop variable. Third the amount the for loop variable should change on each iteration of the for loop. Fourth the action(s) to be taken on each iteration of the for loop.

Example

for (int x = 0; x < 8; x++)
{
  Serial.println(x);
  Serial.println(x + 8);
  Serial.println(x + 16);
}

Oh wow, I got for() and while() mixed up... thank you! It works exactly the way I wanted :slight_smile: