Compare commits
6 Commits
Author | SHA1 | Date |
---|---|---|
Neale Pickett | 9ea79f756a | |
Neale Pickett | c41f6ddcc0 | |
Molly Nicholas | fde662bbee | |
Molly Nicholas | be1a659413 | |
Molly Nicholas | 7c154f79b7 | |
molecule | e8e59dde86 |
14
README.md
14
README.md
|
@ -2,11 +2,23 @@
|
|||
|
||||
[![Lightning cloud](http://i.imgur.com/79LUuV7.png)](https://www.youtube.com/watch?v=XxMMNcU-hWE "Click to see the video")
|
||||
|
||||
A little lightning cloud for fun. [Full Instructable available here](http://www.instructables.com/id/How-to-make-a-Lightning-Cloud/)
|
||||
A little lightning cloud for fun. [Full Instructable available here.](http://www.instructables.com/id/How-to-make-a-Lightning-Cloud/)
|
||||
|
||||
##V1.1
|
||||
[![Lightning cloud v1.1](http://i.imgur.com/i8TT3HJ.png)](https://www.youtube.com/watch?v=XI98PhaZPTs "Click to see the video")
|
||||
|
||||
Added control via Bluetooth Low Energy module. When you type the letter "f", the lightning "f"lashes.
|
||||
[Instructable for adding BLE control available here.](http://www.instructables.com/id/How-to-Add-Bluetooth-Control-to-your-Lightning-Clo/step6/Test-with-the-Adafruit-BLE-app/)
|
||||
|
||||
To check out v1.1, use the following command:
|
||||
|
||||
$ git checkout -b branch_name v1.1
|
||||
|
||||
##V1.0
|
||||
[![Lightning cloud v1.0](http://i.imgur.com/79LUuV7.png)](https://www.youtube.com/watch?v=XxMMNcU-hWE "Click to see the video")
|
||||
|
||||
The basic lightning animation. Randomly generates flashes. [Full Instructable available here.](http://www.instructables.com/id/How-to-make-a-Lightning-Cloud/)
|
||||
|
||||
To check out v1.0, use the following command:
|
||||
|
||||
$ git checkout -b branch_name v1.0
|
||||
|
|
|
@ -0,0 +1,123 @@
|
|||
// This #include statement was automatically added by the Particle IDE.
|
||||
#include "neopixel/neopixel.h"
|
||||
|
||||
// IMPORTANT: Set pixel COUNT, PIN and TYPE
|
||||
#define PIXEL_COUNT 4
|
||||
#define PIXEL_PIN D0
|
||||
#define PIXEL_TYPE WS2812B
|
||||
|
||||
|
||||
// Parameter 1 = number of pixels in strip
|
||||
// Parameter 2 = pin number (most are valid)
|
||||
// note: if not specified, D2 is selected for you.
|
||||
// Parameter 3 = pixel type [ WS2812, WS2812B, WS2811, TM1803 ]
|
||||
// note: if not specified, WS2812B is selected for you.
|
||||
// note: RGB order is automatically applied to WS2811,
|
||||
// WS2812/WS2812B/TM1803 is GRB order.
|
||||
//
|
||||
// 800 KHz bitstream 800 KHz bitstream (most NeoPixel products ...
|
||||
// ... WS2812 (6-pin part)/WS2812B (4-pin part) )
|
||||
//
|
||||
// 400 KHz bitstream (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
|
||||
// (Radio Shack Tri-Color LED Strip - TM1803 driver
|
||||
// NOTE: RS Tri-Color LED's are grouped in sets of 3)
|
||||
|
||||
Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXEL_COUNT, PIXEL_PIN, PIXEL_TYPE);
|
||||
|
||||
const int HIGH_STRIKE_LIKELIHOOD = 5;
|
||||
const int LOW_STRIKE_LIKELIHOOD = 10;
|
||||
int currentDataPoint = 0;
|
||||
int chance = LOW_STRIKE_LIKELIHOOD;
|
||||
|
||||
// Simple moving average plot
|
||||
int NUM_Y_VALUES = 17;
|
||||
|
||||
float yValues[] = {
|
||||
0,
|
||||
7,
|
||||
10,
|
||||
9,
|
||||
7.1,
|
||||
7.5,
|
||||
7.4,
|
||||
12,
|
||||
15,
|
||||
10,
|
||||
0,
|
||||
3,
|
||||
3.5,
|
||||
4,
|
||||
1,
|
||||
7,
|
||||
1
|
||||
};
|
||||
|
||||
float simple_moving_average_previous = 0;
|
||||
float random_moving_average_previous = 0;
|
||||
|
||||
void setup() {
|
||||
|
||||
strip.begin(); // Sends the start protocol for the LEDs.
|
||||
strip.show(); // Initialize all pixels to 'off'
|
||||
|
||||
Particle.function("lightning", triggerWeather);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
||||
}
|
||||
|
||||
int triggerWeather(String command) {
|
||||
bool strike = false;
|
||||
if (command==String("f")) {
|
||||
strike = true;
|
||||
} else if (random(chance) == 0) {
|
||||
strike = true;
|
||||
}
|
||||
if (strike) {
|
||||
int led = random(PIXEL_COUNT);
|
||||
for (int i = 0; i < 10; i++) {
|
||||
// Use this line to keep the lightning focused in one LED.
|
||||
// lightningStrike(led):
|
||||
// Use this line if you want the lightning to spread out among multiple LEDs.
|
||||
lightningStrike(random(PIXEL_COUNT));
|
||||
}
|
||||
// Once there's been one strike, I make it more likely that there will be a second.
|
||||
chance = HIGH_STRIKE_LIKELIHOOD;
|
||||
} else {
|
||||
chance = LOW_STRIKE_LIKELIHOOD;
|
||||
}
|
||||
turnAllPixelsOff();
|
||||
delay(1000);
|
||||
}
|
||||
|
||||
void turnAllPixelsOff() {
|
||||
for (int i = 0; i < PIXEL_COUNT; i++) {
|
||||
strip.setPixelColor(i, 0);
|
||||
}
|
||||
strip.show();
|
||||
}
|
||||
|
||||
void lightningStrike(int pixel) {
|
||||
float brightness = simple_moving_average();
|
||||
float scaledWhite = abs(brightness*500);
|
||||
|
||||
strip.setPixelColor(pixel, strip.Color(scaledWhite, scaledWhite, scaledWhite));
|
||||
strip.show();
|
||||
delay(random(5, 100));
|
||||
currentDataPoint++;
|
||||
currentDataPoint = currentDataPoint%NUM_Y_VALUES;
|
||||
}
|
||||
|
||||
|
||||
// https://en.wikipedia.org/wiki/Moving_average#Simple_moving_average
|
||||
float simple_moving_average() {
|
||||
uint32_t startingValue = currentDataPoint;
|
||||
uint32_t endingValue = (currentDataPoint+1)%NUM_Y_VALUES;
|
||||
float simple_moving_average_current = simple_moving_average_previous +
|
||||
(yValues[startingValue])/NUM_Y_VALUES -
|
||||
(yValues[endingValue])/NUM_Y_VALUES;
|
||||
|
||||
simple_moving_average_previous = simple_moving_average_current;
|
||||
return simple_moving_average_current;
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
<!-- Replace your-device-ID-goes-here with your actual device ID
|
||||
and replace your-access-token-goes-here with your actual access token-->
|
||||
<!DOCTYPE>
|
||||
<html>
|
||||
<body>
|
||||
<center>
|
||||
<br>
|
||||
<br>
|
||||
<br>
|
||||
<form action="https://api.particle.io/v1/devices/400021000747343337373738/lightning?access_token=5b3dd71af422f403693b305955cd765de6680700" method="POST">
|
||||
Tell your device what to do!<br>
|
||||
<br>
|
||||
<input type="radio" name="args" value="f">Trigger lightning.
|
||||
<br>
|
||||
<input type="radio" name="args" value="g">Trigger nothing.
|
||||
<br>
|
||||
<br>
|
||||
<input type="submit" value="Do it!">
|
||||
</form>
|
||||
</center>
|
||||
</body>
|
||||
</html>
|
|
@ -89,8 +89,14 @@ void setup() {
|
|||
}
|
||||
|
||||
void loop() {
|
||||
bool strike = false;
|
||||
String trigger = readFromBluetooth();
|
||||
if (trigger==String("f")) {
|
||||
strike = true;
|
||||
} else if (random(chance) == 0) {
|
||||
strike = true;
|
||||
}
|
||||
if (strike) {
|
||||
int led = random(NUM_LEDS);
|
||||
for (int i = 0; i < 10; i++) {
|
||||
// Use this line to keep the lightning focused in one LED.
|
||||
|
|
Loading…
Reference in New Issue