-
-
Save aovestdipaperino/31053e17b71270296e85673237655184 to your computer and use it in GitHub Desktop.
NightLocker
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "DigiKeyboard.h" | |
#include "Arduino.h" | |
#include <FastLED.h> | |
#define NUM_LEDS 12 | |
#define DATA_PIN PIN_B0 | |
#define BUTTON_PIN PIN_B2 | |
CRGB leds[NUM_LEDS]; | |
void static OFF() { | |
for (int i=0; i < NUM_LEDS; i++) leds[i] = CRGB::Black; | |
} | |
void setup() { | |
pinMode(LED_BUILTIN, OUTPUT); | |
pinMode(BUTTON_PIN, INPUT); | |
FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS); | |
OFF(); | |
FastLED.show(); | |
} | |
void static KITT_LOOP() { | |
static uint8_t dir = +1; | |
static int8_t currLed = 0; | |
OFF(); | |
leds[currLed] = 0x330000; | |
leds[currLed-dir] = 0x050000; | |
currLed += dir; | |
if (currLed == NUM_LEDS) { | |
dir = -1; | |
currLed = NUM_LEDS -2; | |
} | |
if (currLed == -1) { | |
currLed = 1; | |
dir = 1; | |
} | |
leds[currLed] = CRGB::Red; | |
FastLED.show(); | |
delay(66); | |
if (!currLed) { | |
OFF(); | |
FastLED.show(); | |
delay(1666); | |
} | |
} | |
static void PRESENCE_LOOP() { | |
static uint8_t currLed = 0; | |
OFF(); | |
leds[currLed++] = CRGB::Green; | |
currLed %= NUM_LEDS; | |
FastLED.show(); | |
delay(1000); | |
} | |
uint32_t timestamp = UINT32_MAX; | |
void loop() { | |
DigiKeyboard.update(); | |
DigiKeyboard.sendKeyStroke(0); | |
static uint32_t timestamp = UINT32_MAX; | |
if (millis() > timestamp) { | |
timestamp = UINT32_MAX; | |
DigiKeyboard.sendKeyStroke(KEY_Q, MOD_GUI_LEFT | MOD_CONTROL_LEFT); //run | |
delay(10); | |
} | |
if (digitalRead(BUTTON_PIN)) { | |
timestamp = UINT32_MAX; | |
PRESENCE_LOOP(); | |
} else { | |
if (timestamp == UINT32_MAX) { | |
timestamp = millis() + 2000; // two seconds. | |
} | |
KITT_LOOP(); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment