Skip to content

Instantly share code, notes, and snippets.

@ArthurGuy
Created August 4, 2017 12:30
Show Gist options
  • Save ArthurGuy/d6724cace34e0ab0be35295bfd055ddf to your computer and use it in GitHub Desktop.
Save ArthurGuy/d6724cace34e0ab0be35295bfd055ddf to your computer and use it in GitHub Desktop.
LEDJar
#include "FastLED.h"
#include <CapacitiveSensor.h>
// How many leds in your strip?
#define NUM_LEDS 130
// What pin are the LED's connected to?
#define DATA_PIN 2
// Define the array of leds
CRGB leds[NUM_LEDS];
CapacitiveSensor cs = CapacitiveSensor(4,6);
bool lightsOn = false;
long onTime = 0;
int effect = 0;
void setup() {
Serial.begin(115200);
Serial.println("resetting");
LEDS.addLeds<WS2812, DATA_PIN, GRB>(leds,NUM_LEDS);
LEDS.setBrightness(255);
}
void loop() {
if (!lightsOn) {
//long start = millis();
long total = cs.capacitiveSensor(30);
//Serial.println(total); // debug output
delay(10);
// How big should the cap sense reading be before we turn on the lights?
if (total > 1000) {
lightsOn = true;
onTime = millis();
}
}
if (lightsOn) {
if (effect == 0) {
effect(1);
} else if (effect == 1) {
effect(2);
} else if (effect == 2) {
effect(3);
} else if (effect == 3) {
effect(4);
}
// After 5 seconds turn off the light
if ((millis() - onTime) > 5000) {
lightsOn = false;
allOff();
effect++;
if (effect > 3) {
effect = 0;
}
}
} else {
// The jar is off
sparkle();
}
}
void allOff() {
for(int i = 0; i < NUM_LEDS; i++) {
leds[i] = 0;
}
FastLED.show();
}
void sparkle() {
// sparkle effect here
}
void effect() {
// different lighting effects here
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment