Neopixels
Neopixels are programmable, individually addressable, multicolor LEDs. Using only a single data line, the user can individually set the color and brightness of each LED .Thus, without using up pins, a row of neopixels can display a host of status information. Or they can just be beautiful!
Make sure you have imported the Adafruit Neopixel library prior to use( see libraries).
Make sure you have imported the Adafruit Neopixel library prior to use( see libraries).
Neopixel Test Code ( boldface indicates essential code)
// NeoPixelTest code to verify operation of neopixel strip
// shows how to set color, turn On, turn Off
// set length of strip in code
#include <Adafruit_NeoPixel.h>
#include <avr/power.h>
#define PIN 7 // what pin is data in connected to?
#define NUMPIXELS 6 // how many neopixels are there?
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
int LEDnum;
void setup()
{
pixels.begin(); // This initializes the NeoPixel library.
}
void loop()
{
// set pixel colors
pixels.setPixelColor(0, pixels.Color(50,0,0)); // sets color to Moderate Red,etc
pixels.setPixelColor(1, pixels.Color(0,50,0)); // Moderate Green
pixels.setPixelColor(2, pixels.Color(0,0,50)); // Moderate Blue
pixels.setPixelColor(3, pixels.Color(50,50,0)); // Red + Green
pixels.setPixelColor(4, pixels.Color(0,50,50)); // Green + Blue
pixels.setPixelColor(5, pixels.Color(50,0,50)); // Red + Blue
pixels.show(); // Send pixel color to the neopixel hardware.
delay(300);
for (LEDnum=0; LEDnum<NUMPIXELS; LEDnum++) //Turn off all LEDs using a for-loop by setting colors to 0
{
pixels.setPixelColor(LEDnum, pixels.Color(0,0,0)); // Off
}
pixels.show();
delay(300);
}
// shows how to set color, turn On, turn Off
// set length of strip in code
#include <Adafruit_NeoPixel.h>
#include <avr/power.h>
#define PIN 7 // what pin is data in connected to?
#define NUMPIXELS 6 // how many neopixels are there?
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
int LEDnum;
void setup()
{
pixels.begin(); // This initializes the NeoPixel library.
}
void loop()
{
// set pixel colors
pixels.setPixelColor(0, pixels.Color(50,0,0)); // sets color to Moderate Red,etc
pixels.setPixelColor(1, pixels.Color(0,50,0)); // Moderate Green
pixels.setPixelColor(2, pixels.Color(0,0,50)); // Moderate Blue
pixels.setPixelColor(3, pixels.Color(50,50,0)); // Red + Green
pixels.setPixelColor(4, pixels.Color(0,50,50)); // Green + Blue
pixels.setPixelColor(5, pixels.Color(50,0,50)); // Red + Blue
pixels.show(); // Send pixel color to the neopixel hardware.
delay(300);
for (LEDnum=0; LEDnum<NUMPIXELS; LEDnum++) //Turn off all LEDs using a for-loop by setting colors to 0
{
pixels.setPixelColor(LEDnum, pixels.Color(0,0,0)); // Off
}
pixels.show();
delay(300);
}
Programming Challenge: Create functions that use Neopixels to visually display what the vehicle is sensing or doing- i.e., turning left, sensing line, etc.