// NeoPixel Ring simple sketch (c) 2013 Shae Erisson
// Released under the GPLv3 license to match the rest of the
// Adafruit NeoPixel library
#include <Adafruit_NeoPixel.h>
// Which pin on the Arduino is connected to the NeoPixels?
#define PIN 15 // On Trinket or Gemma, suggest changing this to 1
int buttonState = 0;
int button=2;
// How many NeoPixels are attached to the Arduino?
#define NUMPIXELS 17 // Popular NeoPixel ring size
Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
//FOR ULTRASONIC
const int trigPin = 5;
const int echoPin = 18;
//define sound speed in cm/uS
#define SOUND_SPEED 0.034
#define CM_TO_INCH 0.393701
long duration;
float distanceCm;
float distanceInch;
//
void setup() {
//FOR ULTRASONIC
pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output
pinMode(echoPin, INPUT); // Sets the echoPin as an Input
//
pinMode(button, INPUT);
pixels.begin(); // INITIALIZE NeoPixel strip object (REQUIRED)
Serial.begin(115200);
for(int i=0; i<NUMPIXELS; i++)
{ // For each pixel...
pixels.setPixelColor(i, pixels.Color(255, 255, 255));
}
pixels.show();
}
void pixelson(){
for(int i=0; i<NUMPIXELS; i++)
{ // For each pixel...
pixels.setPixelColor(i, pixels.Color(0, 0, 0));
}
pixels.show(); // Send the updated pixel colors to the hardware.
}
void loop() {
buttonState = digitalRead(button);
if(buttonState == HIGH){ //ir sensor does not detect motion
Serial.println("ON");
//Serial.println(buttonState);
//pixelson();
}
//FOR ULTRASONIC
// Clears the trigPin
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
// Sets the trigPin on HIGH state for 10 micro seconds
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
// Reads the echoPin, returns the sound wave travel time in microseconds
duration = pulseIn(echoPin, HIGH);
// Calculate the distance
distanceCm = duration * SOUND_SPEED/2;
if (distanceCm < 15.00){
pixelson();
Serial.println("less than 15");
}
}