#I need to simulate lightning flashes

1 messages · Page 1 of 1 (latest)

solemn verge
#

Taking that example:

void flash() {
digitalWrite(mosfetPin, HIGH);
delay(410);
digitalWrite(mosfetPin, LOW);
delay(250);
digitalWrite(mosfetPin, HIGH);
delay(337);
digitalWrite(mosfetPin, LOW);
delay(678);
digitalWrite(mosfetPin, HIGH);
delay(635);
digitalWrite(mosfetPin, LOW);
}

#

switching it into variables:

instructions[0] = 6; // 6 on or off instructions
instructions[1] = 410; // on
instructions[2] = 250; // off
instructions[3] = 337; // on
instructions[4] = 678; // off
instructions[5] = 635; // on
instructions[6] = 0; // off

void flash(instructions) {

for (int i = 1; i <= instructions[0]; i = i + 2) {

digitalWrite(mosfetPin, HIGH);
delay(instructions[i]); // instructions in element 1, 3, and 5
digitalWrite(mosfetPin, LOW);
delay(instructions[i+1]); // instructions in element 2, 4, and 6

}

}

#

The problem I end up with is the 32 byte limit of the NRF payload and 27 (if I remember) with the el-cheapo 315/433mhz ASK radios ...

#

In the end this would be a one-to-many control where individual nanos are connected in each window of a haunted house, hence my need for a inexpensive wireless method

faint arch
#

A quick fix would be to use int16_t for your array, so only 2 bytes per entry.

#

Or you could even drop down to 1 byte, if you sent the number as multiples of 10ms or something like that, losing some imperceptible timing resolution.

solemn verge
#

x10 is definitely doable, since everything is a random number between 150 and 500, reducing it to 15-50 is no problem

#

so something like:

struct SEND_DATA {
int16_t addr;
int16_t strikes;
int16_t on1;
int16_t off1;
int16_t on2;
int16_t off2;
int16_t on3;
int16_t off3;
int16_t on4;
int16_t off4;
int16_t on5;
int16_t off5;
};

#

?

faint arch
#

Yep, or you could use int16_t onoff[10]; for the values if you wanted to loop-index it easier.

solemn verge
#

hmm.. ok.. i'm looking at the radiohead library examples..

#

ok, I think i've got it, but my fingers are freeezing... gotta wait for the heater to kick in before I try and do more here. thanks for your help! 😄

faint arch
#

Hahaha, time to get your PC calculating the digits of pi and warm up the keyboard from the CPU.