hackbyte

disled.c

Jan 7th, 2018
692
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 11.18 KB | None | 0 0
  1. /*******************************************************************************
  2. * disled.c (distraction led (encoder)
  3. *
  4. * Just a cheap hack cuz i don't like christmas at all and so, because i love
  5. * anything that blinks or just shines with whatever light, i have a huge
  6. * problem with all these christmas related lighting stuff....
  7. *
  8. * It's annoying because it's so xmas centered. AND because it just blinks or
  9. * shines in some ways..
  10. *
  11. * So ... here i am, cuz i can do that better .. in some strange ways.
  12. *
  13. * Have fun.
  14. *
  15. * Copyleft 2017-12-25 or so, by me hackbyte and tons of others giving me
  16. * this simple way to do it (arduino, gcc, tons of websites and so on. ;))
  17. *******************************************************************************/
  18.  
  19. #include <Adafruit_NeoPixel.h>
  20. #ifdef __AVR__
  21. #include <avr/power.h>
  22. #endif
  23.  
  24. #define PIN 6
  25. #define NUMLEDS 24
  26. #define METADELAY 50
  27. #define SERIALDEBUG false
  28. #define MORSETICK 75
  29.  
  30. Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUMLEDS, PIN, NEO_GRB + NEO_KHZ800);
  31.  
  32. uint32_t ROT = strip.Color(255, 0, 0); uint32_t GRUEN = strip.Color(0, 255, 0); uint32_t BLAU = strip.Color(0, 0, 255); uint32_t WEISS = strip.Color(255, 255, 255); uint32_t GELB = strip.Color(255, 100, 0); uint32_t AUS = strip.Color(0, 0, 0);
  33.  
  34. /*
  35. morse code timings
  36.   short mark, dot or "dit"     (▄▄▄▄): "dot duration" is one time unit long
  37.   longer mark, dash or "dah" (▄▄▄▄▄▄): three time units long
  38.   inter-element gap between the dots and dashes within a character: one dot duration or one unit long
  39.   short gap (between letters): three time units long
  40.   medium gap (between words): seven time units long
  41. */
  42.  
  43. char morsetext[] = "send nudes";
  44.  
  45. /****************************************************************************************************
  46. Here starts all the mess
  47. *****************************************************************************************************/
  48. void setup() {
  49.   if (SERIALDEBUG) { Serial.begin(57600); }
  50.   sdebug("Setup...");
  51.  
  52.   strip.begin(); strip.setBrightness(100);
  53.   // strip.setBrightness(100);
  54.   strip.show(); // Initialize all pixels to 'off'
  55.  
  56.   allpx(WEISS); delay(500); alloff(); delay(500);
  57.  
  58.   sdebugln(""); sdebugln("");
  59. }
  60.  
  61. /****************************************************************************************************
  62. Here it gets repeated over and over and over and over and over and over and over and over and over an
  63. *****************************************************************************************************/
  64. void loop() {
  65.   sdebug("Loop Start:");
  66.   wildblink(); delay(750); morsemessage(GELB,morsetext); delay(750);
  67.  
  68.   wildblink(); delay(750); morsemessage(ROT,morsetext);delay(750);
  69.  
  70.   wildblink(); delay(750); morsemessage(WEISS,morsetext);delay(750);
  71.  
  72.   wildblink(); delay(750); morsemessage(BLAU,morsetext);delay(750);
  73.  
  74.   wildblink(); delay(750); morsemessage(GRUEN,morsetext);delay(750);
  75.  
  76.   sdebug("\nLoop end...\n\n\n");
  77.   delay(2000);
  78. }
  79.  
  80. /****************************************************************************************************
  81. Here we send any actual message as morse code...
  82. *****************************************************************************************************/
  83. void morsemessage(uint32_t pixelcolor, char morsetext[]) {
  84.   /* loop over a string using subscript*/
  85.   int indexnum;
  86.   for (indexnum = 0; indexnum < strlen(morsetext); indexnum++)
  87.   {
  88.     morsechar(morsetext[indexnum], pixelcolor);
  89.   }
  90. }
  91.  
  92. /****************************************************************************************************
  93. Here we actually send a single char as morse code
  94. *****************************************************************************************************/
  95. void morsechar(char mychar, uint32_t pixelcolor) {
  96.   if (mychar == ' ') {  
  97.     if (SERIALDEBUG) { Serial.println("space"); }
  98.     delay(MORSETICK * 6);
  99.   } else {
  100.     sdebug(mychar);
  101.   }
  102.   switch (tolower(mychar)) {
  103.     case 'a' : bleep(pixelcolor); blip(pixelcolor);     delay(MORSETICK * 2); break;
  104.     case 'b' : bleep(pixelcolor); blip(pixelcolor);     blip(pixelcolor);     blip(pixelcolor);     delay(MORSETICK * 2); break;
  105.     case 'c' : bleep(pixelcolor); blip(pixelcolor);     bleep(pixelcolor);    blip(pixelcolor);     delay(MORSETICK * 2); break;
  106.     case 'd' : bleep(pixelcolor); blip(pixelcolor);     blip(pixelcolor);     delay(MORSETICK * 2); break;
  107.     case 'e' : blip(pixelcolor);  delay(MORSETICK * 2); break;
  108.     case 'f' : blip(pixelcolor);  blip(pixelcolor);     bleep(pixelcolor);    blip(pixelcolor);     delay(MORSETICK * 2); break;
  109.     case 'g' : bleep(pixelcolor); bleep(pixelcolor);    blip(pixelcolor);     delay(MORSETICK * 2); break;
  110.     case 'h' : blip(pixelcolor);  blip(pixelcolor);     blip(pixelcolor);     blip(pixelcolor);     delay(MORSETICK * 2); break;
  111.     case 'i' : blip(pixelcolor);  blip(pixelcolor);     delay(MORSETICK * 2); break;
  112.     case 'j' : blip(pixelcolor);  bleep(pixelcolor);    bleep(pixelcolor);    bleep(pixelcolor);    delay(MORSETICK * 2); break;
  113.     case 'k' : bleep(pixelcolor); blip(pixelcolor);     bleep(pixelcolor);    delay(MORSETICK * 2); break;
  114.     case 'l' : blip(pixelcolor);  bleep(pixelcolor);    blip(pixelcolor);     blip(pixelcolor);     delay(MORSETICK * 2); break;
  115.     case 'm' : bleep(pixelcolor); bleep(pixelcolor);    delay(MORSETICK * 2); break;
  116.     case 'n' : bleep(pixelcolor); blip(pixelcolor);     delay(MORSETICK * 2); break;
  117.     case 'o' : bleep(pixelcolor); bleep(pixelcolor);    bleep(pixelcolor);    delay(MORSETICK * 2); break;
  118.     case 'p' : blip(pixelcolor);  bleep(pixelcolor);    bleep(pixelcolor);    blip(pixelcolor);     delay(MORSETICK * 2); break;
  119.     case 'q' : bleep(pixelcolor); bleep(pixelcolor);    blip(pixelcolor);     bleep(pixelcolor);    delay(MORSETICK * 2); break;
  120.     case 'r' : blip(pixelcolor);  bleep(pixelcolor);    blip(pixelcolor);     delay(MORSETICK * 2); break;
  121.     case 's' : blip(pixelcolor);  blip(pixelcolor);     blip(pixelcolor);     delay(MORSETICK * 2); break;
  122.     case 't' : bleep(pixelcolor); delay(MORSETICK * 2); break;
  123.     case 'u' : blip(pixelcolor);  blip(pixelcolor);     bleep(pixelcolor);    delay(MORSETICK * 2); break;
  124.     case 'v' : blip(pixelcolor);  blip(pixelcolor);     blip(pixelcolor);     bleep(pixelcolor);    delay(MORSETICK * 2); break;
  125.     case 'w' : blip(pixelcolor);  bleep(pixelcolor);    bleep(pixelcolor);    delay(MORSETICK * 2); break;
  126.     case 'x' : bleep(pixelcolor); blip(pixelcolor);     blip(pixelcolor);     bleep(pixelcolor);    delay(MORSETICK * 2); break;
  127.     case 'y' : bleep(pixelcolor); blip(pixelcolor);     bleep(pixelcolor);    bleep(pixelcolor);    delay(MORSETICK * 2); break;
  128.     case 'z' : bleep(pixelcolor); bleep(pixelcolor);    blip(pixelcolor);     blip(pixelcolor);     delay(MORSETICK * 2); break;
  129.     case '*' : break;
  130.   }
  131.   sdebugln(" <-");
  132. }
  133.  
  134. /****************************************************************************************************
  135. Here, we just send a blip (dit)
  136. *****************************************************************************************************/
  137. void  blip(uint32_t pixelcolor) {
  138.   allpx(pixelcolor);
  139.   delay(MORSETICK);
  140.   alloff();
  141.   delay(MORSETICK);
  142. }
  143.  
  144. /****************************************************************************************************
  145. Here we just send a bleep (dah)
  146. *****************************************************************************************************/
  147. void bleep(uint32_t pixelcolor) {
  148.   allpx(pixelcolor);
  149.   delay(MORSETICK * 3);
  150.   alloff();
  151.   delay(MORSETICK);
  152. }
  153.  
  154. /****************************************************************************************************
  155. Here w just switch _all_ leds to any specified color
  156. *****************************************************************************************************/
  157. void allpx(uint32_t THIScolor) {
  158.   for (uint16_t pixelnum = 0; pixelnum < strip.numPixels(); pixelnum++) { strip.setPixelColor(pixelnum, THIScolor); } strip.show();
  159. }
  160.  
  161. /****************************************************************************************************
  162. Here we nearly do the same but just put all leds to off
  163. *****************************************************************************************************/
  164. void alloff() { allpx(AUS); }
  165.  
  166. /****************************************************************************************************
  167. Here we write a message out to the serial port if we're supposed to do so
  168. *****************************************************************************************************/
  169. void sdebug(char debugmsg[]) {
  170.   if (! SERIALDEBUG) { return 0; }
  171.   Serial.print(debugmsg);
  172. }
  173.  
  174. /****************************************************************************************************
  175. Here we write a message and a linefeed out to the serial port if we're supposed to do so
  176. *****************************************************************************************************/
  177. void sdebugln(char debugmsg[]) {
  178.   if (! SERIALDEBUG) { return 0; }
  179.   Serial.println(debugmsg);
  180. }
  181.  
  182. /****************************************************************************************************
  183. Below, there is other stuff
  184. *****************************************************************************************************/
  185. void wildblink() {
  186.   for (uint16_t innernumrepeats=0; innernumrepeats<4; innernumrepeats++) { policeBlink(WEISS); delay(25); policeBlink(GELB); delay(25); policeBlink(WEISS); delay(25); policeBlink(ROT); delay(25); policeBlink(GRUEN); delay(25); }
  187.   // for (uint16_t innernumrepeats=0; innernumrepeats<4; innernumrepeats++) { policeBlink(BLAU); delay(25); policeBlink(ROT); delay(25); policeBlink(WEISS); delay(25); policeBlink(GELB); delay(25); policeBlink(GRUEN); delay(25); }
  188. }
  189.  
  190. void alarmblink(uint32_t pixelcolor, uint16_t repeatnum) {
  191.   for (uint16_t innernumrepeats = 0; innernumrepeats < repeatnum; innernumrepeats++) {
  192.     policeBlink(GELB);
  193.   }
  194. }
  195.  
  196. /****************************************************************************************************
  197.  emulate police car warning lights
  198. *****************************************************************************************************/
  199. void policeBlink(uint32_t pixelcolor) {
  200.   allpx(pixelcolor); delay(100); allpx(AUS); delay(50);
  201.   allpx(pixelcolor); delay(10);  allpx(AUS); delay(50);
  202.   allpx(pixelcolor); delay(10);  allpx(AUS); delay(50);
  203. }
  204.  
  205. /****************************************************************************************************
  206. Below, there is only not used stuff
  207. *****************************************************************************************************/
  208. // morsechar('w',pixelcolor); morsechar('e',pixelcolor); morsechar('i',pixelcolor); morsechar('h',pixelcolor); morsechar('n',pixelcolor); morsechar('a',pixelcolor); morsechar('c',pixelcolor); morsechar('h',pixelcolor); morsechar('t',pixelcolor); morsechar('e',pixelcolor); morsechar('n',pixelcolor);  delay(MORSETICK*7);
  209. // morsechar('n',pixelcolor); morsechar('e',pixelcolor); morsechar('r',pixelcolor); morsechar('v',pixelcolor); morsechar('t',pixelcolor); delay(MORSETICK*7);
  210. // morsechar('t',pixelcolor); morsechar('o',pixelcolor); morsechar('t',pixelcolor); morsechar('a',pixelcolor); morsechar('l',pixelcolor); delay(MORSETICK*7);
Advertisement
Add Comment
Please, Sign In to add comment