Neopixel Fun Times

Hello All,

I recognize I am very late but today’s prototyping session inspired me to write some custom neopixel code.

Thank you Becky, Phuong-Anh, André & Tzu Ching for help with coding, circuitry, as well as by providing all the Arduino components.

The Sharp IR sensor works best in low lit situations

————————-CODE IS BELOW

//this code requires the Sharp.IR code libary and a sharp ir sensor, the VFL has them to lend out
#include <SharpIR.h>

//this specifies what model and pin the sensor is on, i called it sensor
SharpIR sensor(GP2YA41SK0F, A2);

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

#define NUM_LEDS 8

#define BRIGHTNESS 30

//you all know what this is

#define PIN 6

//specify the which type of neopixel strip this is, RGBW
Adafruit_NeoPixel strip = Adafruit_NeoPixel(60, PIN, NEO_RGBW + NEO_KHZ800);

 

void setup()
{
Serial.begin(9600);
strip.begin();
strip.show(); // starts with all the pixels off
}

void loop()
{
int distance = sensor.getDistance(); //distance becomes the number of centimeters something is from the sensor so it can later be recalled

Serial.println(distance); //initializes the distance integer to be displayed on serial monitor

//an if+else reacting to 3cm-10cm distance with a specific color for every individual pixel

if (distance == 3) {
strip.setPixelColor(0,strip.Color(0, 217, 0));
strip.show();
} else {
strip.setPixelColor(0, 0);
strip.show();
}if (distance == 4) {
strip.setPixelColor(1,strip.Color(10, 217, 0));
strip.show();
} else {
strip.setPixelColor(1, 0);
strip.show();
}
if (distance == 5) {
strip.setPixelColor(2,strip.Color(30, 217, 0));
strip.show();
} else {
strip.setPixelColor(2, 0);
strip.show();
}
if (distance == 6) {
strip.setPixelColor(3,strip.Color(60, 200, 0));
strip.show();
} else {
strip.setPixelColor(3, 0);
strip.show();
}
if (distance == 7) {
strip.setPixelColor(4,strip.Color(70, 150, 0));
strip.show();
} else {
strip.setPixelColor(4, 0);
strip.show();
}
if (distance == 8) {
strip.setPixelColor(5,strip.Color(100, 100, 0));
strip.show();
} else {
strip.setPixelColor(5, 0);
strip.show();
}
if (distance == 9) {
strip.setPixelColor(6,strip.Color(150, 50, 0));
strip.show();
} else {
strip.setPixelColor(6, 0);
strip.show();
}
if (distance == 10) {
strip.setPixelColor(7,strip.Color(217, 0, 0));
strip.show();
} else {
strip.setPixelColor(7, 0);
strip.show();
}

}