Pololu Robotics & Electronics
Menu
My account Comments or questions? About Pololu Contact Ordering information Distributors

Pololu Forum

Im not sure how to set the values for my LED strip in my Arduino program using the pololu library functions

I’m trying to work on a small project for myself, using a motion sensor and a LED strip so I can make motion activated lights. I’ve been using the Pololu Library to program my LEDs strip, and I’ve looked at the examples in combonation with the github page for the pololu LED library named PololuLedStrip, But cant find what how to set the values for the type rgb_color that’ll allow me to make the LEDs power on and turn a specific color. I understand that the library defines a type named rgb_color which can be used to represent colors. In the example code it seems to make this type an array usually with the array being as long as the amount of LEDs in your LED strip. I also know that this variable type can hold 3 values that represent the amount of red, green, and blue light you want your LEDs to emit. The trouble i’m having is setting those value with a specific notation or command. If anyonw can help that’d be greatly appreciated. I’ll link my code to this post.Motion_Sensing_LEDS.ino (891 Bytes)

My code:

#include <PololuLedStrip.h>

PololuLedStrip<12> ledStrip;

#define LED_COUNT 60
rgb_color colors[LED_COUNT]; // this array variable represents all the LEDs on the strip and what color theyll be using 3 values for red, blue , and green
 
int pirPin = 7; // Input for HC-S501




void setup() {
  // put your setup code here, to run once:
Serial.begin(19200); // set baud rate (rate at which bits are communiccated to the computer from the microcontroller
pinMode(pirPin,INPUT); // this pin will recieve a signal when the

}

void loop() {
  // put your main code here, to run repeatedly:

// detect motion
int Motion_detect = digitalRead(pirPin);

// if motion detected then turn on the LEDs and set them to white
if(Motion_detect == 1)
  {
    for(byte i = 0; i < LED_COUNT; i++)
    {
     colors[i] = {212, 255, 250};
    }

    delay(600000);

    for(byte i = 0; i < LED_COUNT; i++)
    {
      colors[i] = {0, 0, 0};
    
    }

  }
  Serial.println(Motion_detect); // print 
}

Hello.

The way you are setting the colors looks like it should work, except you are missing the command to actually write the colors to the strip, which would look like this:

  ledStrip.write(colors, LED_COUNT); 

From looking at your code, you probably want to call that function after each of your for loops.

Brandon