« Box | Main | Code »
Monday
Apr252016

Post Full Of Spoilers

Read this at the risk of spoiling everything.  I would avoid it if you can.

Last night I figured out my code.  Right not it is set up to run two actions on a single strand of LEDs.  Seven LEDs will be designated as display lights for Morse Code which will display a phrase and repeat after the cycle.  The rest of the LEDs are coded to be on at a constant brightness.  I'll tell you what they will all be used for later but at this point they work correctly.  

This code took about 20 hours to sort out and involved information gathered and learned from more then 15 other finished codes found all over the internet.  While each of the codes I found taught me something that pushed me towards my final product, three of them were major pieces to the puzzle as I plugged and played through all of them.  I'm way closer to Arduino literacy then I was with the code for Zed and with help from the many sources I can write commands from scratch.  This allowed me to turn what was originally a much longer script of parts into a nice tight set of commands where instead of having three sepperate sections refer to three sepperate LED actions, I now have one driving it all three.

Here of a video of the lights in action.

 The Guts!

// Think about the space between the repeat.  Longer or not?
// There is a dimming of the pixels that are not involved in the Morse when pulse occurs.  Hoping external power supply fixes issue.
// Think about leaving some light in the low end of the pulse and pauses.
#include <Adafruit_NeoPixel.h>
#define PIN 6
#define NUM_LEDS 8
// Parameter 1 = number of pixels in strip
// Parameter 2 = pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
//   NEO_KHZ800  800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
//   NEO_KHZ400  400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
//   NEO_GRB     Pixels are wired for GRB bitstream (most NeoPixel products)
//   NEO_RGB     Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUM_LEDS, PIN, NEO_GRB + NEO_KHZ800);
void setup() {
  strip.begin();
  strip.show(); // Initialize all pixels to 'off'
}
void loop() {
  RGBLoop();
}
void RGBLoop() {
// Color of strip minus pixels involved in Morse Code
  for (int i = 0; i < NUM_LEDS; i++) {
// pixels.Color takes RGB values, from 0,0,0 up to 255,255,255
    strip.setPixelColor(i, strip.Color(255, 255, 255)); // Moderately bright green color.
    strip.show(); // This sends the updated pixel color to the hardware.
  }
// Morse Code "DISPLACEMENT" 
  for (int j = 0; j < 43; j++ ) {
// Fade IN
    for (int k = 0; k < 256; k++) {
      switch (j) {
        case 0: setAlldah(k, k, k); break;
        case 1: setAlldi(k, k, k); break;
        case 2: setAlldi(k, k, k); break;
        case 3: setAllpause(k, k, k); break;
        case 4: setAlldi(k, k, k); break;
        case 5: setAlldi(k, k, k); break;
        case 6: setAllpause(k, k, k); break;
        case 7: setAlldi(k, k, k); break;
        case 8: setAlldi(k, k, k); break;
        case 9: setAlldi(k, k, k); break;
        case 10: setAllpause(k, k, k); break;
        case 11: setAlldi(k, k, k); break;
        case 12: setAlldah(k, k, k); break;
        case 13: setAlldah(k, k, k); break;
        case 14: setAlldi(k, k, k); break;
        case 15: setAllpause(k, k, k); break;
        case 16: setAlldi(k, k, k); break;
        case 17: setAlldah(k, k, k); break;
        case 18: setAlldi(k, k, k); break;
        case 19: setAlldi(k, k, k); break;
        case 20: setAllpause(k, k, k); break;
        case 21: setAlldi(k, k, k); break;
        case 22: setAlldah(k, k, k); break;
        case 23: setAllpause(k, k, k); break;
        case 24: setAlldah(k, k, k); break;
        case 25: setAlldi(k, k, k); break;
        case 26: setAlldah(k, k, k); break;
        case 27: setAlldi(k, k, k); break;
        case 28: setAllpause(k, k, k); break;
        case 29: setAlldi(k, k, k); break;
        case 30: setAllpause(k, k, k); break;
        case 31: setAlldah(k, k, k); break;
        case 32: setAlldah(k, k, k); break;
        case 33: setAllpause(k, k, k); break;
        case 34: setAlldi(k, k, k); break;
        case 35: setAllpause(k, k, k); break;
        case 36: setAlldah(k, k, k); break;
        case 37: setAlldi(k, k, k); break;
        case 38: setAllpause(k, k, k); break;
        case 39: setAlldah(k, k, k); break;
        case 40: setAllpause(k, k, k); break;
        case 41: setAllpause(k, k, k); break;
        case 42: setAllpause(k, k, k); break;
      }
      showStrip();
    }
// Fade OUT
    for (int k = 255; k >= 0; k--) {
      switch (j) {
        case 0: setAlldah(k, k, k); break;
        case 1: setAlldi(k, k, k); break;
        case 2: setAlldi(k, k, k); break;
        case 3: setAllpause(k, k, k); break;
        case 4: setAlldi(k, k, k); break;
        case 5: setAlldi(k, k, k); break;
        case 6: setAllpause(k, k, k); break;
        case 7: setAlldi(k, k, k); break;
        case 8: setAlldi(k, k, k); break;
        case 9: setAlldi(k, k, k); break;
        case 10: setAllpause(k, k, k); break;
        case 11: setAlldi(k, k, k); break;
        case 12: setAlldah(k, k, k); break;
        case 13: setAlldah(k, k, k); break;
        case 14: setAlldi(k, k, k); break;
        case 15: setAllpause(k, k, k); break;
        case 16: setAlldi(k, k, k); break;
        case 17: setAlldah(k, k, k); break;
        case 18: setAlldi(k, k, k); break;
        case 19: setAlldi(k, k, k); break;
        case 20: setAllpause(k, k, k); break;
        case 21: setAlldi(k, k, k); break;
        case 22: setAlldah(k, k, k); break;
        case 23: setAllpause(k, k, k); break;
        case 24: setAlldah(k, k, k); break;
        case 25: setAlldi(k, k, k); break;
        case 26: setAlldah(k, k, k); break;
        case 27: setAlldi(k, k, k); break;
        case 28: setAllpause(k, k, k); break;
        case 29: setAlldi(k, k, k); break;
        case 30: setAllpause(k, k, k); break;
        case 31: setAlldah(k, k, k); break;
        case 32: setAlldah(k, k, k); break;
        case 33: setAllpause(k, k, k); break;
        case 34: setAlldi(k, k, k); break;
        case 35: setAllpause(k, k, k); break;
        case 36: setAlldah(k, k, k); break;
        case 37: setAlldi(k, k, k); break;
        case 38: setAllpause(k, k, k); break;
        case 39: setAlldah(k, k, k); break;
        case 40: setAllpause(k, k, k); break;
        case 41: setAllpause(k, k, k); break;
        case 42: setAllpause(k, k, k); break;
      }
      showStrip();
    }
  }
}
void showStrip() {
#ifdef ADAFRUIT_NEOPIXEL_H
  // NeoPixel
  strip.show();
#endif
}
void setPixel(int Pixel, byte red, byte green, byte blue) {
#ifdef ADAFRUIT_NEOPIXEL_H
  // NeoPixel
  strip.setPixelColor(Pixel, strip.Color(red, green, blue));
#endif
}
// di
void setAlldi(byte red, byte green, byte blue) {
  for (int i = 0; i < 4; i++ ) {
    setPixel(i, red, green, blue);
  }
  showStrip();
  delay(3);
}
// dah
void setAlldah(byte red, byte green, byte blue) {
  for (int i = 0; i < 4; i++ ) {
    setPixel(i, red, green, blue);
  }
  showStrip();
  delay(5);
}
// pause
void setAllpause(byte red, byte green, byte blue) {
  for (int j = 0; j < 4; j++ ) {
    setPixel(j, 0, 0, 0);
  }
  showStrip();
  delay(2);
}

 

Reader Comments

There are no comments for this journal entry. To create a new comment, use the form below.

PostPost a New Comment

Enter your information below to add a new comment.

My response is on my own website »
Author Email (optional):
Author URL (optional):
Post:
 
Some HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>