Created
February 8, 2017 14:59
-
-
Save hhayley/0f6f9634465fa0897730ae003acec26c to your computer and use it in GitHub Desktop.
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 "Interval.h" | |
#include <Adafruit_NeoPixel.h> | |
const int knockSensor = A0; | |
int val = 0; | |
#define PIN 6 | |
const int numPixels = 7; | |
Adafruit_NeoPixel strip = Adafruit_NeoPixel(numPixels, PIN, NEO_RGBW + NEO_KHZ800); | |
int alpha; // Current value of the pixels | |
int dir = 1; // Direction of the pixels... 1 = getting brighter, 0 = getting dimmer | |
int flip; // Randomly flip the direction every once in a while | |
int minAlpha = 25; // Min value of brightness | |
int maxAlpha = 100; // Max value of brightness | |
int alphaDelta = 5; // Delta of brightness between times through the loop | |
void setup() { | |
Serial.begin(9600); | |
strip.begin(); | |
strip.show(); | |
} | |
void loop() { | |
val = analogRead(knockSensor); | |
Serial.println(val); | |
flip = random(40); | |
if (flip > val/2) { | |
dir = 1 - dir; | |
} | |
if (dir == 1) { | |
alpha += alphaDelta; | |
} | |
if (dir == 0) { | |
alpha -= alphaDelta; | |
} | |
if (alpha < minAlpha) { | |
alpha = minAlpha; | |
dir = 1; | |
} | |
if (alpha > maxAlpha) { | |
alpha = maxAlpha; | |
dir = 0; | |
} | |
strip.setPixelColor(0, alpha / 5, alpha * 1.5, 0, 10); // orange | |
strip.setPixelColor(1, alpha / 3, alpha, 0, alpha ); // white | |
strip.setPixelColor(4, alpha / 5, 0, 30); // cyan | |
strip.setPixelColor(2, 0, 0, 0, 0); | |
strip.setPixelColor(3, 0, 0, 0, 0); | |
strip.setPixelColor(5, 0, 0, 0, 0); | |
strip.setPixelColor(6, 0, 0, 0, 0); | |
strip.show(); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment