Compare commits

...

9 Commits
v1.0 ... master

Author SHA1 Message Date
Neale Pickett 9ea79f756a Figured out what author was going for from a gist 2018-08-05 20:55:04 +00:00
Neale Pickett c41f6ddcc0 chance variable matters now 2018-08-05 20:42:25 +00:00
Molly Nicholas fde662bbee Add code to control lightning from browser. 2015-12-13 09:46:15 -08:00
Molly Nicholas be1a659413 Merge branch 'master' of github.com:molecule/cloud-lightning 2015-12-13 09:37:16 -08:00
Molly Nicholas 7c154f79b7 Add version for the Particle Photon 2015-12-13 09:36:59 -08:00
molecule e8e59dde86 Update README.md 2015-11-14 10:00:27 -08:00
Molly Nicholas 586415a57a Merge branch 'master' of github.com:molecule/cloud-lightning 2015-11-14 08:03:48 -08:00
Molly Nicholas 32e6fb47f4 Control lightning from BLE module 2015-11-14 08:03:18 -08:00
molecule 402723b901 Update README.md 2015-11-07 17:51:10 -08:00
4 changed files with 194 additions and 3 deletions

View File

@ -2,7 +2,26 @@
[![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
##Early prototypes:

View File

@ -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;
}

View File

@ -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>

View File

@ -37,7 +37,7 @@
// NEO_GRB Pixels are wired for GRB bitstream
// NEO_KHZ400 400 KHz bitstream (e.g. FLORA pixels)
// NEO_KHZ800 800 KHz bitstream (e.g. High Density LED strip)
int NUM_LEDS = 5;
int NUM_LEDS = 4;
int LED_PIN = 4;
Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUM_LEDS, LED_PIN, NEO_GRB + NEO_KHZ800);
@ -76,6 +76,8 @@ float (*functionPtrs[10])(); //the array of function pointers
int NUM_FUNCTIONS = 2;
void setup() {
// Setup the Serial connection to talk over Bluetooth
Serial.begin(9600);
// Neopixel setup
strip.begin();
@ -87,7 +89,14 @@ void setup() {
}
void loop() {
if (random(chance) == 3) {
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.
@ -122,6 +131,24 @@ void lightningStrike(int pixel) {
currentDataPoint = currentDataPoint%NUM_Y_VALUES;
}
/**
* Read the data from the BLE, breaking on '\n' and '\r' characters.
*/
String readFromBluetooth() {
String readString = "";
while (Serial.available()) {
delay(10); //small delay to allow input buffer to fill
char c = Serial.read(); //gets one byte from serial buffer
if (c == '\n' || c == '\r') {
break;
}
readString += c;
}
return readString;
}
float callFunction(int index) {
return (*functionPtrs[index])(); //calls the function at the index of `index` in the array
}