Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Adafruit_NeoPixel.h>
- #ifdef __AVR__
- #include <avr/power.h>
- #endif
- #define PIN 6
- #define trueNum 64
- #define NUM_PIXELS trueNum
- #define NUM_LEDS trueNum
- #define BRIGHTNESS 100
- int timer = 0;
- //int ratio = 3;
- //double sR = 7.5;
- int sVal = 2;//2
- Adafruit_NeoPixel strip = Adafruit_NeoPixel(trueNum, PIN, NEO_RGB + NEO_KHZ800);
- /*int gamma[] = {
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2,
- 2, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5,
- 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 9, 9, 9, 10,
- 10, 10, 11, 11, 11, 12, 12, 13, 13, 13, 14, 14, 15, 15, 16, 16,
- 17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22, 23, 24, 24, 25,
- 25, 26, 27, 27, 28, 29, 29, 30, 31, 32, 32, 33, 34, 35, 35, 36,
- 37, 38, 39, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 50,
- 51, 52, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 66, 67, 68,
- 69, 70, 72, 73, 74, 75, 77, 78, 79, 81, 82, 83, 85, 86, 87, 89,
- 90, 92, 93, 95, 96, 98, 99,101,102,104,105,107,109,110,112,114,
- 115,117,119,120,122,124,126,127,129,131,133,135,137,138,140,142,
- 144,146,148,150,152,154,156,158,160,162,164,167,169,171,173,175,
- 177,180,182,184,186,189,191,193,196,198,200,203,205,208,210,213,
- 215,218,220,223,225,228,231,233,236,239,241,244,247,249,252,255 };
- */
- /********************************************************************************************************************************************/
- /********************************************************************************************************************************************/
- /********************************************************************************************************************************************/
- void setup() {
- Serial.begin(115200);
- pinMode(13,INPUT);
- pinMode(12,OUTPUT);
- digitalWrite(12,HIGH);
- strip.setBrightness(BRIGHTNESS);
- strip.begin();
- strip.show(); // Initialize all LEDS to 'off'
- }
- /********************************************************************************************************************************************/
- /********************************************************************************************************************************************/
- /********************************************************************************************************************************************/
- void loop() {
- select();
- }
- /********************************************************************************************************************************************/
- /********************************************************************************************************************************************/
- /********************************************************************************************************************************************/
- /*void off(){
- Serial.println("Off");
- for (int led = 0; led < trueNum; led++) {
- setHue(255, led);
- }
- strip.show();
- select();
- }
- /********************************************************************************************************************************************/
- /********************************************************************************************************************************************/
- /********************************************************************************************************************************************/
- void sparkleRain(){
- int fast = 1;
- int vals[NUM_LEDS/fast];
- double ratio = 255.0/(NUM_LEDS/fast);
- for(int i = 0; i<NUM_LEDS/fast;i++){
- vals[i] = int(i*ratio);}
- int index = 0;
- int adjuster = 1;
- int val = 0;
- while(1) {
- if(timer >= 500){
- timer = 0;
- break;
- }
- else{
- timer++;
- Serial.println(timer);
- }
- index++;
- if(index>=NUM_LEDS/fast)index=00;
- for(int i = 0;i<NUM_LEDS/fast;i++){
- int tmp = i+index;
- if(tmp>=NUM_LEDS/fast)tmp-=NUM_LEDS/fast;
- setHue(int(vals[tmp]), i);
- //setHue(int(vals[tmp]), i+NUM_LEDS/fast);
- //setHue(int(vals[tmp]), i+NUM_LEDS/2);
- //setHue(int(vals[tmp]), i+NUM_LEDS/2+NUM_LEDS/fast);
- //if(int(random(0,100))==0)strip.setPixelColor(i,strip.Color(255,255,255));
- }
- strip.show();
- delay(getSpeed());
- }
- select();
- }
- /********************************************************************************************************************************************/
- /********************************************************************************************************************************************/
- /********************************************************************************************************************************************/
- void solidRain(){
- Serial.println(F("SOLID RAIN"));
- //Serial.println(NUM_LEDS);
- //int vals[255];
- //for(int i = 0; i<255;i++){
- // vals[i] = int(i);}
- int index = 0;
- while(1) {
- if(timer >= 500){
- timer = 0;
- break;
- }
- else{
- timer++;
- Serial.println(timer);
- }
- index+=2;
- if(index>=255)index=00;
- for(int i = 0;i<trueNum;i+=1){
- setHue(index, i);
- }
- strip.show();
- delay(getSpeed());
- }
- select();
- }
- /********************************************************************************************************************************************/
- /********************************************************************************************************************************************/
- /********************************************************************************************************************************************/
- /*void colorWipe() {
- while(1){
- if(timer >= 500){
- timer = 0;
- break;
- }
- else{
- timer++;
- Serial.println(timer);
- }
- int color = int(random(0,255));
- for(uint16_t i=0; i<strip.numPixels(); i++) {
- if(timer >= 500){
- timer = 0;
- break;
- }
- else{
- timer++;
- Serial.println(timer);
- }
- setHue(color,i);
- strip.show();
- delay(10);
- }
- select();
- }}
- /********************************************************************************************************************************************/
- /********************************************************************************************************************************************/
- /********************************************************************************************************************************************/
- void colorWipeReturn(){
- while(1){
- if(timer >= 750){
- timer = 0;
- break;
- }
- int color = int(random(0,255));
- for(uint16_t i=0; i<strip.numPixels(); i++) {
- timer++;
- setHue(color,i);
- strip.show();
- delay(getSpeed()-10);
- }
- color = int(random(0,255));
- for(uint16_t i=strip.numPixels()-1; i>0; i--) {
- timer++;
- setHue(color,i);
- strip.show();
- delay(getSpeed()-10);
- }}
- select();
- }
- /********************************************************************************************************************************************/
- /********************************************************************************************************************************************/
- /********************************************************************************************************************************************/
- void changer(){
- while(1){
- if(timer >= 200){
- timer = 0;
- break;
- }
- else{
- timer++;
- Serial.println(timer);
- }
- int color = int(random(0,255));
- for(uint16_t i=0; i<strip.numPixels(); i++) {
- setHue(color,i);
- }
- strip.show();
- delay(450);
- }
- select();
- }
- /********************************************************************************************************************************************/
- /********************************************************************************************************************************************/
- /********************************************************************************************************************************************/
- /*void strobe(){
- for(uint16_t i=0; i<strip.numPixels(); i++) {
- if(i%3 == 0)
- strip.setPixelColor(i,strip.Color(255,255,255));
- else
- strip.setPixelColor(i,strip.Color(0,0,0));
- }
- strip.show();
- delay(getSpeed()*2);
- for(uint16_t i=strip.numPixels()-1; i>0; i=i) {
- //Serial.println(i);
- i--;
- strip.setPixelColor(i,strip.Color(0,0,0));
- }
- strip.show();
- delay(getSpeed());
- select();
- }
- /********************************************************************************************************************************************/
- /********************************************************************************************************************************************/
- /********************************************************************************************************************************************/
- /*void light(){
- for(uint16_t i=0; i<strip.numPixels(); i++) {
- if(i%3 == 0)
- strip.setPixelColor(i,strip.Color(255,255,255));
- else
- strip.setPixelColor(i,strip.Color(0,0,0));
- }
- strip.show();
- delay(getSpeed());
- select();
- }
- /********************************************************************************************************************************************/
- /********************************************************************************************************************************************/
- /********************************************************************************************************************************************/
- /*void whiteOverRainbow() {
- uint8_t whiteLength =3;
- uint8_t whiteSpeed = 20;
- if(whiteLength >= strip.numPixels()) whiteLength = strip.numPixels() - 1;
- int head = whiteLength - 1;
- int tail = 0;
- int loops = 99999;
- int loopNum = 0;
- static unsigned long lastTime = 0;
- int ex = 0;
- while(true){
- int sel = digitalRead(13);
- if(sel == 1){
- ex = 1;
- break;
- }
- for(int j=0; j<256; j++) {
- for(uint16_t i=0; i<strip.numPixels(); i++) {
- if((i >= tail && i <= head) || (tail > head && i >= tail) || (tail > head && i <= head) ){
- strip.setPixelColor(i, strip.Color(255,255,255, 255 ) );
- }
- else{
- setHue((((i * 256 / strip.numPixels()) + j) & 255),i);
- }
- }
- if(millis() - lastTime > whiteSpeed) {
- head++;
- tail++;
- if(head == strip.numPixels()){
- loopNum++;
- }
- lastTime = millis();
- }
- if(loopNum == loops) return;
- head%=strip.numPixels();
- tail%=strip.numPixels();
- strip.show();
- delay(getSpeed());
- }
- }
- select();
- }
- /********************************************************************************************************************************************/
- /********************************************************************************************************************************************/
- /********************************************************************************************************************************************/
- void disco(){
- while(1){
- if(timer >= 200){
- timer = 0;
- break;
- }
- else{
- timer++;
- Serial.println(timer);
- }
- int color = int(random(0,255));
- for(uint16_t i=0; i<strip.numPixels(); i++) {
- if(i%10 == 0)
- color = int(random(0,255));
- setHue(color,i);
- }
- strip.show();
- delay(450);
- }
- select();
- }
- //FOR CHRISTMAS LIGHTS: R:255, lower g and b values, mostly b to get the gold color
- /********************************************************************************************************************************************/
- /********************************************************************************************************************************************/
- /********************************************************************************************************************************************/
- void select(){
- sVal++;
- if(sVal > 4)
- sVal = 0;
- Serial.println(sVal);
- switch(sVal){
- case 0:
- disco();
- break;
- case 1:
- sparkleRain();
- break;
- case 2:
- solidRain();
- break;
- case 3:
- colorWipeReturn();
- break;
- case 4:
- changer();
- break;
- //default:
- // off();
- }
- }
- /********************************************************************************************************************************************/
- /********************************************************************************************************************************************/
- /********************************************************************************************************************************************/
- int getSpeed(){
- /*int spd = int(1000*(double(analogRead(0))/1024.0));
- if(spd <0)
- spd *=-1;
- //Serial.println(spd);
- //int spd = 100;
- */
- int spd = 50;
- return spd;
- }
- /********************************************************************************************************************************************/
- /********************************************************************************************************************************************/
- /********************************************************************************************************************************************/
- /********************************************************************************************************************************************/
- /********************************************************************************************************************************************/
- /********************************************************************************************************************************************/
- void setHue(int h, uint16_t n) {
- //this is the algorithm to convert from RGB to HSV
- double r=0;
- double g=0;
- double b=0;
- double hf=h/42.5; // Not /60 as range is _not_ 0-360
- int i=(int)floor(h/42.5);
- double f = h/42.5 - i;
- double qv = 1 - f;
- double tv = f;
- switch (i)
- {
- case 0:
- r = 1;
- g = tv;
- break;
- case 1:
- r = qv;
- g = 1;
- break;
- case 2:
- g = 1;
- b = tv;
- break;
- case 3:
- g = qv;
- b = 1;
- break;
- case 4:
- r = tv;
- b = 1;
- break;
- case 5:
- r = 1;
- b = qv;
- break;
- }
- int red = constrain((int)255*r,0,255);
- int green = constrain((int)255*g,0,255);
- int blue = constrain((int)255*b,0,255);
- strip.setPixelColor(n,strip.Color(red,green,blue));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement