Skip to content

Instantly share code, notes, and snippets.

@gelicia
Created April 29, 2015 15:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gelicia/97fa3aa529a0fa50c5f8 to your computer and use it in GitHub Desktop.
Save gelicia/97fa3aa529a0fa50c5f8 to your computer and use it in GitHub Desktop.
Initial bees code
#include <Adafruit_NeoPixel.h>
/*
* PIR sensor tester
*/
int inputPin = 2; // choose the input pin (for PIR sensor)
int ledPin = 6;
int pirState = LOW; // we start, assuming no motion detected
int val = 0; // variable for reading the pin status
Adafruit_NeoPixel strip = Adafruit_NeoPixel(90, ledPin, NEO_GRB + NEO_KHZ800);
void setup() {
pinMode(inputPin, INPUT); // declare sensor as input
strip.begin();
strip.show(); // In
Serial.begin(9600);
}
void loop(){
rainbow(20);
}
void rainbow(uint8_t wait) {
uint16_t i, j;
for(j=0; j<256; j++) {
val = digitalRead(inputPin);
//Serial.println(val);
for(i=0; i<strip.numPixels(); i++) {
if (val == HIGH){
strip.setPixelColor(i, Wheel((i+j) & 255));
}
else {
strip.setPixelColor(i, 0);
}
}
strip.show();
delay(wait);
}
}
// Input a value 0 to 255 to get a color value.
// The colours are a transition r - g - b - back to r.
uint32_t Wheel(byte WheelPos) {
WheelPos = 255 - WheelPos;
if(WheelPos < 85) {
return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
} else if(WheelPos < 170) {
WheelPos -= 85;
return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
} else {
WheelPos -= 170;
return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment