Page 1 of 1
Forum

Welcome to the Tweaking4All community forums!
When participating, please keep the Forum Rules in mind!

Topics for particular software or systems: Start your topic link with the name of the application or system.
For example “MacOS X – Your question“, or “MS Word – Your Tip or Trick“.

Please note that switching to another language when reading a post will not work!





Lightning Effect
 
Share:
Notifications
Clear all

Lightning Effect  

  RSS

Hans
 Hans
(@hans)
Prominent Member Admin
Joined: 7 years ago
Posts: 822
January 12, 2017 3:02 AM  

This topic continues a conversation from the Led Effects article ... (link)

Original post:

Hi, Hans,

You helped me a few years ago with a sketch and now I’m back for more. . I’m making a cloud lamp and I’d like to have a lightning effect inside. I have an Arduino Mega and a short strip of WS2812B NeoPixels. I want the effect to be random, like real lightning. For example, three quick flashes, dark for several seconds, then a slower flash fading up; that kind of thing. I thought I could edit the strobe sketch or the Halloween eyes, but I don’t understand how to use the random function. Would love some help! 

Thanks,

Claire


ReplyQuote
Hans
 Hans
(@hans)
Prominent Member Admin
Joined: 7 years ago
Posts: 822
January 12, 2017 3:06 AM  

I assumed you are using the FastLED variant, so here the modified Strobe code (untested, since I have no hardware laying around at the moment to test this):

#include "FastLED.h"
#define NUM_LEDS 60 
CRGB leds[NUM_LEDS];
#define PIN 6 
byte red = 0xff;
byte green = 0xff;
byte blue = 0xff;
int numberOfFlashes;
int delayBetweenFlashes;
int pauseAfterEffect; 
void setup()
{
  FastLED.addLeds<WS2811, PIN, GRB>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
  randomSeed(analogRead(0));
}
// *** REPLACE FROM HERE ***
void loop() { 
  numberOfFlashes=random(10); // random number between 0 and 10
  delayBetweenFlashes=random(100); // random number between 0 and 100
  pauseAfterEffect=random(1000); // random number between 0 and 1000
  Strobe(red, green, blue, numberOfFlashes, delayBetweenFlashes, pauseAfterEffect);
}
void Strobe(byte red, byte green, byte blue, int StrobeCount, int FlashDelay, int EndPause){
  for(int j = 0; j < StrobeCount; j++) {
    setAll(red,green,blue);
    showStrip();
    delay(FlashDelay);
    setAll(0,0,0);
    showStrip();
    delay(FlashDelay);
  }
 
 delay(EndPause);
}
// *** REPLACE TO HERE ***
void showStrip() {
 #ifdef ADAFRUIT_NEOPIXEL_H 
   // NeoPixel
   strip.show();
 #endif
 #ifndef ADAFRUIT_NEOPIXEL_H
   // FastLED
   FastLED.show();
 #endif
}
void setPixel(int Pixel, byte red, byte green, byte blue) {
 #ifdef ADAFRUIT_NEOPIXEL_H 
   // NeoPixel
   strip.setPixelColor(Pixel, strip.Color(red, green, blue));
 #endif
 #ifndef ADAFRUIT_NEOPIXEL_H 
   // FastLED
   leds[Pixel].r = red;
   leds[Pixel].g = green;
   leds[Pixel].b = blue;
 #endif
}
void setAll(byte red, byte green, byte blue) {
  for(int i = 0; i < NUM_LEDS; i++ ) {
    setPixel(i, red, green, blue); 
  }
  showStrip();
}

Give it a try and let me know how this worked out so we can continue from there ... 


ReplyQuote
gbonsack
(@gbonsack)
New Member
Joined: 3 years ago
Posts: 4
January 21, 2017 8:18 AM  

What I want to do is press a number, on a 3 X 4 keypad and have the sketch run a 35 second light show loop (I do light painting, so I start the show and start walking, while the photographers take a 30 second exposure.

When I compile this sketch, I get an error message for line 141 and 3 more for line 201:

Error message given for line 141: 'theaterChase' was not declared in this scope

Error messages given for line 201: expected unqualified-id before 'for'

for (int j = 0; j < 15; j++) { //do 10 cycles of chasing, changed to 15 for length

error: 'j' does not name a type & error: 'j' does not name a type

I have re-typed several line before and after said line, without any success, any suggestion other than trash Windows 10 and switch to Linux or get a MAC.


ReplyQuote
gbonsack
(@gbonsack)
New Member
Joined: 3 years ago
Posts: 4
January 23, 2017 4:30 AM  

The above keypad_test .ino is a version of my modified Button_Cycler_Mine.ino, which works great, but if I want loop (case) 5, I do not want to run the previous 4, just to run 5 and then power down and repeat for a second shot.


ReplyQuote
Hans
 Hans
(@hans)
Prominent Member Admin
Joined: 7 years ago
Posts: 822
January 24, 2017 5:32 AM  

Since the Arduino fully resets after a power loss, and since the Arduino isn't the greatest when it comes to multi tasking, you might want to consider using a multi-position switch or a rotary selector switch. They can be found in several different shapes ... from rotating to sliding, small, big, multi layer etc.

In your case you'd need only 5 or 6 positions, single layer ... position 6 could be "OFF" for example.
The advantage would be that the last used position is remembered (unless you change the position of the switch of course).

You can choose to use 5 pins or make a more complex setup by using an analog pin and connecting a different resistor per pin. That last solution obviously makes things a little more complicated, but will spare you the use of pins if you would need pins for other purposes.

There are other more advanced methods of course, by using an IC to handling things (see this Arduino Forum topic).


ReplyQuote



gbonsack
(@gbonsack)
New Member
Joined: 3 years ago
Posts: 4
January 29, 2017 9:49 AM  

Hans,

I found the issue with my keypad sketch, when I re-typed one of the 240/302 code lines, I corrected the 240/302 error but accidentally added another letter to the code line - resulting in the "Not Declared" error 50 to 60 lines above that line - "FAT FINGERS".

At the moment, I am 3D Printing parts for the keypad holder, battery pack, Arduino holder and light stick spinner. I should have everything complete and wired together within a couple of day, so I can post a link to a sample video and/or a sample image. Revised code is attached.

Like I said above, the push button (button_cycler_mine.ino) advance sketch worked, but the keypad sketch was full of error message (cut and paste, using our favorite OS).


ReplyQuote
Hans
 Hans
(@hans)
Prominent Member Admin
Joined: 7 years ago
Posts: 822
January 29, 2017 3:44 PM  

Oh wow, nice! I played with 3D printers for a while, but have to admit that it's not ready for use by me yet hahah ...
Too much work and tweaking to get "normal" printing going and no budget for the more expensive ones. 

I'm sorry for not being so much present the past days - work and hobby are seriously beginning to conflict.
One of these days hahah ... I love this stuff more than my job though ... can't wait to see your 3D print!
I'll try to find some time this week to go through your code.


ReplyQuote
gbonsack
(@gbonsack)
New Member
Joined: 3 years ago
Posts: 4
February 5, 2017 6:04 AM  

Here is the working code. I put the YouTube link on the main page.


ReplyQuote
Hans
 Hans
(@hans)
Prominent Member Admin
Joined: 7 years ago
Posts: 822
February 5, 2017 6:21 AM  

Awesome! 
But couldn't find the link on the main page?


ReplyQuote
claire
(@claire)
New Member
Joined: 3 years ago
Posts: 0
February 11, 2017 11:48 AM  

Hi, Hans,
I seem to be back on now. Refreshing the page helps. I tried the sketch and got a lot of error messages. 
  This report would have more information with
  "Show verbose output during compilation"
  enabled in File > Preferences.
Arduino: 1.0.6 (Mac OS X), Board: "Arduino Mega 2560 or Mega ADK"
/Users/claire/Documents/Arduino/libraries/FastLED-3.1.3/platforms/avr/clockless_trinket.h: In member function 'void ClocklessController<DATA_PIN, T1, T2, T3, RGB_ORDER, XTRA0, FLIP, WAIT_TIME>::showPixels(PixelController<RGB_ORDER, 1, -1ul>&) [with unsigned char DATA_PIN = 6u, int T1 = 6, int T2 = 8, int T3 = 6, EOrder RGB_ORDER = GRB, int XTRA0 = 0, bool FLIP = false, int WAIT_TIME = 10]':
/Users/claire/Documents/Arduino/libraries/FastLED-3.1.3/platforms/avr/clockless_trinket.h:368: error: can't find a register in class 'POINTER_REGS' while reloading 'asm'
/Users/claire/Documents/Arduino/libraries/FastLED-3.1.3/platforms/avr/clockless_trinket.h:368: error: can't find a ...

register in class 'POINTER_REGS' while reloading 'asm'
/Users/claire/Documents/Arduino/libraries/FastLED-3.1.3/platforms/avr/clockless_trinket.h:368: error: 'asm' operand has impossible constraints
/Users/claire/Documents/Arduino/libraries/FastLED-3.1.3/platforms/avr/clockless_trinket.h:368: error: 'asm' operand has impossible constraints
/Users/claire/Documents/Arduino/libraries/FastLED-3.1.3/platforms/avr/clockless_trinket.h:369: error: 'asm' operand has impossible constraints
/Users/claire/Documents/Arduino/libraries/FastLED-3.1.3/platforms/avr/clockless_trinket.h:369: error: 'asm' operand has impossible constraints
...
/Users/claire/Documents/Arduino/libraries/FastLED-3.1.3/platforms/avr/clockless_trinket.h:449: error: 'asm' operand has impossible constraints

ReplyQuote



Hans
 Hans
(@hans)
Prominent Member Admin
Joined: 7 years ago
Posts: 822
February 12, 2017 9:41 AM  

Hi Claire,

that seems to be a problem with the FastLED library.

Since I have never seen these errors, maybe you'd want to consider reinstalling everything;

1) download the latest Arduino IDE version,
2) Download and install the latest FastLED library.

