Skip to content

Instantly share code, notes, and snippets.

@abhikpal
Last active October 13, 2016 11:51
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 abhikpal/cd26be4b694894c3f1317ab26e7a1957 to your computer and use it in GitHub Desktop.
Save abhikpal/cd26be4b694894c3f1317ab26e7a1957 to your computer and use it in GitHub Desktop.
//
// PIN MAPPINGS
//
const int num_relays = 8;
const int relays[] = {2, 3, 4, 5, 6, 7, 8, 9};
const int input_pin = A0;
const int input_threshold = 50;
//
// DURATIONS
//
const float scale_factor = 1.5;
const int crack_delay_min = 10 * scale_factor;
const int crack_delay_max = 100 * scale_factor;
const int rolling_delay_min = 10 * scale_factor;
const int rolling_delay_max = 100 * scale_factor;
const int thunderburst_duration_min = 75 * scale_factor;
const int thunderburst_duration_max = 150 * scale_factor;
//
// TRIGGER PROBABILITIES
//
const int rolling_trigger_probability = 10;
//
// LOOP CONTROLLERS.
// ranges for the number of times we crack, roll, etc.
//
const int rolling_num_rolls_min = 2;
const int rolling_num_rolls_max = 10;
const int thunderburst_flash_num_min = 2;
const int thunderburst_flash_num_max = 4;
void setup() {
for(int i = 0; i < num_relays; i++) {
pinMode(relays[i], OUTPUT);
}
reset();
}
void loop() {
int lightning_mode;
int do_shit = 1;
if(analogRead(input_pin) > input_threshold) {
do_shit = 1;
} else {
do_shit = 0;
}
if (do_shit == 1) {
for(int k = 0; k < 15; k++) {
lightning_mode = random(3);
switch (lightning_mode) {
case 0:
crack();
break;
case 1:
rolling();
break;
case 2:
thunderburst();
break;
default:
reset();
}
}
reset();
}
else {
for(int i = 0; i <num_relays; i++) {
digitalWrite(relays[i], LOW);
}
}
}
void crack() {
for(int i = 0; i < num_relays; i++) {
digitalWrite(relays[i], LOW);
delay(random(crack_delay_min, crack_delay_max));
digitalWrite(relays[i], HIGH);
delay(random(crack_delay_min, crack_delay_max));
}
}
void rolling() {
int loop_times = random(rolling_num_rolls_min, rolling_num_rolls_max);
for(int t = 0; t < loop_times; t++) {
for(int i = 0; i < num_relays; i++) {
int probability = random(100);
if(probability < rolling_trigger_probability) {
digitalWrite(relays[i], LOW);
delay(random(rolling_delay_min, rolling_delay_max));
digitalWrite(relays[i], HIGH);
}
}
}
}
void thunderburst() {
int first_cloud_section = random(num_relays);
int second_cloud_section = random(num_relays);
if(first_cloud_section == second_cloud_section) {
thunderburst();
}
int thunderburst_flashes = random(thunderburst_flash_num_min, thunderburst_flash_num_max);
for(int i = 0; i < thunderburst_flashes; i++) {
digitalWrite(relays[first_cloud_section], LOW);
digitalWrite(relays[second_cloud_section], HIGH);
delay(random(thunderburst_duration_min, thunderburst_duration_max));
digitalWrite(relays[first_cloud_section], HIGH);
digitalWrite(relays[second_cloud_section], LOW);
delay(random(thunderburst_duration_min, thunderburst_duration_max));
}
delay(random(thunderburst_duration_min));
}
void simple_default() {
reset();
int pins[] = {0, 0, 0, 0, 0, 0, 0, 0};
for(int i = 0; i < num_relays; i++) {
pins[i] = random(0, num_relays);
}
for(int i = 0; i < num_relays; i += 2) {
digitalWrite(relays[pins[i]], LOW);
digitalWrite(relays[pins[i+1]], LOW);
delay(random(400));
}
}
void reset() {
for(int i = 0; i < num_relays; i++) {
digitalWrite(relays[i], HIGH);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment