Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*******************************************************************************
- * disled.c (distraction led (encoder)
- *
- * Just a cheap hack cuz i don't like christmas at all and so, because i love
- * anything that blinks or just shines with whatever light, i have a huge
- * problem with all these christmas related lighting stuff....
- *
- * It's annoying because it's so xmas centered. AND because it just blinks or
- * shines in some ways..
- *
- * So ... here i am, cuz i can do that better .. in some strange ways.
- *
- * Have fun.
- *
- * Copyleft 2017-12-25 or so, by me hackbyte and tons of others giving me
- * this simple way to do it (arduino, gcc, tons of websites and so on. ;))
- *******************************************************************************/
- #include <Adafruit_NeoPixel.h>
- #ifdef __AVR__
- #include <avr/power.h>
- #endif
- #define PIN 6
- #define NUMLEDS 24
- #define METADELAY 50
- #define SERIALDEBUG false
- #define MORSETICK 75
- Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUMLEDS, PIN, NEO_GRB + NEO_KHZ800);
- 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);
- /*
- morse code timings
- short mark, dot or "dit" (▄▄▄▄): "dot duration" is one time unit long
- longer mark, dash or "dah" (▄▄▄▄▄▄): three time units long
- inter-element gap between the dots and dashes within a character: one dot duration or one unit long
- short gap (between letters): three time units long
- medium gap (between words): seven time units long
- */
- char morsetext[] = "send nudes";
- /****************************************************************************************************
- Here starts all the mess
- *****************************************************************************************************/
- void setup() {
- if (SERIALDEBUG) { Serial.begin(57600); }
- sdebug("Setup...");
- strip.begin(); strip.setBrightness(100);
- // strip.setBrightness(100);
- strip.show(); // Initialize all pixels to 'off'
- allpx(WEISS); delay(500); alloff(); delay(500);
- sdebugln(""); sdebugln("");
- }
- /****************************************************************************************************
- Here it gets repeated over and over and over and over and over and over and over and over and over an
- *****************************************************************************************************/
- void loop() {
- sdebug("Loop Start:");
- wildblink(); delay(750); morsemessage(GELB,morsetext); delay(750);
- wildblink(); delay(750); morsemessage(ROT,morsetext);delay(750);
- wildblink(); delay(750); morsemessage(WEISS,morsetext);delay(750);
- wildblink(); delay(750); morsemessage(BLAU,morsetext);delay(750);
- wildblink(); delay(750); morsemessage(GRUEN,morsetext);delay(750);
- sdebug("\nLoop end...\n\n\n");
- delay(2000);
- }
- /****************************************************************************************************
- Here we send any actual message as morse code...
- *****************************************************************************************************/
- void morsemessage(uint32_t pixelcolor, char morsetext[]) {
- /* loop over a string using subscript*/
- int indexnum;
- for (indexnum = 0; indexnum < strlen(morsetext); indexnum++)
- {
- morsechar(morsetext[indexnum], pixelcolor);
- }
- }
- /****************************************************************************************************
- Here we actually send a single char as morse code
- *****************************************************************************************************/
- void morsechar(char mychar, uint32_t pixelcolor) {
- if (mychar == ' ') {
- if (SERIALDEBUG) { Serial.println("space"); }
- delay(MORSETICK * 6);
- } else {
- sdebug(mychar);
- }
- switch (tolower(mychar)) {
- case 'a' : bleep(pixelcolor); blip(pixelcolor); delay(MORSETICK * 2); break;
- case 'b' : bleep(pixelcolor); blip(pixelcolor); blip(pixelcolor); blip(pixelcolor); delay(MORSETICK * 2); break;
- case 'c' : bleep(pixelcolor); blip(pixelcolor); bleep(pixelcolor); blip(pixelcolor); delay(MORSETICK * 2); break;
- case 'd' : bleep(pixelcolor); blip(pixelcolor); blip(pixelcolor); delay(MORSETICK * 2); break;
- case 'e' : blip(pixelcolor); delay(MORSETICK * 2); break;
- case 'f' : blip(pixelcolor); blip(pixelcolor); bleep(pixelcolor); blip(pixelcolor); delay(MORSETICK * 2); break;
- case 'g' : bleep(pixelcolor); bleep(pixelcolor); blip(pixelcolor); delay(MORSETICK * 2); break;
- case 'h' : blip(pixelcolor); blip(pixelcolor); blip(pixelcolor); blip(pixelcolor); delay(MORSETICK * 2); break;
- case 'i' : blip(pixelcolor); blip(pixelcolor); delay(MORSETICK * 2); break;
- case 'j' : blip(pixelcolor); bleep(pixelcolor); bleep(pixelcolor); bleep(pixelcolor); delay(MORSETICK * 2); break;
- case 'k' : bleep(pixelcolor); blip(pixelcolor); bleep(pixelcolor); delay(MORSETICK * 2); break;
- case 'l' : blip(pixelcolor); bleep(pixelcolor); blip(pixelcolor); blip(pixelcolor); delay(MORSETICK * 2); break;
- case 'm' : bleep(pixelcolor); bleep(pixelcolor); delay(MORSETICK * 2); break;
- case 'n' : bleep(pixelcolor); blip(pixelcolor); delay(MORSETICK * 2); break;
- case 'o' : bleep(pixelcolor); bleep(pixelcolor); bleep(pixelcolor); delay(MORSETICK * 2); break;
- case 'p' : blip(pixelcolor); bleep(pixelcolor); bleep(pixelcolor); blip(pixelcolor); delay(MORSETICK * 2); break;
- case 'q' : bleep(pixelcolor); bleep(pixelcolor); blip(pixelcolor); bleep(pixelcolor); delay(MORSETICK * 2); break;
- case 'r' : blip(pixelcolor); bleep(pixelcolor); blip(pixelcolor); delay(MORSETICK * 2); break;
- case 's' : blip(pixelcolor); blip(pixelcolor); blip(pixelcolor); delay(MORSETICK * 2); break;
- case 't' : bleep(pixelcolor); delay(MORSETICK * 2); break;
- case 'u' : blip(pixelcolor); blip(pixelcolor); bleep(pixelcolor); delay(MORSETICK * 2); break;
- case 'v' : blip(pixelcolor); blip(pixelcolor); blip(pixelcolor); bleep(pixelcolor); delay(MORSETICK * 2); break;
- case 'w' : blip(pixelcolor); bleep(pixelcolor); bleep(pixelcolor); delay(MORSETICK * 2); break;
- case 'x' : bleep(pixelcolor); blip(pixelcolor); blip(pixelcolor); bleep(pixelcolor); delay(MORSETICK * 2); break;
- case 'y' : bleep(pixelcolor); blip(pixelcolor); bleep(pixelcolor); bleep(pixelcolor); delay(MORSETICK * 2); break;
- case 'z' : bleep(pixelcolor); bleep(pixelcolor); blip(pixelcolor); blip(pixelcolor); delay(MORSETICK * 2); break;
- case '*' : break;
- }
- sdebugln(" <-");
- }
- /****************************************************************************************************
- Here, we just send a blip (dit)
- *****************************************************************************************************/
- void blip(uint32_t pixelcolor) {
- allpx(pixelcolor);
- delay(MORSETICK);
- alloff();
- delay(MORSETICK);
- }
- /****************************************************************************************************
- Here we just send a bleep (dah)
- *****************************************************************************************************/
- void bleep(uint32_t pixelcolor) {
- allpx(pixelcolor);
- delay(MORSETICK * 3);
- alloff();
- delay(MORSETICK);
- }
- /****************************************************************************************************
- Here w just switch _all_ leds to any specified color
- *****************************************************************************************************/
- void allpx(uint32_t THIScolor) {
- for (uint16_t pixelnum = 0; pixelnum < strip.numPixels(); pixelnum++) { strip.setPixelColor(pixelnum, THIScolor); } strip.show();
- }
- /****************************************************************************************************
- Here we nearly do the same but just put all leds to off
- *****************************************************************************************************/
- void alloff() { allpx(AUS); }
- /****************************************************************************************************
- Here we write a message out to the serial port if we're supposed to do so
- *****************************************************************************************************/
- void sdebug(char debugmsg[]) {
- if (! SERIALDEBUG) { return 0; }
- Serial.print(debugmsg);
- }
- /****************************************************************************************************
- Here we write a message and a linefeed out to the serial port if we're supposed to do so
- *****************************************************************************************************/
- void sdebugln(char debugmsg[]) {
- if (! SERIALDEBUG) { return 0; }
- Serial.println(debugmsg);
- }
- /****************************************************************************************************
- Below, there is other stuff
- *****************************************************************************************************/
- void wildblink() {
- 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); }
- // 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); }
- }
- void alarmblink(uint32_t pixelcolor, uint16_t repeatnum) {
- for (uint16_t innernumrepeats = 0; innernumrepeats < repeatnum; innernumrepeats++) {
- policeBlink(GELB);
- }
- }
- /****************************************************************************************************
- emulate police car warning lights
- *****************************************************************************************************/
- void policeBlink(uint32_t pixelcolor) {
- allpx(pixelcolor); delay(100); allpx(AUS); delay(50);
- allpx(pixelcolor); delay(10); allpx(AUS); delay(50);
- allpx(pixelcolor); delay(10); allpx(AUS); delay(50);
- }
- /****************************************************************************************************
- Below, there is only not used stuff
- *****************************************************************************************************/
- // 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);
- // morsechar('n',pixelcolor); morsechar('e',pixelcolor); morsechar('r',pixelcolor); morsechar('v',pixelcolor); morsechar('t',pixelcolor); delay(MORSETICK*7);
- // 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