Arduino Library Use: https://learn.adafruit.com/adafruit-neopixel-uberguide/arduino-library-use
#include <Adafruit_NeoPixel.h>
// Which pin on the Arduino is connected to the NeoPixels? // On a Trinket or Gemma we suggest changing this to 1:
#define LED_PIN 6 // How many NeoPixels are attached to the Arduino?
#define LED_COUNT 60 // Declare our NeoPixel strip object:
Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800);
// Argument 1 = Number of pixels in NeoPixel strip
// Argument 2 = Arduino pin number (most are valid)
// Argument 3 = Pixel type flags, add together as needed:
void setup() { strip.begin();
strip.show(); // Initialize all pixels to 'off'
strip.setPixelColor(n, red, green, blue);
strip.show();
strip.fill(color, first, count);
strip.clear();
#include <NewPing.h>
#define TRIGGER_PIN 12 // Arduino pin tied to trigger pin
#define ECHO_PIN 11 // Arduino pin tied to echo pin on the ultrasonic sensor.
#define MAX_DISTANCE 200 // Maximum distance we want to ping for (in centimeters). Maximum sensor distance is rated at 400-500cm.
NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); // NewPing setup of pins and maximum distance.
#include <Adafruit_NeoPixel.h>
#define PIN 6 //
#define NUMPIXELS 16 //
Adafruit_NeoPixel strip(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
#define DELAYVAL 50 // Time (in milliseconds) to pause between pixels
int distance=0;
void setup() {
strip.begin();
strip.show(); // Initialize all pixels to 'off'
strip.setBrightness(50);
Serial.begin(115200); // Open serial monitor at 115200 baud to see ping results
}
void loop() {
delay(50); // Wait 50ms between pings (about 20 pings/sec). 29ms should be the shortest delay between pings.
Serial.print("Ping: ");
Serial.print(sonar.ping_cm()); // Send ping, get distance in cm and print result (0 = outside set distance range)
Serial.println("cm");
distance= sonar.ping_cm();
if (distance<10){
colorWipe(strip.Color(255, 0, 0), 50); // Red
}
if ((distance >10) && (distance<20)){
colorWipe(strip.Color(0, 255, 0), 50);//blue
}
if (distance >30) {
colorWipe(strip.Color(0, 0, 255), 50);//green
}
}
void colorWipe(uint32_t color, int wait) {
for(int i=0; i<strip.numPixels(); i++) { // For each pixel in strip...
strip.setPixelColor(i, color); // Set pixel's color (in RAM)
strip.show(); // Update strip to match
delay(wait); // Pause for a moment
}
}
#include <DistanceSensor.h>
// Define pins
const int echoPin = 12;
const int trigPin = 13;
// Start the sensor
DistanceSensor sensor(trigPin, echoPin);
#include <Adafruit_NeoPixel.h>
#define PIN 6 //
#define NUMPIXELS 10 //
Adafruit_NeoPixel strip(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
#define DELAYVAL 50 // Time (in milliseconds) to pause between pixels
void setup() {
strip.begin();
strip.show(); // Initialize all pixels to 'off'
strip.setBrightness(50);
Serial.begin(115200); // Open serial monitor at 115200 baud to see ping results
}
void loop() {
int distance = sensor.getCM();
Serial.print("Distance: "); // Write values to serial port
Serial.print(distance);
Serial.println("cm");
if (distance<10){
colorWipe(strip.Color(255, 0, 0), 50); // Red
}
if ((distance >10) && (distance<20)){
colorWipe(strip.Color(0, 255, 0), 50);//green
}
if (distance >30) {
colorWipe(strip.Color(0, 0, 255), 50);//blue
}
}
void colorWipe(uint32_t color, int wait) {
for (int i = 0; i < strip.numPixels(); i++) {
strip.setPixelColor(i, color);
strip.show();
delay(wait);
}
}