Created
November 12, 2019 21:09
-
-
Save giantmolecules/669a49d0f346771ada8223112dc9c6e9 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 <Adafruit_NeoPixel.h> | |
#define PIN 0 // On Trinket or Gemma, suggest changing this to 1 | |
#define NUMPIXELS 3 // Popular NeoPixel ring size | |
Adafruit_NeoPixel strip(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800); | |
int counter = 0; | |
bool buttonState = 0; | |
int pastTime = 0; | |
bool wait = false; | |
int interval = 2000; | |
void setup() { | |
pinMode(1, INPUT_PULLUP); | |
strip.clear(); | |
strip.begin(); | |
} | |
void loop() { | |
buttonState = digitalRead(1); | |
if (buttonState == 0) { | |
for (int j = 0; j < 3; j++) { | |
for (int i = 0; i < 3; i++) { | |
strip.clear(); // Set all pixel colors to 'off' | |
strip.setPixelColor(i, strip.Color(0, 150, 0)); | |
strip.show(); // Send the updated pixel colors to the hardware. | |
delay(200); | |
} | |
} | |
counter = random(3); | |
for (int k = 0; k < counter; k++) { | |
strip.clear(); // Set all pixel colors to 'off' | |
strip.setPixelColor(k, strip.Color(0, 150, 0)); | |
strip.show(); // Send the updated pixel colors to the hardware. | |
delay(200); | |
} | |
pastTime = millis(); | |
wait = true; | |
} | |
if (wait && millis() - pastTime > interval) { | |
strip.clear(); | |
strip.show(); | |
pastTime = millis(); | |
wait = false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment