├── audio-stuff ├── audio-stuff2.ino ├── audio-stuff3.ino └── audio-stuff.ino ├── README.md ├── puck-js └── code.js ├── led-patterns-1 ├── makeColor.ino └── led-patterns-1.ino ├── led-rainbow-test2 ├── makeColor.ino └── led-rainbow-test2.ino ├── mini-glonut-patterns ├── makeColor.ino ├── audio-test1 │ └── audio-test1.ino └── mini-glonut-patterns.ino ├── octo-led-rainbow-1 └── Rainbow │ ├── makeColor.ino │ └── Rainbow.ino ├── new-patterns-3 └── new-patterns-3.ino ├── audio-patterns-1 └── audio-patterns-1.ino ├── new-patterns-1 └── new-patterns-1.ino └── led-test1 └── led-test1.ino └── led-test1.ino.ino /audio-stuff/audio-stuff2.ino: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /audio-stuff/audio-stuff3.ino: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Hardware projects 2 | 3 | By [Tim Scanlin](timscanlin.net), check out [my blog](http://blog.timscanlin.net/) too! 4 | -------------------------------------------------------------------------------- /puck-js/code.js: -------------------------------------------------------------------------------- 1 | var http = require("http"); 2 | 3 | var on = false; 4 | 5 | var options = { 6 | host: "192.168.1.20", 7 | path: "/CasaTunes/CasaService.svc/SetZonePower", 8 | method: "POST", 9 | data: { 10 | Power :on, 11 | ZoneID: 9 12 | } 13 | }; 14 | 15 | setWatch(function(e) { 16 | console.log("Button pressed"); 17 | on = !on; 18 | LED1.write(on); 19 | 20 | http.request(options, function(res) { 21 | res.on('data', function(data) { 22 | console.log(data); 23 | }); 24 | }); 25 | 26 | }, BTN, { repeat: true, debounce:50, edge: 'rising' }); 27 | // you'll need to use edge: 'falling' if you connected the button to 0v -------------------------------------------------------------------------------- /led-patterns-1/makeColor.ino: -------------------------------------------------------------------------------- 1 | // Convert HSL (Hue, Saturation, Lightness) to RGB (Red, Green, Blue) 2 | // 3 | // hue: 0 to 359 - position on the color wheel, 0=red, 60=orange, 4 | // 120=yellow, 180=green, 240=blue, 300=violet 5 | // 6 | // saturation: 0 to 100 - how bright or dull the color, 100=full, 0=gray 7 | // 8 | // lightness: 0 to 100 - how light the color is, 100=white, 50=color, 0=black 9 | // 10 | int makeColor(unsigned int hue, unsigned int saturation, unsigned int lightness) 11 | { 12 | unsigned int red, green, blue; 13 | unsigned int var1, var2; 14 | 15 | if (hue > 359) hue = hue % 360; 16 | if (saturation > 100) saturation = 100; 17 | if (lightness > 100) lightness = 100; 18 | 19 | // algorithm from: http://www.easyrgb.com/index.php?X=MATH&H=19#text19 20 | if (saturation == 0) { 21 | red = green = blue = lightness * 255 / 100; 22 | } else { 23 | if (lightness < 50) { 24 | var2 = lightness * (100 + saturation); 25 | } else { 26 | var2 = ((lightness + saturation) * 100) - (saturation * lightness); 27 | } 28 | var1 = lightness * 200 - var2; 29 | red = h2rgb(var1, var2, (hue < 240) ? hue + 120 : hue - 240) * 255 / 600000; 30 | green = h2rgb(var1, var2, hue) * 255 / 600000; 31 | blue = h2rgb(var1, var2, (hue >= 120) ? hue - 120 : hue + 240) * 255 / 600000; 32 | } 33 | return (red << 16) | (green << 8) | blue; 34 | } 35 | 36 | unsigned int h2rgb(unsigned int v1, unsigned int v2, unsigned int hue) 37 | { 38 | if (hue < 60) return v1 * 60 + (v2 - v1) * hue; 39 | if (hue < 180) return v2 * 60; 40 | if (hue < 240) return v1 * 60 + (v2 - v1) * (240 - hue); 41 | return v1 * 60; 42 | } 43 | 44 | 45 | // alternate code: 46 | // http://forum.pjrc.com/threads/16469-looking-for-ideas-on-generating-RGB-colors-from-accelerometer-gyroscope?p=37170&viewfull=1#post37170 47 | -------------------------------------------------------------------------------- /led-rainbow-test2/makeColor.ino: -------------------------------------------------------------------------------- 1 | // Convert HSL (Hue, Saturation, Lightness) to RGB (Red, Green, Blue) 2 | // 3 | // hue: 0 to 359 - position on the color wheel, 0=red, 60=orange, 4 | // 120=yellow, 180=green, 240=blue, 300=violet 5 | // 6 | // saturation: 0 to 100 - how bright or dull the color, 100=full, 0=gray 7 | // 8 | // lightness: 0 to 100 - how light the color is, 100=white, 50=color, 0=black 9 | // 10 | int makeColor(unsigned int hue, unsigned int saturation, unsigned int lightness) 11 | { 12 | unsigned int red, green, blue; 13 | unsigned int var1, var2; 14 | 15 | if (hue > 359) hue = hue % 360; 16 | if (saturation > 100) saturation = 100; 17 | if (lightness > 100) lightness = 100; 18 | 19 | // algorithm from: http://www.easyrgb.com/index.php?X=MATH&H=19#text19 20 | if (saturation == 0) { 21 | red = green = blue = lightness * 255 / 100; 22 | } else { 23 | if (lightness < 50) { 24 | var2 = lightness * (100 + saturation); 25 | } else { 26 | var2 = ((lightness + saturation) * 100) - (saturation * lightness); 27 | } 28 | var1 = lightness * 200 - var2; 29 | red = h2rgb(var1, var2, (hue < 240) ? hue + 120 : hue - 240) * 255 / 600000; 30 | green = h2rgb(var1, var2, hue) * 255 / 600000; 31 | blue = h2rgb(var1, var2, (hue >= 120) ? hue - 120 : hue + 240) * 255 / 600000; 32 | } 33 | return (red << 16) | (green << 8) | blue; 34 | } 35 | 36 | unsigned int h2rgb(unsigned int v1, unsigned int v2, unsigned int hue) 37 | { 38 | if (hue < 60) return v1 * 60 + (v2 - v1) * hue; 39 | if (hue < 180) return v2 * 60; 40 | if (hue < 240) return v1 * 60 + (v2 - v1) * (240 - hue); 41 | return v1 * 60; 42 | } 43 | 44 | 45 | // alternate code: 46 | // http://forum.pjrc.com/threads/16469-looking-for-ideas-on-generating-RGB-colors-from-accelerometer-gyroscope?p=37170&viewfull=1#post37170 47 | -------------------------------------------------------------------------------- /mini-glonut-patterns/makeColor.ino: -------------------------------------------------------------------------------- 1 | // Convert HSL (Hue, Saturation, Lightness) to RGB (Red, Green, Blue) 2 | // 3 | // hue: 0 to 359 - position on the color wheel, 0=red, 60=orange, 4 | // 120=yellow, 180=green, 240=blue, 300=violet 5 | // 6 | // saturation: 0 to 100 - how bright or dull the color, 100=full, 0=gray 7 | // 8 | // lightness: 0 to 100 - how light the color is, 100=white, 50=color, 0=black 9 | // 10 | int makeColor(unsigned int hue, unsigned int saturation, unsigned int lightness) 11 | { 12 | unsigned int red, green, blue; 13 | unsigned int var1, var2; 14 | 15 | if (hue > 359) hue = hue % 360; 16 | if (saturation > 100) saturation = 100; 17 | if (lightness > 100) lightness = 100; 18 | 19 | // algorithm from: http://www.easyrgb.com/index.php?X=MATH&H=19#text19 20 | if (saturation == 0) { 21 | red = green = blue = lightness * 255 / 100; 22 | } else { 23 | if (lightness < 50) { 24 | var2 = lightness * (100 + saturation); 25 | } else { 26 | var2 = ((lightness + saturation) * 100) - (saturation * lightness); 27 | } 28 | var1 = lightness * 200 - var2; 29 | red = h2rgb(var1, var2, (hue < 240) ? hue + 120 : hue - 240) * 255 / 600000; 30 | green = h2rgb(var1, var2, hue) * 255 / 600000; 31 | blue = h2rgb(var1, var2, (hue >= 120) ? hue - 120 : hue + 240) * 255 / 600000; 32 | } 33 | return (red << 16) | (green << 8) | blue; 34 | } 35 | 36 | unsigned int h2rgb(unsigned int v1, unsigned int v2, unsigned int hue) 37 | { 38 | if (hue < 60) return v1 * 60 + (v2 - v1) * hue; 39 | if (hue < 180) return v2 * 60; 40 | if (hue < 240) return v1 * 60 + (v2 - v1) * (240 - hue); 41 | return v1 * 60; 42 | } 43 | 44 | 45 | // alternate code: 46 | // http://forum.pjrc.com/threads/16469-looking-for-ideas-on-generating-RGB-colors-from-accelerometer-gyroscope?p=37170&viewfull=1#post37170 47 | -------------------------------------------------------------------------------- /octo-led-rainbow-1/Rainbow/makeColor.ino: -------------------------------------------------------------------------------- 1 | // Convert HSL (Hue, Saturation, Lightness) to RGB (Red, Green, Blue) 2 | // 3 | // hue: 0 to 359 - position on the color wheel, 0=red, 60=orange, 4 | // 120=yellow, 180=green, 240=blue, 300=violet 5 | // 6 | // saturation: 0 to 100 - how bright or dull the color, 100=full, 0=gray 7 | // 8 | // lightness: 0 to 100 - how light the color is, 100=white, 50=color, 0=black 9 | // 10 | int makeColor(unsigned int hue, unsigned int saturation, unsigned int lightness) 11 | { 12 | unsigned int red, green, blue; 13 | unsigned int var1, var2; 14 | 15 | if (hue > 359) hue = hue % 360; 16 | if (saturation > 100) saturation = 100; 17 | if (lightness > 100) lightness = 100; 18 | 19 | // algorithm from: http://www.easyrgb.com/index.php?X=MATH&H=19#text19 20 | if (saturation == 0) { 21 | red = green = blue = lightness * 255 / 100; 22 | } else { 23 | if (lightness < 50) { 24 | var2 = lightness * (100 + saturation); 25 | } else { 26 | var2 = ((lightness + saturation) * 100) - (saturation * lightness); 27 | } 28 | var1 = lightness * 200 - var2; 29 | red = h2rgb(var1, var2, (hue < 240) ? hue + 120 : hue - 240) * 255 / 600000; 30 | green = h2rgb(var1, var2, hue) * 255 / 600000; 31 | blue = h2rgb(var1, var2, (hue >= 120) ? hue - 120 : hue + 240) * 255 / 600000; 32 | } 33 | return (red << 16) | (green << 8) | blue; 34 | } 35 | 36 | unsigned int h2rgb(unsigned int v1, unsigned int v2, unsigned int hue) 37 | { 38 | if (hue < 60) return v1 * 60 + (v2 - v1) * hue; 39 | if (hue < 180) return v2 * 60; 40 | if (hue < 240) return v1 * 60 + (v2 - v1) * (240 - hue); 41 | return v1 * 60; 42 | } 43 | 44 | // alternate code: 45 | // http://forum.pjrc.com/threads/16469-looking-for-ideas-on-generating-RGB-colors-from-accelerometer-gyroscope?p=37170&viewfull=1#post37170 46 | -------------------------------------------------------------------------------- /new-patterns-3/new-patterns-3.ino: -------------------------------------------------------------------------------- 1 | /* 2 | fft_adc_serial.pde 3 | guest openmusiclabs.com 7.7.14 4 | example sketch for testing the fft library. 5 | it takes in data on ADC0 (Analog0) and processes them 6 | with the fft. the data is sent out over the serial 7 | port at 115.2kb. 8 | */ 9 | 10 | #define LOG_OUT 1 // use the log output function 11 | #define FFT_N 256 // set to 256 point fft 12 | 13 | #include // include the library 14 | 15 | void setup() { 16 | Serial.begin(9600); // use the serial port 17 | TIMSK0 = 0; // turn off timer0 for lower jitter 18 | ADCSRA = 0xe5; // set the adc to free running mode 19 | ADMUX = 0x40; // use adc0 20 | DIDR0 = 0x01; // turn off the digital input for adc0 21 | } 22 | 23 | void loop() { 24 | while(1) { // reduces jitter 25 | cli(); // UDRE interrupt slows this way down on arduino1.0 26 | for (int i = 0 ; i < 512 ; i += 2) { // save 256 samples 27 | while(!(ADCSRA & 0x10)); // wait for adc to be ready 28 | ADCSRA = 0xf5; // restart adc 29 | byte m = ADCL; // fetch adc data 30 | byte j = ADCH; 31 | int k = (j << 8) | m; // form into an int 32 | k -= 0x0200; // form into a signed int 33 | k <<= 6; // form into a 16b signed int 34 | fft_input[i] = k; // put real data into even bins 35 | fft_input[i+1] = 0; // set odd bins to 0 36 | } 37 | fft_window(); // window the data for better frequency response 38 | fft_reorder(); // reorder the data before doing the fft 39 | fft_run(); // process the data in the fft 40 | fft_mag_log(); // take the output of the fft 41 | sei(); 42 | Serial.println("start"); 43 | for (byte i = 0 ; i < FFT_N/2 ; i++) { 44 | Serial.print(fft_log_out[i]); // send out the data 45 | Serial.print(", "); 46 | } 47 | Serial.println(""); 48 | //Serial.write(255); // send a start byte 49 | //Serial.write(fft_log_out, 128); // send out the data 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /audio-patterns-1/audio-patterns-1.ino: -------------------------------------------------------------------------------- 1 | #include "FastLED.h" 2 | 3 | #define NUM_LEDS 182 4 | #define LEDS_STRIP 26 5 | #define CLOCK_PIN 13 6 | #define LED_PIN 3 7 | #define DATA_PIN 3 8 | #define COLOR_ORDER GRB 9 | #define CHIPSET WS2811 // WS2811 LPD8806 10 | #define FREQ_COUNT 7 11 | 12 | #define BRIGHTNESS 255 // reduce power consumption 13 | #define LED_DITHER 255 // try 0 to disable flickering 14 | #define CORRECTION TypicalLEDStrip 15 | 16 | CRGB leds[NUM_LEDS]; // Define the array of leds 17 | 18 | // MSGEQ7 19 | #include "MSGEQ7.h" 20 | #define pinAnalogLeft A0 21 | #define pinAnalogRight A1 22 | #define pinReset 8 23 | #define pinStrobe 7 24 | #define MSGEQ7_INTERVAL ReadsPerSecond(50) 25 | #define MSGEQ7_SMOOTH 191 26 | 27 | CMSGEQ7 MSGEQ7; 28 | 29 | int hue = 0; 30 | 31 | void setup() { 32 | Serial.begin(115200); 33 | 34 | // FastLED setup 35 | FastLED.addLeds(leds, NUM_LEDS).setCorrection(CORRECTION); 36 | FastLED.setBrightness( BRIGHTNESS ); 37 | FastLED.setDither(LED_DITHER); 38 | FastLED.show(); // needed to reset leds to zero 39 | 40 | // This will set the IC ready for reading 41 | MSGEQ7.begin(); 42 | } 43 | 44 | void loop() { 45 | // Analyze without delay 46 | bool newReading = MSGEQ7.read(MSGEQ7_INTERVAL); 47 | 48 | // Led strip output 49 | if (newReading) { 50 | for (int x = 0; x < FREQ_COUNT; x++) { 51 | uint8_t val = MSGEQ7.get(x); 52 | 53 | // Reduce noise 54 | val = mapNoise(val); 55 | 56 | // Visualize leds to the beat 57 | CRGB color = CRGB::Blue; 58 | color.nscale8_video(val); 59 | 60 | Serial.println(val); 61 | 62 | int startingLed = x * LEDS_STRIP; 63 | for (int i = startingLed; i < NUM_LEDS; i++) { 64 | int limit = val / 4; 65 | if (i - startingLed <= limit / 2 || (i - startingLed >= LEDS_STRIP - (limit / 2) && i - startingLed < LEDS_STRIP) ) { 66 | leds[i] = CHSV(hue, 255, 50); 67 | } else { 68 | leds[i] = CHSV(hue, 255, 0); 69 | } 70 | 71 | } 72 | hue++; 73 | } 74 | 75 | // Update Leds 76 | FastLED.show(); 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /new-patterns-1/new-patterns-1.ino: -------------------------------------------------------------------------------- 1 | #include "FastLED.h" 2 | 3 | #define NUM_LEDS 182 4 | #define DATA_PIN 3 5 | 6 | #define SEQUENCE_COUNT 2 7 | #define SEQUENCE_PROPS 4 8 | 9 | CRGB leds[NUM_LEDS]; 10 | 11 | int arr [NUM_LEDS][3]; // 3=h,s,v 12 | int patterns [2][2]; // start,end 13 | 14 | char sequence[SEQUENCE_COUNT][SEQUENCE_PROPS][20] = { 15 | {"17", "NULL", "NULL", "43"}, 16 | {"20", "NULL", "NULL", "0"} 17 | }; 18 | 19 | 20 | void setup() { 21 | FastLED.addLeds(leds, 60); 22 | Serial.begin(9600); 23 | patterns[0][0] = 0; 24 | patterns[0][1] = 13; 25 | patterns[1][0] = 14; 26 | patterns[1][1] = 26; 27 | 28 | 29 | static int count = 1; 30 | static int hue = 0; 31 | static int saturation = 255; 32 | static int brightness = 50; 33 | Serial.println(brightness); 34 | 35 | static int dindex = 0; 36 | 37 | 38 | // for (int i = 0; i < SEQUENCE_COUNT; i++) { 39 | // for (int j = 0; j < SEQUENCE_PROPS; j++) { 40 | // int count; 41 | // Serial.println(sequence[i][j]); 42 | // if (isdigit(sequence[i][j][0])) { 43 | // 44 | // int num = atoi(sequence[i][j]); 45 | // 46 | // Serial.print(j); 47 | // Serial.print(" - "); 48 | // Serial.print(num); 49 | //// if (j == 0) { 50 | //// count = atoi(sequence[i][j]); 51 | //// } else if (j == 1) { 52 | //// hue = atoi(sequence[i][j]); 53 | //// } else if (j == 2) { 54 | //// saturation = atoi(sequence[i][j]); 55 | //// } else if (j == 3) { 56 | //// brightness = atoi(sequence[i][j]); 57 | //// } 58 | // } 59 | // 60 | // int start = 0; 61 | // while (start < count) { 62 | // arr[dindex][0] = hue; 63 | // arr[dindex][1] = 255; 64 | // arr[dindex][2] = brightness; 65 | // start++; 66 | // dindex++; 67 | // } 68 | // 69 | // Serial.println(arr[dindex][0]); 70 | // } 71 | // } 72 | 73 | } 74 | 75 | void loop() { 76 | static uint8_t hue = 0; 77 | static uint8_t saturation = 255; 78 | static uint8_t brightness = 50; 79 | static uint8_t index = 0; 80 | static uint8_t len = 8; 81 | 82 | 83 | for (int i = 0; i < NUM_LEDS; i++){ 84 | if(i <= index && i > index - len) { 85 | arr[i][0] = hue; 86 | arr[i][1] = 255; 87 | arr[i][2] = brightness; 88 | if (index - i < 3) { 89 | arr[i][2] = brightness * (index - i) / 3; 90 | } else if (index - i > len - 3) { 91 | arr[i][2] = brightness * (abs(index - i - len)) / 3; 92 | } 93 | } else if (i == index - len) { 94 | arr[i][0] = hue; 95 | arr[i][1] = 255; 96 | arr[i][2] = 0; 97 | } 98 | } 99 | 100 | for (int i = 0; i < NUM_LEDS; i++){ 101 | leds[i] = CHSV(arr[i][0], arr[i][1], arr[i][2]); 102 | } 103 | 104 | 105 | hue += 7; 106 | index++; 107 | if (index - len > NUM_LEDS) { 108 | index = 0; 109 | } 110 | 111 | FastLED.show(); 112 | delay(100); 113 | } 114 | -------------------------------------------------------------------------------- /octo-led-rainbow-1/Rainbow/Rainbow.ino: -------------------------------------------------------------------------------- 1 | /* OctoWS2811 Rainbow.ino - Rainbow Shifting Test 2 | http://www.pjrc.com/teensy/td_libs_OctoWS2811.html 3 | Copyright (c) 2013 Paul Stoffregen, PJRC.COM, LLC 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | 23 | 24 | Required Connections 25 | -------------------- 26 | pin 2: LED Strip #1 OctoWS2811 drives 8 LED Strips. 27 | pin 14: LED strip #2 All 8 are the same length. 28 | pin 7: LED strip #3 29 | pin 8: LED strip #4 A 100 ohm resistor should used 30 | pin 6: LED strip #5 between each Teensy pin and the 31 | pin 20: LED strip #6 wire to the LED strip, to minimize 32 | pin 21: LED strip #7 high frequency ringining & noise. 33 | pin 5: LED strip #8 34 | pin 15 & 16 - Connect together, but do not use 35 | pin 4 - Do not use 36 | pin 3 - Do not use as PWM. Normal use is ok. 37 | pin 1 - Output indicating CPU usage, monitor with an oscilloscope, 38 | logic analyzer or even an LED (brighter = CPU busier) 39 | */ 40 | 41 | #include 42 | 43 | const int ledsPerStrip = 180; 44 | 45 | DMAMEM int displayMemory[ledsPerStrip*6]; 46 | int drawingMemory[ledsPerStrip*6]; 47 | 48 | const int config = WS2811_GRB | WS2811_800kHz; 49 | 50 | OctoWS2811 leds(ledsPerStrip, displayMemory, drawingMemory, config); 51 | 52 | int rainbowColors[180]; 53 | 54 | 55 | void setup() { 56 | pinMode(1, OUTPUT); 57 | digitalWrite(1, HIGH); 58 | for (int i=0; i<180; i++) { 59 | int hue = i * 2; 60 | int saturation = 100; 61 | int lightness = 10; 62 | // pre-compute the 180 rainbow colors 63 | rainbowColors[i] = makeColor(hue, saturation, lightness); 64 | } 65 | digitalWrite(1, LOW); 66 | leds.begin(); 67 | } 68 | 69 | 70 | void loop() { 71 | rainbow(10, 2500); 72 | } 73 | 74 | 75 | // phaseShift is the shift between each row. phaseShift=0 76 | // causes all rows to show the same colors moving together. 77 | // phaseShift=180 causes each row to be the opposite colors 78 | // as the previous. 79 | // 80 | // cycleTime is the number of milliseconds to shift through 81 | // the entire 360 degrees of the color wheel: 82 | // Red -> Orange -> Yellow -> Green -> Blue -> Violet -> Red 83 | // 84 | void rainbow(int phaseShift, int cycleTime) 85 | { 86 | int color, x, y, offset, wait; 87 | 88 | wait = cycleTime * 1000 / ledsPerStrip; 89 | for (color=0; color < 180; color++) { 90 | digitalWrite(1, HIGH); 91 | for (x=0; x < ledsPerStrip; x++) { 92 | for (y=0; y < 8; y++) { 93 | int index = (color + x + y*phaseShift/2) % 180; 94 | leds.setPixel(x + y*ledsPerStrip, rainbowColors[index]); 95 | } 96 | } 97 | leds.show(); 98 | digitalWrite(1, LOW); 99 | delayMicroseconds(wait); 100 | } 101 | } 102 | 103 | -------------------------------------------------------------------------------- /audio-stuff/audio-stuff.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int analogPin = A4; 6 | int val = 0; 7 | 8 | // 9 | //void setup() 10 | //{ 11 | //// note that you should not call pinMode for the analog pins 12 | //Serial.begin(9600); // initialise serial port for 9600 baud 13 | //} 14 | // 15 | //void loop() 16 | //{ 17 | // 18 | // val = analogRead(analogPin); // read the input pin 19 | // Serial.println(val,DEC); 20 | // delay(250); // delay 1/4 second between readings 21 | //} 22 | 23 | #include "FastLED.h" 24 | 25 | // How many leds in your strip? 26 | #define NUM_LEDS 26 27 | 28 | // For led chips like Neopixels, which have a data line, ground, and power, you just 29 | // need to define DATA_PIN. For led chipsets that are SPI based (four wires - data, clock, 30 | // ground, and power), like the LPD8806 define both DATA_PIN and CLOCK_PIN 31 | #define DATA_PIN 3 32 | #define CLOCK_PIN 13 33 | 34 | // Define the array of leds 35 | CRGB leds[NUM_LEDS]; 36 | 37 | void setup() { 38 | Serial.begin(9600); // initialise serial port for 9600 baud 39 | // Uncomment/edit one of the following lines for your leds arrangement. 40 | // FastLED.addLeds(leds, NUM_LEDS); 41 | // FastLED.addLeds(leds, NUM_LEDS); 42 | // FastLED.addLeds(leds, NUM_LEDS); 43 | FastLED.addLeds(leds, NUM_LEDS); 44 | } 45 | 46 | void loop() { 47 | static uint8_t hue = 0; 48 | val = analogRead(analogPin); // read the input pin 49 | Serial.println(val,DEC); 50 | FastLED.showColor(CHSV(hue++, 255, 50)); 51 | 52 | delay(10); 53 | 54 | // Turn the LED on, then pause 55 | // for (int i = 0; i < NUM_LEDS; i++) { 56 | // leds[i] = CRGB::Green; 57 | // } 58 | // FastLED.show(); 59 | // delay(500); 60 | // // Now turn the LED off, then pause 61 | // for (int i = 0; i < NUM_LEDS; i++) { 62 | // leds[i] = CRGB::Black; 63 | // } 64 | // FastLED.show(); 65 | // delay(500); 66 | 67 | } 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | /* 84 | fft_adc.pde 85 | guest openmusiclabs.com 8.18.12 86 | example sketch for testing the fft library. 87 | it takes in data on ADC0 (Analog0) and processes them 88 | with the fft. the data is sent out over the serial 89 | port at 115.2kb. there is a pure data patch for 90 | visualizing the data. 91 | */ 92 | 93 | //#define LOG_OUT 1 // use the log output function 94 | //#define FFT_N 256 // set to 256 point fft 95 | // 96 | //#include // include the library 97 | // 98 | //void setup() { 99 | // Serial.begin(115200); // use the serial port 100 | // TIMSK0 = 0; // turn off timer0 for lower jitter 101 | // ADCSRA = 0xe5; // set the adc to free running mode 102 | // ADMUX = 0x40; // use adc0 103 | // DIDR0 = 0x01; // turn off the digital input for adc0 104 | //} 105 | // 106 | //void loop() { 107 | // while(1) { // reduces jitter 108 | // cli(); // UDRE interrupt slows this way down on arduino1.0 109 | // for (int i = 0 ; i < 512 ; i += 2) { // save 256 samples 110 | // while(!(ADCSRA & 0x10)); // wait for adc to be ready 111 | // ADCSRA = 0xf5; // restart adc 112 | // byte m = ADCL; // fetch adc data 113 | // byte j = ADCH; 114 | // int k = (j << 8) | m; // form into an int 115 | // k -= 0x0200; // form into a signed int 116 | // k <<= 6; // form into a 16b signed int 117 | // fft_input[i] = k; // put real data into even bins 118 | // fft_input[i+1] = 0; // set odd bins to 0 119 | // } 120 | // fft_window(); // window the data for better frequency response 121 | // fft_reorder(); // reorder the data before doing the fft 122 | // fft_run(); // process the data in the fft 123 | // fft_mag_log(); // take the output of the fft 124 | // sei(); 125 | // Serial.write(255); // send a start byte 126 | // Serial.write(fft_log_out, 128); // send out the data 127 | // } 128 | //} 129 | 130 | -------------------------------------------------------------------------------- /led-test1/led-test1.ino/led-test1.ino.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #ifdef __AVR__ 3 | #include 4 | #endif 5 | 6 | #define PIN 2 7 | 8 | // Parameter 1 = number of pixels in strip 9 | // Parameter 2 = Arduino pin number (most are valid) 10 | // Parameter 3 = pixel type flags, add together as needed: 11 | // NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs) 12 | // NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers) 13 | // NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products) 14 | // NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2) 15 | // NEO_RGBW Pixels are wired for RGBW bitstream (NeoPixel RGBW products) 16 | Adafruit_NeoPixel strip = Adafruit_NeoPixel(80, PIN, NEO_GRB + NEO_KHZ800); 17 | 18 | // IMPORTANT: To reduce NeoPixel burnout risk, add 1000 uF capacitor across 19 | // pixel power leads, add 300 - 500 Ohm resistor on first pixel's data input 20 | // and minimize distance between Arduino and first pixel. Avoid connecting 21 | // on a live circuit...if you must, connect GND first. 22 | 23 | void setup() { 24 | // This is for Trinket 5V 16MHz, you can remove these three lines if you are not using a Trinket 25 | #if defined (__AVR_ATtiny85__) 26 | if (F_CPU == 16000000) clock_prescale_set(clock_div_1); 27 | #endif 28 | // End of trinket special code 29 | 30 | 31 | strip.begin(); 32 | strip.show(); // Initialize all pixels to 'off' 33 | } 34 | 35 | void loop() { 36 | // Some example procedures showing how to display to the pixels: 37 | colorWipe(strip.Color(255, 0, 0), 50); // Red 38 | colorWipe(strip.Color(0, 255, 0), 50); // Green 39 | colorWipe(strip.Color(0, 0, 55), 50); // Blue 40 | ////colorWipe(strip.Color(0, 0, 0, 255), 50); // White RGBW 41 | // // Send a theater pixel chase in... 42 | // theaterChase(strip.Color(127, 127, 127), 50); // White 43 | // theaterChase(strip.Color(127, 0, 0), 50); // Red 44 | // theaterChase(strip.Color(0, 0, 127), 50); // Blue 45 | 46 | rainbow(20); 47 | rainbowCycle(20); 48 | // theaterChaseRainbow(50); 49 | } 50 | 51 | // Fill the dots one after the other with a color 52 | void colorWipe(uint32_t c, uint8_t wait) { 53 | for(uint16_t i=0; i 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | 22 | // The display size and color to use 23 | const unsigned int matrix_width = 60; 24 | const unsigned int matrix_height = 24; 25 | const unsigned int myColor = 0x000700; // 1/16 Power Green 26 | 27 | // These parameters adjust the vertical thresholds 28 | const float maxLevel = 0.4; // 1.0 = max, lower is more "sensitive" Oraignal .5 then .3 29 | const float dynamicRange = 40.0; // total range to display, in decibels 30 | const float linearBlend = 0.3; // useful range is 0 to 0.7 31 | 32 | 33 | AudioControlSGTL5000 audioShield; 34 | 35 | // GUItool: begin automatically generated code 36 | AudioInputI2S i2s1; //xy=217,220 37 | AudioMixer4 mixer1; //xy=369,319 38 | AudioAnalyzeFFT1024 fft; //xy=509,319 fft1024_1 39 | AudioConnection patchCord1(i2s1, 0, mixer1, 0); 40 | AudioConnection patchCord2(i2s1, 1, mixer1, 1); 41 | AudioConnection patchCord3(mixer1, fft); 42 | AudioControlSGTL5000 sgtl5000_1; //xy=341,406 43 | 44 | 45 | // OctoWS2811 objects 46 | const int ledsPerPin = matrix_width * matrix_height / 8; 47 | DMAMEM int displayMemory[ledsPerPin * 6]; 48 | int drawingMemory[ledsPerPin * 6]; 49 | const int config = WS2811_GRB | WS2811_800kHz; 50 | OctoWS2811 leds(ledsPerPin, displayMemory, drawingMemory, config); 51 | 52 | // This array holds the volume level (0 to 1.0) for each 53 | // vertical pixel to turn on. Computed in setup() using 54 | // the 3 parameters above. 55 | float thresholdVertical[matrix_height]; 56 | 57 | // This array specifies how many of the FFT frequency bin 58 | // to use for each horizontal pixel. Because humans hear 59 | // in octaves and FFT bins are linear, the low frequencies 60 | // use a small number of bins, higher frequencies use more. 61 | int frequencyBinsHorizontal[matrix_width] = { 62 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 63 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 64 | 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 65 | 5, 5, 6, 6, 6, 7, 7, 7, 8, 8, 66 | 9, 9, 10, 10, 11, 12, 12, 13, 14, 15, 67 | 15, 16, 17, 18, 19, 20, 22, 23, 24, 25 68 | }; 69 | 70 | 71 | 72 | // Run setup once 73 | void setup() { 74 | // the audio library needs to be given memory to start working 75 | AudioMemory(12); 76 | 77 | // Enable the audio shield and set the output volume. 78 | audioShield.enable(); 79 | audioShield.inputSelect(AUDIO_INPUT_LINEIN); 80 | audioShield.lineInLevel(6); 81 | 82 | 83 | // compute the vertical thresholds before starting 84 | computeVerticalLevels(); 85 | 86 | //fft.windowFunction(AudioWindowTukey1024); 87 | //fft.windowFunction(AudioWindowBlackmanHarris1024); 88 | 89 | // turn on the display 90 | leds.begin(); 91 | leds.show(); 92 | } 93 | 94 | // A simple xy() function to turn display matrix coordinates 95 | // into the index numbers OctoWS2811 requires. If your LEDs 96 | // are arranged differently, edit this code... 97 | unsigned int xy(unsigned int x, unsigned int y) { 98 | if ((y & 1) == 0) { 99 | // even numbered rows (0, 2, 4...) are left to right 100 | return y * matrix_width + x; 101 | } else { 102 | // odd numbered rows (1, 3, 5...) are right to left 103 | return y * matrix_width + matrix_width - 1 - x; 104 | } 105 | } 106 | //unsigned int xy(unsigned int x, unsigned int y) { 107 | // return y * matrix_width + x; //All rows Left to Right 108 | //} 109 | 110 | // Run repetitively 111 | void loop() { 112 | unsigned int x, y, freqBin; 113 | float level; 114 | 115 | if (fft.available()) { 116 | // freqBin counts which FFT frequency data has been used, 117 | // starting at low frequency 118 | freqBin = 0; 119 | 120 | for (x = 0; x < matrix_width; x++) { 121 | // get the volume for each horizontal pixel position 122 | level = fft.read(freqBin, freqBin + frequencyBinsHorizontal[x] - 1); 123 | 124 | // uncomment to see the spectrum in Arduino's Serial Monitor 125 | // Serial.print(level); 126 | // Serial.print(" "); 127 | 128 | for (y = 0; y < matrix_height; y++) { 129 | // for each vertical pixel, check if above the threshold 130 | // and turn the LED on or off 131 | if (level >= thresholdVertical[y]) { 132 | leds.setPixel(xy(x, y), myColor); 133 | } else { 134 | leds.setPixel(xy(x, y), 0x000000); 135 | } 136 | } 137 | // increment the frequency bin count, so we display 138 | // low to higher frequency from left to right 139 | freqBin = freqBin + frequencyBinsHorizontal[x]; 140 | } 141 | // after all pixels set, show them all at the same instant 142 | leds.show(); 143 | // Serial.println(); 144 | } 145 | } 146 | 147 | 148 | // Run once from setup, the compute the vertical levels 149 | void computeVerticalLevels() { 150 | unsigned int y; 151 | float n, logLevel, linearLevel; 152 | 153 | for (y = 0; y < matrix_height; y++) { 154 | n = (float)y / (float)(matrix_height - 1); 155 | logLevel = pow10f(n * -1.0 * (dynamicRange / 20.0)); 156 | linearLevel = 1.0 - n; 157 | linearLevel = linearLevel * linearBlend; 158 | logLevel = logLevel * (1.0 - linearBlend); 159 | thresholdVertical[y] = (logLevel + linearLevel) * maxLevel; 160 | } 161 | } 162 | -------------------------------------------------------------------------------- /led-rainbow-test2/led-rainbow-test2.ino: -------------------------------------------------------------------------------- 1 | /* OctoWS2811 Rainbow.ino - Rainbow Shifting Test 2 | http://www.pjrc.com/teensy/td_libs_OctoWS2811.html 3 | Copyright (c) 2013 Paul Stoffregen, PJRC.COM, LLC 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | 23 | 24 | Required Connections 25 | -------------------- 26 | pin 2: LED Strip #1 OctoWS2811 drives 8 LED Strips. 27 | pin 14: LED strip #2 All 8 are the same length. 28 | pin 7: LED strip #3 29 | pin 8: LED strip #4 A 100 ohm resistor should used 30 | pin 6: LED strip #5 between each Teensy pin and the 31 | pin 20: LED strip #6 wire to the LED strip, to minimize 32 | pin 21: LED strip #7 high frequency ringining & noise. 33 | pin 5: LED strip #8 34 | pin 15 & 16 - Connect together, but do not use 35 | pin 4 - Do not use 36 | pin 3 - Do not use as PWM. Normal use is ok. 37 | pin 1 - Output indicating CPU usage, monitor with an oscilloscope, 38 | logic analyzer or even an LED (brighter = CPU busier) 39 | */ 40 | 41 | #include 42 | //#include 43 | 44 | const int ledsPerStrip = 180; // 180 45 | const int totalColors = 180; 46 | const int stripCount = 8; // 8 47 | const int totalLeds = 1440; 48 | const int hoopCount = 24; 49 | const int ledsPerHoop = 60; 50 | const int lightnessLimit = 5; 51 | 52 | DMAMEM int displayMemory[ledsPerStrip * stripCount]; 53 | int drawingMemory[ledsPerStrip * stripCount]; 54 | 55 | const int config = WS2811_GRB | WS2811_800kHz; 56 | 57 | OctoWS2811 leds(ledsPerStrip, displayMemory, drawingMemory, config); 58 | 59 | int rainbowColors[totalColors * (lightnessLimit + 1)]; // 1 is for 0 color. 60 | 61 | 62 | // SETUP 63 | void setup() { 64 | pinMode(1, OUTPUT); 65 | digitalWrite(1, HIGH); 66 | delay(2000); 67 | Serial.begin(9600); 68 | Serial.println("Setup"); 69 | int index = 0; 70 | for (int j = lightnessLimit; j >= 0; j--) { 71 | for (int i = 0; i < totalColors; i++) { 72 | int hue = i * 2; 73 | int saturation = 100; 74 | int lightness = j; 75 | index = (abs(lightnessLimit - j) * 180) + i; 76 | // pre-compute the 180 rainbow colors 77 | rainbowColors[index] = makeColor(hue, saturation, lightness); 78 | } 79 | } 80 | digitalWrite(1, LOW); 81 | leds.begin(); 82 | } 83 | 84 | // LOOP 85 | void loop() { 86 | Serial.println("Loop"); 87 | // sparklingInRandomly(5500); 88 | // rainbowRingsGoingOutFade(5500); 89 | // rainbow(5500000, 180); 90 | 91 | // rainbowRingsGoingOut(5500); 92 | // raibowSyncCircleAround(5500); 93 | 94 | // int i = random(3); 95 | // shuffle(i); 96 | 97 | // hRings(8, 12000); 98 | // vRings(8, 20000); 99 | sRandom(8, 20000); 100 | 101 | ///rainbowRingsGoingOutFade2(5500, 1); 102 | } 103 | 104 | void shuffle(int n) { 105 | switch(n) { 106 | case 0: 107 | rainbowRingsGoingOut(5500); 108 | break; 109 | case 1: 110 | raibowSyncCircleAround(5500); 111 | break; 112 | case 2: 113 | solidRainbow(180, 5500); 114 | break; 115 | default: 116 | rainbowRingsGoingOut(5500); 117 | } 118 | } 119 | //////////// 120 | 121 | 122 | // FUNCTIONS 123 | 124 | void hRings(int duration, int delay1) { 125 | int counter = 0; 126 | int color = 0; 127 | digitalWrite(1, HIGH); 128 | while (counter < (duration * 1000)) { 129 | for (int y = 0; y < ledsPerHoop; y++) { 130 | for (int x = 0; x < hoopCount; x++) { 131 | leds.setPixel((x * 60) + y, rainbowColors[color]); 132 | } 133 | color = (color + 5) % totalColors; 134 | if (color > 160) { 135 | color += 180 * 4; 136 | } 137 | leds.show(); 138 | delayMicroseconds(delay1); 139 | counter += (delay1 / 1000); // offset 140 | } 141 | } 142 | digitalWrite(1, LOW); 143 | } 144 | 145 | void vRings(int duration, int delay1) { 146 | int counter = 0; 147 | int color = 0; 148 | digitalWrite(1, HIGH); 149 | while (counter < (duration * 1000)) { 150 | for (int x = 0; x < totalLeds; x++) { 151 | leds.setPixel(x, rainbowColors[color]); 152 | if (x % ledsPerHoop == 0) { 153 | color = (color + 9) % totalColors; 154 | leds.show(); 155 | delayMicroseconds(delay1); 156 | counter += (delay1 / 1000); // offset 157 | } 158 | } 159 | } 160 | digitalWrite(1, LOW); 161 | } 162 | 163 | void sRandom(int duration, int delay1) { 164 | int counter = 0; 165 | int color = 0; 166 | digitalWrite(1, HIGH); 167 | while (counter < (duration * 1000)) { 168 | leds.setPixel(random(totalLeds), rainbowColors[color]); 169 | color = (color + 9) % totalColors; 170 | if (color % 5 == 0) { 171 | leds.show(); 172 | } 173 | // delayMicroseconds(delay1); 174 | counter += (delay1 / 1000); // offset 175 | } 176 | digitalWrite(1, LOW); 177 | } 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | //////// FRESH LINE 191 | 192 | int rainbowRingsGoingAroundColor = 0; 193 | void rainbowRingsGoingAround(int cycleTime) { // TOO SIMILAR... 194 | int color, x, y, z, wait; 195 | wait = cycleTime; // cycleTime * 1000 / ledsPerStrip; 196 | x = 0; 197 | y = 0; 198 | z = 0; 199 | digitalWrite(1, HIGH); 200 | 201 | int toggle = 0; 202 | while (x < 180 * 2) { 203 | for (y = 0; y < 60; y++) { 204 | z = (60 * x) + y; 205 | z %= 1440; 206 | leds.setPixel(z, rainbowColors[rainbowRingsGoingAroundColor]); 207 | } 208 | if (toggle == 0) { 209 | rainbowRingsGoingAroundColor++; 210 | } else { 211 | rainbowRingsGoingAroundColor--; 212 | } 213 | if (rainbowRingsGoingAroundColor >= 180) { 214 | toggle = 1; 215 | } 216 | leds.show(); 217 | delayMicroseconds(10000); // 10000 218 | x++; 219 | } 220 | 221 | digitalWrite(1, LOW); 222 | } 223 | 224 | 225 | 226 | int rainbowRingsGoingOutFadeColor = 0; 227 | void rainbowRingsGoingOutFade(int cycleTime) { // GOOD 228 | int color, x, y, z, wait; 229 | wait = cycleTime; // cycleTime * 1000 / ledsPerStrip; 230 | x = 0; 231 | y = 0; 232 | digitalWrite(1, HIGH); 233 | 234 | for (y = 0; y < ledsPerHoop; y++) { 235 | for (x = 0; x < hoopCount; x++) { 236 | z = (x * ledsPerHoop) + y; 237 | // rainbowRingsGoingOutFadeColor = y; 238 | // if (y < 2) { 239 | // rainbowRingsGoingOutFadeColor -= 180 * 2; 240 | // } else if (y > 56) { 241 | // rainbowRingsGoingOutFadeColor += 180; 242 | // } 243 | rainbowRingsGoingOutFadeColor += 17; 244 | rainbowRingsGoingOutFadeColor %= 180; 245 | // Serial.println("color: %d", rainbowRingsGoingOutFadeColor); 246 | Serial.println(rainbowRingsGoingOutFadeColor); 247 | leds.setPixel(z, rainbowColors[rainbowRingsGoingOutFadeColor]); 248 | } 249 | leds.show(); 250 | delayMicroseconds(cycleTime * 10); 251 | } 252 | 253 | digitalWrite(1, LOW); 254 | } 255 | 256 | 257 | int rainbowRingsGoingOutDarkerColor = 0; 258 | void rainbowRingsGoingOutDarker(int cycleTime) { // GOOD 259 | int color, x, y, z, wait; 260 | wait = cycleTime * 1000 / ledsPerStrip; 261 | x = 0; 262 | y = 0; 263 | digitalWrite(1, HIGH); 264 | 265 | while (x < totalLeds) { 266 | leds.setPixel(y, rainbowColors[rainbowRingsGoingOutDarkerColor]); 267 | x++; 268 | y += 60; 269 | if (x % 24 == 0) { 270 | leds.show(); 271 | delayMicroseconds(cycleTime * 5); 272 | y++; 273 | rainbowRingsGoingOutDarkerColor += 7; // z++; 274 | } 275 | y %= totalLeds; 276 | rainbowRingsGoingOutDarkerColor %= 1080; // 180 277 | } 278 | digitalWrite(1, LOW); 279 | } 280 | 281 | 282 | void raibowSyncCircleAround(int cycleTime) { // GOOD 283 | int color, x, y, z, wait; 284 | wait = cycleTime * 1000 / ledsPerStrip; 285 | x = 0; 286 | y = 0; 287 | z = 0; 288 | digitalWrite(1, HIGH); 289 | 290 | while (x < totalLeds) { 291 | leds.setPixel(x, rainbowColors[y]); 292 | x++; 293 | if (x % 60 == 0) { 294 | y += 2; //6 295 | leds.show(); 296 | delayMicroseconds(cycleTime * 10); 297 | } 298 | // x %= totalLeds; 299 | y %= 180; 300 | } 301 | digitalWrite(1, LOW); 302 | } 303 | 304 | 305 | void raibowRingLineAround(int cycleTime) { 306 | int color, x, y, z, wait; 307 | wait = cycleTime * 1000 / ledsPerStrip; 308 | x = 0; 309 | y = 0; 310 | z = 0; 311 | digitalWrite(1, HIGH); 312 | 313 | while (x < 14400) { 314 | leds.setPixel(x, rainbowColors[y]); 315 | leds.show(); 316 | x++; 317 | if (x % 120 == 0) { 318 | y += 12; 319 | } 320 | x %= totalLeds; 321 | y %= 180; 322 | } 323 | digitalWrite(1, LOW); 324 | } 325 | 326 | 327 | int rainbowRingsGoingOutColor = 0; 328 | void rainbowRingsGoingOut(int cycleTime) { // GOOD 329 | int color, x, y, z, wait; 330 | wait = cycleTime * 1000 / ledsPerStrip; 331 | x = 0; 332 | y = 0; 333 | digitalWrite(1, HIGH); 334 | 335 | while (x < totalLeds) { 336 | leds.setPixel(y, rainbowColors[rainbowRingsGoingOutColor]); 337 | x++; 338 | y += 60; 339 | if (x % 24 == 0) { 340 | leds.show(); 341 | delayMicroseconds(cycleTime * 5); 342 | y++; 343 | rainbowRingsGoingOutColor += 7; // z++; 344 | } 345 | y %= totalLeds; 346 | rainbowRingsGoingOutColor %= 180; 347 | } 348 | digitalWrite(1, LOW); 349 | } 350 | 351 | 352 | void solidColorRingsGoingOut(int cycleTime) { 353 | int color, x, y, z, wait; 354 | wait = cycleTime * 1000 / ledsPerStrip; 355 | x = 0; 356 | y = 0; 357 | z = 0; 358 | digitalWrite(1, HIGH); 359 | while (z < 180) { 360 | z %= 180; 361 | x = 0; 362 | while (x < totalLeds) { 363 | y += 60; 364 | y %= totalLeds; 365 | if (x % 24 == 0) { 366 | y++; 367 | } 368 | leds.setPixel(y, rainbowColors[z]); 369 | leds.show(); 370 | x++; 371 | } 372 | z += 45; 373 | } 374 | digitalWrite(1, LOW); 375 | } 376 | 377 | 378 | void sparklingInRandomly(int cycleTime) { 379 | int color, x, y, wait; 380 | wait = cycleTime * 1000 / ledsPerStrip; 381 | x = 0; 382 | y = 0; 383 | digitalWrite(1, HIGH); 384 | while (x < 1440) { 385 | // y = y + (x * 60); 386 | // if (y > 1440) { 387 | // y++; 388 | // y %= 1440; 389 | // } 390 | y = random(1440); 391 | leds.setPixel(y, rainbowColors[random(180)]); 392 | leds.show(); 393 | x++; 394 | } 395 | digitalWrite(1, LOW); 396 | } 397 | 398 | 399 | //int currentColor = 0; 400 | //void raibowLine(int cycleTime) { 401 | // int color, x, y, wait; 402 | // wait = cycleTime * 1000 / ledsPerStrip; 403 | // x = 0; 404 | // y = 0; 405 | // digitalWrite(1, HIGH); 406 | // while (x <= 1440) { 407 | // x++; 408 | // if (x % 60 == 0) { 409 | // currentColor = random(180); 410 | // } 411 | // leds.setPixel(x, rainbowColors[currentColor]); 412 | // leds.show(); 413 | // } 414 | //// currentColor += 30 % 180; 415 | // digitalWrite(1, LOW); 416 | //} 417 | 418 | 419 | // First one. lol 420 | void solidRainbow(int phaseShift, int cycleTime) { 421 | int color, x, y, wait; 422 | wait = cycleTime * 1000 / ledsPerStrip; 423 | for (color = 0; color < 180; color++) { 424 | digitalWrite(1, HIGH); 425 | for (x = 0; x < ledsPerStrip; x++) { 426 | for (y = 0; y < stripCount; y++) { 427 | int index = color; // (color + x + y*phaseShift/2) % 180; 428 | leds.setPixel(x + y * ledsPerStrip, rainbowColors[index]); 429 | } 430 | } 431 | leds.show(); 432 | digitalWrite(1, LOW); 433 | delayMicroseconds(wait * 2); 434 | } 435 | } 436 | 437 | 438 | // phaseShift is the shift between each row. phaseShift=0 439 | // causes all rows to show the same colors moving together. 440 | // phaseShift=180 causes each row to be the opposite colors 441 | // as the previous. 442 | // 443 | // cycleTime is the number of milliseconds to shift through 444 | // the entire 360 degrees of the color wheel: 445 | // Red -> Orange -> Yellow -> Green -> Blue -> Violet -> Red 446 | // 447 | void rainbow(int phaseShift, int cycleTime) { 448 | int color, x, y, wait; 449 | 450 | wait = cycleTime * 1000 / ledsPerStrip; 451 | for (color = 0; color < 180; color++) { 452 | digitalWrite(1, HIGH); 453 | for (x = 0; x < ledsPerStrip; x++) { 454 | for (y = 0; y < stripCount; y++) { 455 | int index = (color + x + y * phaseShift / 2) % 180; 456 | leds.setPixel(x + y * ledsPerStrip, rainbowColors[index]); 457 | } 458 | } 459 | leds.show(); 460 | digitalWrite(1, LOW); 461 | delayMicroseconds(wait); 462 | } 463 | } 464 | 465 | 466 | -------------------------------------------------------------------------------- /led-patterns-1/led-patterns-1.ino: -------------------------------------------------------------------------------- 1 | /* OctoWS2811 Rainbow.ino - Rainbow Shifting Test 2 | http://www.pjrc.com/teensy/td_libs_OctoWS2811.html 3 | Copyright (c) 2013 Paul Stoffregen, PJRC.COM, LLC 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | 23 | 24 | Required Connections 25 | -------------------- 26 | pin 2: LED Strip #1 OctoWS2811 drives 8 LED Strips. 27 | pin 14: LED strip #2 All 8 are the same length. 28 | pin 7: LED strip #3 29 | pin 8: LED strip #4 A 100 ohm resistor should used 30 | pin 6: LED strip #5 between each Teensy pin and the 31 | pin 20: LED strip #6 wire to the LED strip, to minimize 32 | pin 21: LED strip #7 high frequency ringining & noise. 33 | pin 5: LED strip #8 34 | pin 15 & 16 - Connect together, but do not use 35 | pin 4 - Do not use 36 | pin 3 - Do not use as PWM. Normal use is ok. 37 | pin 1 - Output indicating CPU usage, monitor with an oscilloscope, 38 | logic analyzer or even an LED (brighter = CPU busier) 39 | */ 40 | 41 | #include 42 | //#include 43 | 44 | const int ledsPerStrip = 180; // 180 45 | const int totalColors = 180; 46 | const int stripCount = 8; // 8 47 | const int totalLeds = 1440; 48 | const int hoopCount = 24; 49 | const int ledsPerHoop = 60; 50 | const int lightnessLimit = 5; 51 | 52 | int lastPattern = 0; 53 | 54 | DMAMEM int displayMemory[ledsPerStrip * stripCount]; 55 | int drawingMemory[ledsPerStrip * stripCount]; 56 | 57 | const int config = WS2811_GRB | WS2811_800kHz; 58 | 59 | OctoWS2811 leds(ledsPerStrip, displayMemory, drawingMemory, config); 60 | 61 | int rainbowColors[totalColors * (lightnessLimit + 1)]; // 1 is for 0 color. 62 | 63 | 64 | // SETUP 65 | void setup() { 66 | pinMode(1, OUTPUT); 67 | digitalWrite(1, HIGH); 68 | delay(2000); 69 | Serial.begin(9600); 70 | Serial.println("Setup"); 71 | int index = 0; 72 | for (int j = lightnessLimit; j >= 0; j--) { 73 | for (int i = 0; i < totalColors; i++) { 74 | int hue = i * 2; 75 | int saturation = 100; 76 | int lightness = j; 77 | index = (abs(lightnessLimit - j) * 180) + i; 78 | // pre-compute the 180 rainbow colors 79 | rainbowColors[index] = makeColor(hue, saturation, lightness); 80 | } 81 | } 82 | digitalWrite(1, LOW); 83 | leds.begin(); 84 | } 85 | 86 | // LOOP 87 | void loop() { 88 | Serial.println("Loop"); 89 | // sparklingInRandomly(5500); 90 | // rainbowRingsGoingOutFade(5500); 91 | // rainbow(5500000, 180); 92 | 93 | // rainbowRingsGoingOut(5500); 94 | // raibowSyncCircleAround(5500); 95 | 96 | 97 | verticalRings(8, 30000); 98 | 99 | // Make sure it's different each time. 100 | int patternCount = 5; 101 | int i = random(patternCount); 102 | while (i == lastPattern) { 103 | i = random(patternCount); 104 | } 105 | shuffle(i); 106 | lastPattern = i; 107 | 108 | // doubleRainbowCircle(8, 90000); 109 | // horizontalRingsWithGaps(8, 30000); 110 | 111 | // hRings(8,20000); // 50000 112 | // vRings(8, 60000); 113 | // sRandom(8, 20000); 114 | 115 | ///rainbowRingsGoingOutFade2(5500, 1); 116 | } 117 | 118 | void shuffle(int n) { 119 | switch(n) { 120 | case 0: 121 | horizontalRings(8,20000); // 50000 122 | break; 123 | case 1: 124 | verticalRings(8, 60000); 125 | break; 126 | case 2: 127 | sparkleRandom(8, 20000); 128 | break; 129 | case 3: 130 | allRainbow(8, 30000); 131 | break; 132 | case 4: 133 | horizontalRingsWithGaps(8, 30000); 134 | break; 135 | case 5: 136 | doubleRainbowCircle(8, 30000); 137 | break; 138 | default: 139 | horizontalRings(8, 20000); // 50000 140 | } 141 | } 142 | //////////// 143 | 144 | 145 | // FUNCTIONS 146 | 147 | void horizontalRings(int duration, int delay1) { 148 | int counter = 0; 149 | int color = 0; 150 | digitalWrite(1, HIGH); 151 | while (counter < (duration * 1000)) { 152 | for (int y = 0; y < ledsPerHoop; y++) { 153 | for (int x = 0; x < hoopCount; x++) { 154 | leds.setPixel((x * 60) + y, rainbowColors[color]); 155 | } 156 | color = (color + 5) % totalColors; 157 | if (color > 160) { 158 | color += 180 * 4; 159 | } 160 | leds.show(); 161 | delayMicroseconds(delay1); 162 | counter += (delay1 / 1000); // offset 163 | } 164 | } 165 | digitalWrite(1, LOW); 166 | } 167 | 168 | 169 | 170 | void horizontalRingsWithGaps(int duration, int delay1) { // overflows 171 | int counter = 0; 172 | int color = 0; 173 | digitalWrite(1, HIGH); 174 | while (counter < (duration * 1000)) { 175 | int gapStart = random(5, 55); 176 | int gapEnd = random(5, 55); 177 | for (int y = 0; y < ledsPerHoop; y++) { 178 | for (int x = 0; x < hoopCount; x++) { 179 | leds.setPixel((x * 60) + y, rainbowColors[color]); 180 | } 181 | if (y < (gapStart + 4) && y >= gapStart) { 182 | color += 180; 183 | } 184 | if (y > (gapEnd - 4) && y <= gapEnd) { // (y == gapEnd) { 185 | color -= 180; 186 | } 187 | leds.show(); 188 | delayMicroseconds(delay1); 189 | counter += (delay1 / 1000); // offset 190 | } 191 | color = (color + random(40)) % totalColors; 192 | } 193 | digitalWrite(1, LOW); 194 | } 195 | 196 | void verticalRings(int duration, int delay1) { // stops in between.. 197 | int counter = 0; 198 | int color = 0; 199 | digitalWrite(1, HIGH); 200 | while (counter < (duration * 1000)) { 201 | for (int x = 0; x < totalLeds; x++) { 202 | leds.setPixel(x, rainbowColors[color]); 203 | if (x % ledsPerHoop == 0) { 204 | color = (color + 9) % totalColors; 205 | leds.show(); 206 | delayMicroseconds(delay1); 207 | counter += (delay1 / 1000); // offset 208 | } 209 | } 210 | } 211 | digitalWrite(1, LOW); 212 | } 213 | 214 | 215 | void sparkleRandom(int duration, int delay1) { 216 | int counter = 0; 217 | int color = 0; 218 | digitalWrite(1, HIGH); 219 | while (counter < (duration * 1000)) { 220 | leds.setPixel(random(totalLeds), rainbowColors[color]); 221 | color = (color + 9) % totalColors; 222 | if (color % 5 == 0) { 223 | leds.show(); 224 | } 225 | // delayMicroseconds(delay1); 226 | counter += (delay1 / (1000 * 15)); // offset 227 | } 228 | digitalWrite(1, LOW); 229 | } 230 | 231 | 232 | void allRainbow(int duration, int delay1) { 233 | int counter = 0; 234 | int color = 0; 235 | digitalWrite(1, HIGH); 236 | while (counter < (duration * 1000)) { 237 | for (int x = 0; x < totalLeds; x++) { 238 | leds.setPixel(x, rainbowColors[color]); 239 | if (x % totalLeds == 0) { 240 | color = (color + 1) % totalColors; 241 | leds.show(); 242 | delayMicroseconds(delay1); 243 | counter += (delay1 / (1000 * 15)); // offset 244 | } 245 | } 246 | } 247 | digitalWrite(1, LOW); 248 | } 249 | 250 | 251 | 252 | void doubleRainbowCircle(int duration, int delay1) { 253 | int counter = 0; 254 | int color = 0; 255 | int index = 0; 256 | digitalWrite(1, HIGH); 257 | while (counter < (duration * 1000)) { 258 | index += ledsPerHoop; 259 | int stripe1 = random(20); 260 | int stripe2 = random(20, 40); 261 | int stripe3 = random(40, 60); 262 | for (int x = 0; x < totalLeds; x++) { 263 | index++; 264 | index %= totalLeds; 265 | leds.setPixel(index, rainbowColors[color]); 266 | if (x % ledsPerHoop == 0) { 267 | color = (color + 15) % totalColors; 268 | } 269 | if (x % totalLeds == 0) { 270 | leds.show(); 271 | delayMicroseconds(delay1); 272 | counter += (delay1 / (1000 * 25)); // offset 273 | } 274 | } 275 | } 276 | digitalWrite(1, LOW); 277 | } 278 | 279 | 280 | 281 | 282 | 283 | //////// FRESH LINE 284 | // 285 | //int rainbowRingsGoingAroundColor = 0; 286 | //void rainbowRingsGoingAround(int cycleTime) { // TOO SIMILAR... 287 | // int color, x, y, z, wait; 288 | // wait = cycleTime; // cycleTime * 1000 / ledsPerStrip; 289 | // x = 0; 290 | // y = 0; 291 | // z = 0; 292 | // digitalWrite(1, HIGH); 293 | // 294 | // int toggle = 0; 295 | // while (x < 180 * 2) { 296 | // for (y = 0; y < 60; y++) { 297 | // z = (60 * x) + y; 298 | // z %= 1440; 299 | // leds.setPixel(z, rainbowColors[rainbowRingsGoingAroundColor]); 300 | // } 301 | // if (toggle == 0) { 302 | // rainbowRingsGoingAroundColor++; 303 | // } else { 304 | // rainbowRingsGoingAroundColor--; 305 | // } 306 | // if (rainbowRingsGoingAroundColor >= 180) { 307 | // toggle = 1; 308 | // } 309 | // leds.show(); 310 | // delayMicroseconds(10000); // 10000 311 | // x++; 312 | // } 313 | // 314 | // digitalWrite(1, LOW); 315 | //} 316 | // 317 | // 318 | // 319 | //int rainbowRingsGoingOutFadeColor = 0; 320 | //void rainbowRingsGoingOutFade(int cycleTime) { // GOOD 321 | // int color, x, y, z, wait; 322 | // wait = cycleTime; // cycleTime * 1000 / ledsPerStrip; 323 | // x = 0; 324 | // y = 0; 325 | // digitalWrite(1, HIGH); 326 | // 327 | // for (y = 0; y < ledsPerHoop; y++) { 328 | // for (x = 0; x < hoopCount; x++) { 329 | // z = (x * ledsPerHoop) + y; 330 | // // rainbowRingsGoingOutFadeColor = y; 331 | // // if (y < 2) { 332 | // // rainbowRingsGoingOutFadeColor -= 180 * 2; 333 | // // } else if (y > 56) { 334 | // // rainbowRingsGoingOutFadeColor += 180; 335 | // // } 336 | // rainbowRingsGoingOutFadeColor += 17; 337 | // rainbowRingsGoingOutFadeColor %= 180; 338 | // // Serial.println("color: %d", rainbowRingsGoingOutFadeColor); 339 | // Serial.println(rainbowRingsGoingOutFadeColor); 340 | // leds.setPixel(z, rainbowColors[rainbowRingsGoingOutFadeColor]); 341 | // } 342 | // leds.show(); 343 | // delayMicroseconds(cycleTime * 10); 344 | // } 345 | // 346 | // digitalWrite(1, LOW); 347 | //} 348 | // 349 | // 350 | //int rainbowRingsGoingOutDarkerColor = 0; 351 | //void rainbowRingsGoingOutDarker(int cycleTime) { // GOOD 352 | // int color, x, y, z, wait; 353 | // wait = cycleTime * 1000 / ledsPerStrip; 354 | // x = 0; 355 | // y = 0; 356 | // digitalWrite(1, HIGH); 357 | // 358 | // while (x < totalLeds) { 359 | // leds.setPixel(y, rainbowColors[rainbowRingsGoingOutDarkerColor]); 360 | // x++; 361 | // y += 60; 362 | // if (x % 24 == 0) { 363 | // leds.show(); 364 | // delayMicroseconds(cycleTime * 5); 365 | // y++; 366 | // rainbowRingsGoingOutDarkerColor += 7; // z++; 367 | // } 368 | // y %= totalLeds; 369 | // rainbowRingsGoingOutDarkerColor %= 1080; // 180 370 | // } 371 | // digitalWrite(1, LOW); 372 | //} 373 | // 374 | // 375 | //void raibowSyncCircleAround(int cycleTime) { // GOOD 376 | // int color, x, y, z, wait; 377 | // wait = cycleTime * 1000 / ledsPerStrip; 378 | // x = 0; 379 | // y = 0; 380 | // z = 0; 381 | // digitalWrite(1, HIGH); 382 | // 383 | // while (x < totalLeds) { 384 | // leds.setPixel(x, rainbowColors[y]); 385 | // x++; 386 | // if (x % 60 == 0) { 387 | // y += 2; //6 388 | // leds.show(); 389 | // delayMicroseconds(cycleTime * 10); 390 | // } 391 | //// x %= totalLeds; 392 | // y %= 180; 393 | // } 394 | // digitalWrite(1, LOW); 395 | //} 396 | // 397 | // 398 | //void raibowRingLineAround(int cycleTime) { 399 | // int color, x, y, z, wait; 400 | // wait = cycleTime * 1000 / ledsPerStrip; 401 | // x = 0; 402 | // y = 0; 403 | // z = 0; 404 | // digitalWrite(1, HIGH); 405 | // 406 | // while (x < 14400) { 407 | // leds.setPixel(x, rainbowColors[y]); 408 | // leds.show(); 409 | // x++; 410 | // if (x % 120 == 0) { 411 | // y += 12; 412 | // } 413 | // x %= totalLeds; 414 | // y %= 180; 415 | // } 416 | // digitalWrite(1, LOW); 417 | //} 418 | // 419 | // 420 | //int rainbowRingsGoingOutColor = 0; 421 | //void rainbowRingsGoingOut(int cycleTime) { // GOOD 422 | // int color, x, y, z, wait; 423 | // wait = cycleTime * 1000 / ledsPerStrip; 424 | // x = 0; 425 | // y = 0; 426 | // digitalWrite(1, HIGH); 427 | // 428 | // while (x < totalLeds) { 429 | // leds.setPixel(y, rainbowColors[rainbowRingsGoingOutColor]); 430 | // x++; 431 | // y += 60; 432 | // if (x % 24 == 0) { 433 | // leds.show(); 434 | // delayMicroseconds(cycleTime * 5); 435 | // y++; 436 | // rainbowRingsGoingOutColor += 7; // z++; 437 | // } 438 | // y %= totalLeds; 439 | // rainbowRingsGoingOutColor %= 180; 440 | // } 441 | // digitalWrite(1, LOW); 442 | //} 443 | // 444 | // 445 | //void solidColorRingsGoingOut(int cycleTime) { 446 | // int color, x, y, z, wait; 447 | // wait = cycleTime * 1000 / ledsPerStrip; 448 | // x = 0; 449 | // y = 0; 450 | // z = 0; 451 | // digitalWrite(1, HIGH); 452 | // while (z < 180) { 453 | // z %= 180; 454 | // x = 0; 455 | // while (x < totalLeds) { 456 | // y += 60; 457 | // y %= totalLeds; 458 | // if (x % 24 == 0) { 459 | // y++; 460 | // } 461 | // leds.setPixel(y, rainbowColors[z]); 462 | // leds.show(); 463 | // x++; 464 | // } 465 | // z += 45; 466 | // } 467 | // digitalWrite(1, LOW); 468 | //} 469 | // 470 | // 471 | //void sparklingInRandomly(int cycleTime) { 472 | // int color, x, y, wait; 473 | // wait = cycleTime * 1000 / ledsPerStrip; 474 | // x = 0; 475 | // y = 0; 476 | // digitalWrite(1, HIGH); 477 | // while (x < 1440) { 478 | // // y = y + (x * 60); 479 | // // if (y > 1440) { 480 | // // y++; 481 | // // y %= 1440; 482 | // // } 483 | // y = random(1440); 484 | // leds.setPixel(y, rainbowColors[random(180)]); 485 | // leds.show(); 486 | // x++; 487 | // } 488 | // digitalWrite(1, LOW); 489 | //} 490 | // 491 | // 492 | ////int currentColor = 0; 493 | ////void raibowLine(int cycleTime) { 494 | //// int color, x, y, wait; 495 | //// wait = cycleTime * 1000 / ledsPerStrip; 496 | //// x = 0; 497 | //// y = 0; 498 | //// digitalWrite(1, HIGH); 499 | //// while (x <= 1440) { 500 | //// x++; 501 | //// if (x % 60 == 0) { 502 | //// currentColor = random(180); 503 | //// } 504 | //// leds.setPixel(x, rainbowColors[currentColor]); 505 | //// leds.show(); 506 | //// } 507 | ////// currentColor += 30 % 180; 508 | //// digitalWrite(1, LOW); 509 | ////} 510 | // 511 | // 512 | //// First one. lol 513 | //void solidRainbow(int phaseShift, int cycleTime) { 514 | // int color, x, y, wait; 515 | // wait = cycleTime * 1000 / ledsPerStrip; 516 | // for (color = 0; color < 180; color++) { 517 | // digitalWrite(1, HIGH); 518 | // for (x = 0; x < ledsPerStrip; x++) { 519 | // for (y = 0; y < stripCount; y++) { 520 | // int index = color; // (color + x + y*phaseShift/2) % 180; 521 | // leds.setPixel(x + y * ledsPerStrip, rainbowColors[index]); 522 | // } 523 | // } 524 | // leds.show(); 525 | // digitalWrite(1, LOW); 526 | // delayMicroseconds(wait * 2); 527 | // } 528 | //} 529 | // 530 | 531 | // phaseShift is the shift between each row. phaseShift=0 532 | // causes all rows to show the same colors moving together. 533 | // phaseShift=180 causes each row to be the opposite colors 534 | // as the previous. 535 | // 536 | // cycleTime is the number of milliseconds to shift through 537 | // the entire 360 degrees of the color wheel: 538 | // Red -> Orange -> Yellow -> Green -> Blue -> Violet -> Red 539 | // 540 | void rainbow(int phaseShift, int cycleTime) { 541 | int color, x, y, wait; 542 | 543 | wait = cycleTime * 1000 / ledsPerStrip; 544 | for (color = 0; color < 180; color++) { 545 | digitalWrite(1, HIGH); 546 | for (x = 0; x < ledsPerStrip; x++) { 547 | for (y = 0; y < stripCount; y++) { 548 | int index = (color + x + y * phaseShift / 2) % 180; 549 | leds.setPixel(x + y * ledsPerStrip, rainbowColors[index]); 550 | } 551 | } 552 | leds.show(); 553 | digitalWrite(1, LOW); 554 | delayMicroseconds(wait); 555 | } 556 | } 557 | 558 | 559 | -------------------------------------------------------------------------------- /mini-glonut-patterns/mini-glonut-patterns.ino: -------------------------------------------------------------------------------- 1 | /* OctoWS2811 Rainbow.ino - Rainbow Shifting Test 2 | http://www.pjrc.com/teensy/td_libs_OctoWS2811.html 3 | Copyright (c) 2013 Paul Stoffregen, PJRC.COM, LLC 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | 23 | 24 | Required Connections 25 | -------------------- 26 | pin 2: LED Strip #1 OctoWS2811 drives 8 LED Strips. 27 | pin 14: LED strip #2 All 8 are the same length. 28 | pin 7: LED strip #3 29 | pin 8: LED strip #4 A 100 ohm resistor should used 30 | pin 6: LED strip #5 between each Teensy pin and the 31 | pin 20: LED strip #6 wire to the LED strip, to minimize 32 | pin 21: LED strip #7 high frequency ringining & noise. 33 | pin 5: LED strip #8 34 | pin 15 & 16 - Connect together, but do not use 35 | pin 4 - Do not use 36 | pin 3 - Do not use as PWM. Normal use is ok. 37 | pin 1 - Output indicating CPU usage, monitor with an oscilloscope, 38 | logic analyzer or even an LED (brighter = CPU busier) 39 | */ 40 | 41 | #include 42 | //#include 43 | 44 | const int ledsPerStrip = 180; // 180 45 | const int totalColors = 180; 46 | const int stripCount = 8; // 8 47 | const int hoopCount = 12; 48 | const int ledsPerHoop = 75; 49 | const int totalLeds = hoopCount * ledsPerHoop; 50 | const int lightnessLimit = 5; 51 | 52 | int lastPattern = 0; 53 | 54 | DMAMEM int displayMemory[ledsPerStrip * stripCount]; 55 | int drawingMemory[ledsPerStrip * stripCount]; 56 | 57 | const int config = WS2811_GRB | WS2811_800kHz; 58 | 59 | OctoWS2811 leds(ledsPerStrip, displayMemory, drawingMemory, config); 60 | 61 | int rainbowColors[totalColors * (lightnessLimit + 1)]; // 1 is for 0 color. 62 | 63 | 64 | // SETUP 65 | void setup() { 66 | pinMode(1, OUTPUT); 67 | digitalWrite(1, HIGH); 68 | delay(2000); 69 | Serial.begin(9600); 70 | Serial.println("Setup"); 71 | int index = 0; 72 | for (int j = lightnessLimit; j >= 0; j--) { 73 | for (int i = 0; i < totalColors; i++) { 74 | int hue = i * 2; 75 | int saturation = 100; 76 | int lightness = j; 77 | index = (abs(lightnessLimit - j) * 180) + i; 78 | // pre-compute the 180 rainbow colors 79 | rainbowColors[index] = makeColor(hue, saturation, lightness); 80 | } 81 | } 82 | digitalWrite(1, LOW); 83 | leds.begin(); 84 | } 85 | 86 | // LOOP 87 | void loop() { 88 | Serial.println("Loop"); 89 | // sparklingInRandomly(5500); 90 | // rainbowRingsGoingOutFade(5500); 91 | // rainbow(5500000, 180); 92 | 93 | // rainbowRingsGoingOut(5500); 94 | // raibowSyncCircleAround(5500); 95 | 96 | 97 | 98 | 99 | // Make sure it's different each time. 100 | int patternCount = 5; 101 | int i = random(patternCount); 102 | while (i == lastPattern) { 103 | i = random(patternCount); 104 | } 105 | shuffle(i); 106 | lastPattern = i; 107 | 108 | 109 | 110 | // horizontalRings(8, 20000); 111 | 112 | 113 | 114 | // doubleRainbowCircle(8, 90000); 115 | // horizontalRingsWithGaps(8, 30000); 116 | 117 | // hRings(8,20000); // 50000 118 | // vRings(8, 60000); 119 | // sRandom(8, 20000); 120 | 121 | ///rainbowRingsGoingOutFade2(5500, 1); 122 | } 123 | 124 | void shuffle(int n) { 125 | switch(n) { 126 | case 0: 127 | horizontalRings(8,20000); // 50000 128 | break; 129 | case 1: 130 | verticalRings(8, 60000); 131 | break; 132 | case 2: 133 | sparkleRandom(8, 20000); 134 | break; 135 | case 3: 136 | allRainbow(8, 30000); 137 | break; 138 | case 4: 139 | horizontalRingsWithGaps(8, 30000); 140 | break; 141 | case 5: 142 | doubleRainbowCircle(8, 30000); 143 | break; 144 | default: 145 | horizontalRings(8, 20000); // 50000 146 | } 147 | } 148 | //////////// 149 | 150 | 151 | // FUNCTIONS 152 | 153 | void horizontalRings(int duration, int delay1) { 154 | int counter = 0; 155 | int color = 0; 156 | digitalWrite(1, HIGH); 157 | while (counter < (duration * 1000)) { 158 | for (int y = 0; y < ledsPerHoop; y++) { 159 | for (int x = 0; x < hoopCount; x++) { 160 | leds.setPixel((x * 60) + y, rainbowColors[color]); 161 | } 162 | color = (color + 5) % totalColors; 163 | if (color > 160) { 164 | color += 180 * 4; 165 | } 166 | leds.show(); 167 | delayMicroseconds(delay1); 168 | counter += (delay1 / 1000); // offset 169 | } 170 | } 171 | digitalWrite(1, LOW); 172 | } 173 | 174 | 175 | 176 | void horizontalRingsWithGaps(int duration, int delay1) { // overflows 177 | int counter = 0; 178 | int color = 0; 179 | digitalWrite(1, HIGH); 180 | while (counter < (duration * 1000)) { 181 | int gapStart = random(5, 55); 182 | int gapEnd = random(5, 55); 183 | for (int y = 0; y < ledsPerHoop; y++) { 184 | for (int x = 0; x < hoopCount; x++) { 185 | leds.setPixel((x * 60) + y, rainbowColors[color]); 186 | } 187 | if (y < (gapStart + 4) && y >= gapStart) { 188 | color += 180; 189 | } 190 | if (y > (gapEnd - 4) && y <= gapEnd) { // (y == gapEnd) { 191 | color -= 180; 192 | } 193 | leds.show(); 194 | delayMicroseconds(delay1); 195 | counter += (delay1 / 1000); // offset 196 | } 197 | color = (color + random(40)) % totalColors; 198 | } 199 | digitalWrite(1, LOW); 200 | } 201 | 202 | void verticalRings(int duration, int delay1) { // stops in between.. 203 | int counter = 0; 204 | int color = 0; 205 | digitalWrite(1, HIGH); 206 | while (counter < (duration * 1000)) { 207 | for (int x = 0; x < totalLeds; x++) { 208 | leds.setPixel(x, rainbowColors[color]); 209 | if (x % ledsPerHoop == 0) { 210 | color = (color + 9) % totalColors; 211 | leds.show(); 212 | delayMicroseconds(delay1); 213 | counter += (delay1 / 1000); // offset 214 | } 215 | } 216 | } 217 | digitalWrite(1, LOW); 218 | } 219 | 220 | 221 | void sparkleRandom(int duration, int delay1) { 222 | int counter = 0; 223 | int color = 0; 224 | digitalWrite(1, HIGH); 225 | while (counter < (duration * 1000)) { 226 | leds.setPixel(random(totalLeds), rainbowColors[color]); 227 | color = (color + 9) % totalColors; 228 | if (color % 5 == 0) { 229 | leds.show(); 230 | } 231 | // delayMicroseconds(delay1); 232 | counter += (delay1 / (1000 * 15)); // offset 233 | } 234 | digitalWrite(1, LOW); 235 | } 236 | 237 | 238 | void allRainbow(int duration, int delay1) { 239 | int counter = 0; 240 | int color = 0; 241 | digitalWrite(1, HIGH); 242 | while (counter < (duration * 1000)) { 243 | for (int x = 0; x < totalLeds; x++) { 244 | leds.setPixel(x, rainbowColors[color]); 245 | if (x % totalLeds == 0) { 246 | color = (color + 1) % totalColors; 247 | leds.show(); 248 | delayMicroseconds(delay1); 249 | counter += (delay1 / (1000 * 15)); // offset 250 | } 251 | } 252 | } 253 | digitalWrite(1, LOW); 254 | } 255 | 256 | 257 | 258 | void doubleRainbowCircle(int duration, int delay1) { 259 | int counter = 0; 260 | int color = 0; 261 | int index = 0; 262 | digitalWrite(1, HIGH); 263 | while (counter < (duration * 1000)) { 264 | index += ledsPerHoop; 265 | int stripe1 = random(20); 266 | int stripe2 = random(20, 40); 267 | int stripe3 = random(40, 60); 268 | for (int x = 0; x < totalLeds; x++) { 269 | index++; 270 | index %= totalLeds; 271 | leds.setPixel(index, rainbowColors[color]); 272 | if (x % ledsPerHoop == 0) { 273 | color = (color + 15) % totalColors; 274 | } 275 | if (x % totalLeds == 0) { 276 | leds.show(); 277 | delayMicroseconds(delay1); 278 | counter += (delay1 / (1000 * 25)); // offset 279 | } 280 | } 281 | } 282 | digitalWrite(1, LOW); 283 | } 284 | 285 | 286 | 287 | 288 | 289 | //////// FRESH LINE 290 | // 291 | //int rainbowRingsGoingAroundColor = 0; 292 | //void rainbowRingsGoingAround(int cycleTime) { // TOO SIMILAR... 293 | // int color, x, y, z, wait; 294 | // wait = cycleTime; // cycleTime * 1000 / ledsPerStrip; 295 | // x = 0; 296 | // y = 0; 297 | // z = 0; 298 | // digitalWrite(1, HIGH); 299 | // 300 | // int toggle = 0; 301 | // while (x < 180 * 2) { 302 | // for (y = 0; y < 60; y++) { 303 | // z = (60 * x) + y; 304 | // z %= 1440; 305 | // leds.setPixel(z, rainbowColors[rainbowRingsGoingAroundColor]); 306 | // } 307 | // if (toggle == 0) { 308 | // rainbowRingsGoingAroundColor++; 309 | // } else { 310 | // rainbowRingsGoingAroundColor--; 311 | // } 312 | // if (rainbowRingsGoingAroundColor >= 180) { 313 | // toggle = 1; 314 | // } 315 | // leds.show(); 316 | // delayMicroseconds(10000); // 10000 317 | // x++; 318 | // } 319 | // 320 | // digitalWrite(1, LOW); 321 | //} 322 | // 323 | // 324 | // 325 | //int rainbowRingsGoingOutFadeColor = 0; 326 | //void rainbowRingsGoingOutFade(int cycleTime) { // GOOD 327 | // int color, x, y, z, wait; 328 | // wait = cycleTime; // cycleTime * 1000 / ledsPerStrip; 329 | // x = 0; 330 | // y = 0; 331 | // digitalWrite(1, HIGH); 332 | // 333 | // for (y = 0; y < ledsPerHoop; y++) { 334 | // for (x = 0; x < hoopCount; x++) { 335 | // z = (x * ledsPerHoop) + y; 336 | // // rainbowRingsGoingOutFadeColor = y; 337 | // // if (y < 2) { 338 | // // rainbowRingsGoingOutFadeColor -= 180 * 2; 339 | // // } else if (y > 56) { 340 | // // rainbowRingsGoingOutFadeColor += 180; 341 | // // } 342 | // rainbowRingsGoingOutFadeColor += 17; 343 | // rainbowRingsGoingOutFadeColor %= 180; 344 | // // Serial.println("color: %d", rainbowRingsGoingOutFadeColor); 345 | // Serial.println(rainbowRingsGoingOutFadeColor); 346 | // leds.setPixel(z, rainbowColors[rainbowRingsGoingOutFadeColor]); 347 | // } 348 | // leds.show(); 349 | // delayMicroseconds(cycleTime * 10); 350 | // } 351 | // 352 | // digitalWrite(1, LOW); 353 | //} 354 | // 355 | // 356 | //int rainbowRingsGoingOutDarkerColor = 0; 357 | //void rainbowRingsGoingOutDarker(int cycleTime) { // GOOD 358 | // int color, x, y, z, wait; 359 | // wait = cycleTime * 1000 / ledsPerStrip; 360 | // x = 0; 361 | // y = 0; 362 | // digitalWrite(1, HIGH); 363 | // 364 | // while (x < totalLeds) { 365 | // leds.setPixel(y, rainbowColors[rainbowRingsGoingOutDarkerColor]); 366 | // x++; 367 | // y += 60; 368 | // if (x % 24 == 0) { 369 | // leds.show(); 370 | // delayMicroseconds(cycleTime * 5); 371 | // y++; 372 | // rainbowRingsGoingOutDarkerColor += 7; // z++; 373 | // } 374 | // y %= totalLeds; 375 | // rainbowRingsGoingOutDarkerColor %= 1080; // 180 376 | // } 377 | // digitalWrite(1, LOW); 378 | //} 379 | // 380 | // 381 | //void raibowSyncCircleAround(int cycleTime) { // GOOD 382 | // int color, x, y, z, wait; 383 | // wait = cycleTime * 1000 / ledsPerStrip; 384 | // x = 0; 385 | // y = 0; 386 | // z = 0; 387 | // digitalWrite(1, HIGH); 388 | // 389 | // while (x < totalLeds) { 390 | // leds.setPixel(x, rainbowColors[y]); 391 | // x++; 392 | // if (x % 60 == 0) { 393 | // y += 2; //6 394 | // leds.show(); 395 | // delayMicroseconds(cycleTime * 10); 396 | // } 397 | //// x %= totalLeds; 398 | // y %= 180; 399 | // } 400 | // digitalWrite(1, LOW); 401 | //} 402 | // 403 | // 404 | //void raibowRingLineAround(int cycleTime) { 405 | // int color, x, y, z, wait; 406 | // wait = cycleTime * 1000 / ledsPerStrip; 407 | // x = 0; 408 | // y = 0; 409 | // z = 0; 410 | // digitalWrite(1, HIGH); 411 | // 412 | // while (x < 14400) { 413 | // leds.setPixel(x, rainbowColors[y]); 414 | // leds.show(); 415 | // x++; 416 | // if (x % 120 == 0) { 417 | // y += 12; 418 | // } 419 | // x %= totalLeds; 420 | // y %= 180; 421 | // } 422 | // digitalWrite(1, LOW); 423 | //} 424 | // 425 | // 426 | //int rainbowRingsGoingOutColor = 0; 427 | //void rainbowRingsGoingOut(int cycleTime) { // GOOD 428 | // int color, x, y, z, wait; 429 | // wait = cycleTime * 1000 / ledsPerStrip; 430 | // x = 0; 431 | // y = 0; 432 | // digitalWrite(1, HIGH); 433 | // 434 | // while (x < totalLeds) { 435 | // leds.setPixel(y, rainbowColors[rainbowRingsGoingOutColor]); 436 | // x++; 437 | // y += 60; 438 | // if (x % 24 == 0) { 439 | // leds.show(); 440 | // delayMicroseconds(cycleTime * 5); 441 | // y++; 442 | // rainbowRingsGoingOutColor += 7; // z++; 443 | // } 444 | // y %= totalLeds; 445 | // rainbowRingsGoingOutColor %= 180; 446 | // } 447 | // digitalWrite(1, LOW); 448 | //} 449 | // 450 | // 451 | //void solidColorRingsGoingOut(int cycleTime) { 452 | // int color, x, y, z, wait; 453 | // wait = cycleTime * 1000 / ledsPerStrip; 454 | // x = 0; 455 | // y = 0; 456 | // z = 0; 457 | // digitalWrite(1, HIGH); 458 | // while (z < 180) { 459 | // z %= 180; 460 | // x = 0; 461 | // while (x < totalLeds) { 462 | // y += 60; 463 | // y %= totalLeds; 464 | // if (x % 24 == 0) { 465 | // y++; 466 | // } 467 | // leds.setPixel(y, rainbowColors[z]); 468 | // leds.show(); 469 | // x++; 470 | // } 471 | // z += 45; 472 | // } 473 | // digitalWrite(1, LOW); 474 | //} 475 | // 476 | // 477 | //void sparklingInRandomly(int cycleTime) { 478 | // int color, x, y, wait; 479 | // wait = cycleTime * 1000 / ledsPerStrip; 480 | // x = 0; 481 | // y = 0; 482 | // digitalWrite(1, HIGH); 483 | // while (x < 1440) { 484 | // // y = y + (x * 60); 485 | // // if (y > 1440) { 486 | // // y++; 487 | // // y %= 1440; 488 | // // } 489 | // y = random(1440); 490 | // leds.setPixel(y, rainbowColors[random(180)]); 491 | // leds.show(); 492 | // x++; 493 | // } 494 | // digitalWrite(1, LOW); 495 | //} 496 | // 497 | // 498 | ////int currentColor = 0; 499 | ////void raibowLine(int cycleTime) { 500 | //// int color, x, y, wait; 501 | //// wait = cycleTime * 1000 / ledsPerStrip; 502 | //// x = 0; 503 | //// y = 0; 504 | //// digitalWrite(1, HIGH); 505 | //// while (x <= 1440) { 506 | //// x++; 507 | //// if (x % 60 == 0) { 508 | //// currentColor = random(180); 509 | //// } 510 | //// leds.setPixel(x, rainbowColors[currentColor]); 511 | //// leds.show(); 512 | //// } 513 | ////// currentColor += 30 % 180; 514 | //// digitalWrite(1, LOW); 515 | ////} 516 | // 517 | // 518 | //// First one. lol 519 | //void solidRainbow(int phaseShift, int cycleTime) { 520 | // int color, x, y, wait; 521 | // wait = cycleTime * 1000 / ledsPerStrip; 522 | // for (color = 0; color < 180; color++) { 523 | // digitalWrite(1, HIGH); 524 | // for (x = 0; x < ledsPerStrip; x++) { 525 | // for (y = 0; y < stripCount; y++) { 526 | // int index = color; // (color + x + y*phaseShift/2) % 180; 527 | // leds.setPixel(x + y * ledsPerStrip, rainbowColors[index]); 528 | // } 529 | // } 530 | // leds.show(); 531 | // digitalWrite(1, LOW); 532 | // delayMicroseconds(wait * 2); 533 | // } 534 | //} 535 | // 536 | 537 | // phaseShift is the shift between each row. phaseShift=0 538 | // causes all rows to show the same colors moving together. 539 | // phaseShift=180 causes each row to be the opposite colors 540 | // as the previous. 541 | // 542 | // cycleTime is the number of milliseconds to shift through 543 | // the entire 360 degrees of the color wheel: 544 | // Red -> Orange -> Yellow -> Green -> Blue -> Violet -> Red 545 | // 546 | void rainbow(int phaseShift, int cycleTime) { 547 | int color, x, y, wait; 548 | 549 | wait = cycleTime * 1000 / ledsPerStrip; 550 | for (color = 0; color < 180; color++) { 551 | digitalWrite(1, HIGH); 552 | for (x = 0; x < ledsPerStrip; x++) { 553 | for (y = 0; y < stripCount; y++) { 554 | int index = (color + x + y * phaseShift / 2) % 180; 555 | leds.setPixel(x + y * ledsPerStrip, rainbowColors[index]); 556 | } 557 | } 558 | leds.show(); 559 | digitalWrite(1, LOW); 560 | delayMicroseconds(wait); 561 | } 562 | } 563 | 564 | 565 | --------------------------------------------------------------------------------