Skip to content

Instantly share code, notes, and snippets.

@antila
Created May 19, 2019 21:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save antila/60da8af14366e67791aff84870ded044 to your computer and use it in GitHub Desktop.
Save antila/60da8af14366e67791aff84870ded044 to your computer and use it in GitHub Desktop.
Flash Arduino cloud
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h>
#endif
// Which pin on the Arduino is connected to the NeoPixels?
// On a Trinket or Gemma we suggest changing this to 1
#define PIN 7
// How many NeoPixels are attached to the Arduino?
#define NUMPIXELS 25
// When we setup the NeoPixel library, we tell it how many pixels, and which pin to use to send signals.
// Note that for older NeoPixel strips you might need to change the third parameter--see the strandtest
// example for more information on possible values.
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
void setup() {
// Initialize serial port
Serial.begin(115200);
// This initializes the NeoPixel library.
pixels.begin();
}
void loop() {
int flashCount = random (3, 15); // Min. and max. number of flashes each loop
int flashBrightnessMin = 10; // LED flash min. brightness (0-255)
int flashBrightnessMax = 255; // LED flash max. brightness (0-255)
int flashDurationMin = 1; // Min. duration of each seperate flash
int flashDurationMax = 50; // Max. duration of each seperate flash
int nextFlashDelayMin = 1; // Min, delay between each flash and the next
int nextFlashDelayMax = 150; // Max, delay between each flash and the next
int loopDelay = random (3000, 15000); // Min. and max. delay between each loop
Serial.println();
Serial.print(F("Flashing, count: "));
Serial.println( flashCount );
for (int flash = 0 ; flash <= flashCount; flash += 1) { // Flashing LED strip in a loop, random count
int randomPixel = random (0, NUMPIXELS);
int randomValue = random(flashBrightnessMin, flashBrightnessMax);
pixels.setPixelColor(randomPixel, pixels.Color(
randomValue, // R
randomValue, // G
randomValue // B
));
pixels.show();
// Keep the pixel turned on, random duration
delay(random(flashDurationMin, flashDurationMax));
// Turn the pixel off
pixels.setPixelColor(randomPixel, pixels.Color(0, 0, 0));
pixels.show();
// Random delay before next flash
delay(random(nextFlashDelayMin, nextFlashDelayMax));
}
Serial.print(F("Pausing before next loop, milliseconds: "));
Serial.println(loopDelay);
delay(loopDelay);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment