#define sensorPin A0
#include <Adafruit_NeoPixel.h>
#ifdef _AVR_
#include <avr/power.h> // Required for 16 MHz Adafruit Trinket
#endif
// Which pin on the Arduino is connected to the NeoPixels?
#define PIN 5 // On Trinket or Gemma, suggest changing this to 1
// How many NeoPixels are attached to the Arduino?
#define NUMPIXELS 150 // Popular NeoPixel ring size
// When setting up the NeoPixel library, we tell it how many pixels,
// and which pin to use to send signals. Note that for older NeoPixel
// strips you might need to change the third parameter -- see the
// strandtest example for more information on possible values.
Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
#define DELAYVAL 500
unsigned long lastEvent = 0;
#include <Servo.h>
Servo myservo;
void setup() {
pinMode(sensorPin, INPUT); // Set sensor pin as an INPUT
Serial.begin(9600);
myservo.attach(6);
//////////////////////////////////
#if defined(_AVR_ATtiny85_) && (F_CPU == 16000000)
clock_prescale_set(clock_div_1);
#endif
// END of Trinket-specific code.
pixels.begin();
void loop() {
// Read Sound sensor
pixels.clear();
int sensorData = analogRead(sensorPin);
Serial.println(sensorData);
// If pin goes LOW, sound is detected
if(sensorData > 400){
for (int pos = 70; pos <= 130; pos += 5) { // goes from 0 degrees to 180 degrees
// in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(1); // waits 15 ms for the servo to reach the position
for (int pos = 130; pos >= 70; pos -= 5) { // goes from 180 degrees to 0 degrees
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(1); // waits 15 ms for the servo to reach the position
for(int i=0; i<50; i++) { // For each pixel...
pixels.setPixelColor(i, pixels.Color(255, 50, 0));
pixels.show(); // Send the updated pixel colors to the hardware.
for(int i=50; i<100; i++) { // For each pixel...
pixels.setPixelColor(i, pixels.Color(100, 100, 100));
pixels.show(); // Send the updated pixel colors to the hardware.
for(int i=100; i<NUMPIXELS; i++) { // For each pixel...
pixels.setPixelColor(i, pixels.Color(0, 255, 0));
pixels.show(); // Send the updated pixel colors to the hardware.
delay(100);
// colorWipe(strip.Color(random(0, 255), random(0, 255), random(0, 255)), 0); // Red
// strip.setBrightness(map(sensorData, 500, 1023, 0, 255));
// delay(10);
pixels.clear();
else
pixels.clear();
for(int i=100; i<NUMPIXELS; i++) { // For each pixel...
pixels.setPixelColor(i, pixels.Color(0, 0, 0));
pixels.show(); // Send the updated pixel colors to the hardware.
myservo.write(90);