I think it's the Arduino application that you're using that is very old. 


ReplyQuote
wison
(@wison)
New Member
Joined: 2 years ago
Posts: 0
January 5, 2018 3:21 AM  

Hi Hans, 

I can't find in libraries   <Patterns.h> <Key.h> have any link to download?

Thank you!


ReplyQuote
1234abcd
(@1234abcd)
New Member
Joined: 2 years ago
Posts: 0
October 3, 2018 11:21 PM  

Great and easily customisable lightning effect from Andrew Tuline, awesome in a tree with 10 or more APA102C strips...

/*
 * 
 * Lightning (Andrew Tuline)




 * 
 */

#include "FastLED.h" // FastLED library. Please use the latest version

// Fixed definitions. Cannot be changed interactively
#define LED_DATA 3 // Data pin
#define LED_CLOCK 4 // Clock pin
#define COLOR_ORDER BGR // GRB for WS2812 and BGR for APA102
#define LED_TYPE APA102 // Using APA102, WS2812, WS2801 - don't forget to change LEDS.addLeds
#define NUM_LEDS 144 // Number of LEDs

// Global variables. Can be changed interactively
uint8_t max_bright = 255; // Overall brightness

struct CRGB leds[NUM_LEDS]; // Initialise LED array

uint8_t frequency = 40; // Controls the interval between strikes
uint8_t flashes = 7; // The upper limit of flashes per strike
unsigned int dimmer = 1;
uint8_t ledstart; // Starting location of flash
uint8_t ledlen; // Length of flash

void setup() {
  
  delay(1000);
  
  LEDS.addLeds<LED_TYPE, LED_DATA, LED_CLOCK, COLOR_ORDER>(leds, NUM_LEDS); // For WS2801 or APA102
  
  FastLED.setBrightness(max_bright);
  
}

void loop() {
  
  ledstart = random8(NUM_LEDS); // Determine starting location of flash
  ledlen = random8(NUM_LEDS-ledstart); // Determine length of flash (not to go beyond NUM_LEDS-1)
  
  for (int flashCounter = 0; flashCounter < random8(2,flashes); flashCounter++) {
    if(flashCounter == 0) dimmer = 6; // The brightness of the leader is scaled down by a factor of 6
    else dimmer = random8(1,4); // Return strokes are brighter than the leader
    
    fill_solid(leds+ledstart,ledlen,CHSV(255, 0, 255/dimmer));
    FastLED.show(); // Show a flash
    delay(random8(3,11)); // Each flash only lasts 3-11 milliseconds
    
    fill_solid(leds+ledstart,ledlen,CHSV(255,0,0)); // Clear the section of LEDs
    FastLED.show();
    
    if (flashCounter == 0) delay (150); // Longer delay until next flash after the leader
    
    delay(50+random8(100)); // Shorter delay between strokes
    
  }
  
  delay(random8(frequency)*100); // Delay between strikes
  
}

ReplyQuote
Hans
 Hans
(@hans)
Prominent Member Admin
Joined: 7 years ago
Posts: 822
October 5, 2018 11:14 PM  

Awesome! 


ReplyQuote
Share: