Editing WingScreen

Jump to navigation Jump to search
Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then publish the changes below to finish undoing the edit.

Latest revision Your text
Line 41: Line 41:
/*
/*
*  Serial control interface for LED Strip
*  Serial control interface for LED Strip
*
*    Updated: 20140923
*
*      H4X0r'd some shitz uppple
*        -- insert LED of some sort in A0 & Ground (in right direction)
*        -- pseudo lite senzor for mode switching
*        -- pseudo lite mode 8 noise floor graph
*
*    Command Summary:
*    Command Summary:
*      MODE0 == Auto (Rainbeau)
*      MODE0 == Auto (Rainbeau)
Line 55: Line 47:
*      HH..H == Sequence of Hue values to apply to LEDs
*      HH..H == Sequence of Hue values to apply to LEDs
*        Note: Set "MODE2" before sending hues
*        Note: Set "MODE2" before sending hues
*      S    == Set saturation
*      MODE3 == Center Peak Rainbeau
*      MODE4 == Center Peak Pastel
*/
*/


Line 63: Line 52:


// How many leds in your strip?
// How many leds in your strip?
#define NUM_LEDS 72
#define NUM_LEDS 12


// Spacing between pixel/color
// Spacing between pixel/color
#define HSV_PAD 4
#define HSV_PAD 22


// Delay between cycles
// Delay between cycles
#define LOOP_DELAY 50
#define LOOP_DELAY 20


// Strip Data In (DI)
#define DATA_PIN 11
#define DATA_PIN 11


Line 77: Line 65:
CRGB leds[NUM_LEDS];
CRGB leds[NUM_LEDS];


float counter = 0;
byte count = 0;
byte count = 0;


byte mode = 8;
byte mode = 0;
byte hues[NUM_LEDS];
byte hues[NUM_LEDS];
byte sat = 255;      // Saturation 0-255
boolean irEnable = true;
float ir = 0.0;
const int morse[27] = {2,0,1,0,1,0,2,0,0,2,0,2,0,2,0,0,2,0,1,0,1,0,2,0,0,0,0};


String inputString = "";
String inputString = "";


void setup() {  
void setup() {  
  pinMode(13, OUTPUT);
    
    
   for (int i = 0; i < NUM_LEDS; i++)
   for (int i = 0; i < NUM_LEDS; i++)
Line 99: Line 79:
   }
   }
    
    
  /*
   FastLED.addLeds<WS2812B, DATA_PIN, RGB>(leds, NUM_LEDS);
  *  Confirm GRB color ordering for WS2812b
  *       
  *    \/ \/ \/ \/ BIG FAT NOTE \/ \/ \/ \/
  *
  */
   FastLED.addLeds<WS2812B, DATA_PIN, GRB>(leds, NUM_LEDS);
    
    
  // Max brightness 0-255 (64 ~< 100ma for 12 LEDs)
   FastLED.setBrightness(64);
   FastLED.setBrightness(64);
    
    
Line 118: Line 91:
void loop() {
void loop() {
   int i;
   int i;
  int v;
  float p;
  if (irEnable)
  {
    ir = max((analogRead(A0) / 1.0 - ir) * 0.5 - 10 + ir, ir);
    if (ir > 60)
    {
      // Bump mode
      ir = 0;
      if (++mode > 8)
        mode = 0;
    }
  }
    
    
   if (mode == 0)
   if (mode == 0)
Line 139: Line 97:
     for (i = 0; i < NUM_LEDS; i++)
     for (i = 0; i < NUM_LEDS; i++)
     {
     {
       leds[i] = CHSV(count + (i * HSV_PAD), sat, 255);
       leds[i] = CHSV(count + (i * HSV_PAD), 255, 255);
     }
     }
     FastLED.show();
     FastLED.show();
Line 161: Line 119:
     // Remote
     // Remote
   }
   }
  else if (mode == 3)
  {
    // Rainbeau
    for (i = 0; i < NUM_LEDS; i++)
    {
      // variable position dimming
      // Set 'p' to 0.0 - 1.0 so the ends are 0.0 and the center is 1.0
      p = (((NUM_LEDS / 2) - abs(i - (NUM_LEDS / 2.0)))) / (NUM_LEDS / 2.0);
      v = min(255, round(p * 255.0) + 64);
      // sin function added for oscillating color change
      counter += 0.000001337;
      count = sin(counter * 3.14 * 180) * 255 + (i * HSV_PAD);
      leds[i] = CHSV(count, sat, v);
    }
    FastLED.show();
    count++;
   
    delay(LOOP_DELAY);
  }
  else if (mode == 4)
  {
    // Rainbeau
    for (i = 0; i < NUM_LEDS; i++)
    {
      // variable position dimming
      // Set 'p' to 0.0 - 1.0 so the ends are 0.0 and the center is 1.0
      p = (((NUM_LEDS / 2) - abs(i - (NUM_LEDS / 2.0)))) / (NUM_LEDS / 2.0);
      v = min(255, round(p * 255.0) + 64);
     
      // sin function added for oscillating color change
      counter += 0.000001337;
      count = sin(counter * 3.14 * 180) * 255 + (i * HSV_PAD);
      leds[i] = CHSV(count, sat - (v/1.5), v);
    }
    FastLED.show();
    count++;
   
    delay(LOOP_DELAY);
  }
  else if (mode == 5)
  {
    // Monochrome/Peak
    for (i = 0; i < NUM_LEDS; i++)
    {
      p = (((NUM_LEDS / 2) - abs(i - (NUM_LEDS / 2.0)))) / (NUM_LEDS / 2.0);
      v = min(255, round(p * 255.0) + 16);
      leds[i] = CRGB(v, 0, 0); // CHSV(100, sat, v);
    }
   
    // leds[int(random(0, NUM_LEDS))] = CRGB(96,0,0);
   
    FastLED.show();
    count++;
   
    delay(LOOP_DELAY);
  }
  else if (mode == 6)
  {
    // count = 0;
   
    for (i = 0; i < NUM_LEDS; i++)
    {
      leds[i] = CHSV(morse[(i + count) % 27] == 1 ? 120 : 0, sat, morse[(i + count) % 27] == 0 ? 0 : 255);
    }
    FastLED.show();
   
    count++;
   
    delay(LOOP_DELAY);
  }
  else if (mode == 7)
  {
    byte r;
   
    for (i = 0; i < NUM_LEDS; i++)
    {
      // counter = sin(count * 3.14 * 180) * 255 + i;
     
      r = random(127, 255);     
      leds[i] = CRGB(r, random(0, 100) < 20 ? r : 0, 0);
    }
    // count++;
   
    FastLED.show();
   
    delay(LOOP_DELAY / 5);
  }
  else if (mode == 8)
  {
    // ir = max((analogRead(A0) / 1.0 - ir) * 0.5 - 10 + ir, ir);
   
    for (i = 0; i < NUM_LEDS; i++)
    {
      if (i < ir)
      {
        leds[i] = CHSV(0, 255, 255); // ir > 30 ? 127 : 32);
      }
      else
      {
        leds[i] = CHSV(66, 255, 32);
      }
    }
   
    // ir = min(0, ir - 1.337);
   
    FastLED.show();
   
    delay(LOOP_DELAY);
  }
 
  if (irEnable)
    ir = min(0, ir - 1.337);
}
}


Line 282: Line 127:
   }
   }
   FastLED.show();
   FastLED.show();
 
  // Toggle onboard LED
  digitalWrite(13, !digitalRead(13));
}
}


void serialEvent() {
void serialEvent() {
   byte byteCount = 0;
   byte count = 0;
   byte data;
   byte data;
    
    
Line 297: Line 139:
     data = Serial.read();
     data = Serial.read();
     inputString += (char)data;
     inputString += (char)data;
     if (byteCount < NUM_LEDS)
     if (count < NUM_LEDS)
     {
     {
       hues[byteCount++] = data;
       hues[count++] = data;
     }
     }
      
      
Line 306: Line 148:
       delay(20);
       delay(20);
   }
   }
 
  Serial.println(inputString);
    
    
   if (inputString == "MODE0")
   if (inputString == "MODE0")
Line 318: Line 162:
   {
   {
     mode = 2;
     mode = 2;
  }
  else if (inputString == "MODE3")
  {
    mode = 3;
  }
  else if (inputString == "MODE4")
  {
    mode = 4;
  }
  else if (inputString == "NINJA")
  {
    mode = 5;
  }
  else if (inputString == "MORSE")
  {
    mode = 6;
   }
   }
   else if (inputString.length() == NUM_LEDS)
   else if (inputString.length() == NUM_LEDS)
Line 339: Line 167:
     updateHues();
     updateHues();
   }
   }
   else if (inputString.length() == 1)
   else
   {
   {
     sat = data;
     // WTF?
   }
   }
}
}
Line 348: Line 176:
== Desktop Emulator ==
== Desktop Emulator ==
[[File:HSV.jpg|960px]]
[[File:HSV.jpg|960px]]
See also: [[FlashDevelop]]


=== Main ===
=== Main ===
Please note that all contributions to Noisebridge are considered to be released under the Creative Commons Attribution-NonCommercial-ShareAlike (see Noisebridge:Copyrights for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource. Do not submit copyrighted work without permission!

To protect the wiki against automated edit spam, we kindly ask you to solve the following CAPTCHA:

Cancel Editing help (opens in new window)