12V LED strip coding

I am trying to get my LED strip to light up like Pacman.
i have the code from someone on youtube, i try and verify the code on my computer but it says “error compiling for board arduino/genuino Uno”. I am new to this so could some one help me please with the code, i have done the wiring.
The link bellow is what i am trying to do.

LED_strip.ino (2.99 KB)

Welcome to the Forum. Please read this post: How to use this forum - please read. Please post your code using code tags. The code tags make the code look

like this

when posting source code files. It makes it easier to read, and can be copied with a single mouse click. Also, if you don't do it, some of the character sequences in the code can be misinterpreted by the forum code as italics or funny emoticons.

Unless the sketch is too large, it's better if you post your code, rather than attach it. When it's attached, we have to download it, create a folder then open your code in our IDE. And afterwards, the folder remains unless we navigate to the "Temp" folder and manually remove it. It's much easier to just view the code in your post.

The last message may be "error compiling for board arduino/genuino Uno", but you start with the FIRST message, which, when I compile your code, is:

C:\Users\pjs9486\AppData\Local\Temp\REDBIRD_payload_code\REDBIRD_payload_code.ino: In function 'void useInterrupt(boolean)':

REDBIRD_payload_code:239: error: 'init_SENSOR' was not declared in this scope

You have functions defined inside of other functions. You can NOT do that.

I tried fixing the code. I gave up. It is just too big a mess for me to deal with this late in the day.

Thank you for helping.
I managed to sort the code by going in to the library and downloading neopixel by adafruit. :smiley: :smiley:

My next problem is that my LED strip has 4 wires, 1 for 12v and the others for RGB, this code is for 5v LED strip which only has 3 wires, 1 for 5v, 1 for ground and 1 for pin.
Could some one please adjust the code so it works for PIN 11-R ,10-G and 9-B.

I need a pacman light lol!!

Bellow Is the code

#include <Adafruit_NeoPixel.h>

#define PIN 6
#define LAMPS 30

// adafruit init for this particular strip (see adafruit.com)
Adafruit_NeoPixel strip = Adafruit_NeoPixel(LAMPS, PIN, NEO_GRB + NEO_KHZ800);

// we are lighting max 15 leds at the same time, setting the max brightness lower
// allows us to light all the leds from an arduino board without separate power source
// (15 leds * 33mA = 495 mA)
void setup() {
  strip.begin();
  strip.setBrightness(120);    // overall brightness can be 0 to 255
  strip.show();               // Initialize all pixels to 'off'
}

void loop() {
  // white food pixels
  setFood();
  delay(1500);
  
  // pacman eats the food
  eatFood();
  delay(1500);

  // pacman is chased by ghosts
  chasedByGhosts();
  delay(1500);

  // now pacman is chasing the ghosts
  chaseGhosts();
  delay(1500);
}

// the max brightness here can also be reduced to avoid using too much amps
void setFood() {
  // fade in
  for(int br=0; br<170; br++) {
    uint32_t white = strip.Color(br, br, br);
    for(int i=0; i<strip.numPixels(); i+=4) {
        strip.setPixelColor(i, white); 
    }
    strip.show();
    delay(5);
  }
}

void eatFood(){
  uint32_t yellow = strip.Color(255, 255, 0);
  uint32_t off = strip.Color(0, 0, 0);
  
  for(uint16_t i=0; i<strip.numPixels(); i++) {
      strip.setPixelColor(i, yellow);

      if(i>0){
        strip.setPixelColor(i-1, off);
      }
      
      strip.show();
      delay(60);
  }
  strip.setPixelColor(strip.numPixels()-1, off);
  strip.show();
  delay(60);
}

void chasedByGhosts() {
  uint32_t pacman = strip.Color(255, 255, 0);
  uint32_t clyde = strip.Color(249, 154, 0);
  uint32_t blinky = strip.Color(244, 7, 8);
  uint32_t pinky = strip.Color(249, 161, 166);
  uint32_t inky = strip.Color(48, 218, 219);

  // run back
  for(int i=strip.numPixels(); i>-30; i--) {
      // check: color, position, space between pacman and ghost
      checkLed(pacman, i, 0);

      checkLed(clyde, i, 10);
      checkLed(blinky, i, 16);
      checkLed(pinky, i, 22);
      checkLed(inky, i, 28);

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

void chaseGhosts() {
  uint32_t pacman = strip.Color(255, 255, 0);
  uint32_t scaredghost = strip.Color(0, 0, 246);

  // run ghost, run!
  int maximum = strip.numPixels() + 5;
  for(int j = -30; j<maximum; j++) {
      checkLed(scaredghost, j, 28);
      checkLed(scaredghost, j, 22);
      checkLed(scaredghost, j, 16);
      checkLed(scaredghost, j, 10);
      checkLed(pacman, j, 0);
      strip.show();
      delay(60);
  }
}

// check if this position is within the led strip, if yes then show the color
void checkLed(uint32_t color, int i, int offset) {
  int pos = i + offset;

  if(pos < strip.numPixels() && pos > -1){
     strip.setPixelColor(pos, color); 
  }
  // switch off the pixel before and after this one (depends on direction)
  if(pos+1 < strip.numPixels() && pos+1 > -1){
     strip.setPixelColor(pos+1, strip.Color(0, 0, 0));
  } 
  if(pos-1 < strip.numPixels() && pos-1 > -1){
    strip.setPixelColor(pos-1, strip.Color(0, 0, 0));
  } 
}

My next problem is that my LED strip has 4 wires, 1 for 12v and the others for RGB

Those aren't NeoPixels, so the NeoPixel library won't work. Post a link to the LED strip you have.

You are using the wrong kind of LED strip and you will not be able to use that code with your strip.

The code is written for an "ADDRESSABLE" LED strip with smart LEDs, where you can control each individual LED's color/brightness/on-off, etc.

Your strip strip is NON-ADDRESSABLE, aka dumb. You can only control on/off of ALL per color.