Hello I have a Arduino Nano. In my code is a designation for flashes for lightning. The problem Im having is the speed of the flash. Its basically like a strobe light. It would be nice if each flash gradually came on went off and a new flash started. Below is my code. Is the any way that I can change how fast a flash comes on and goes back off gradually. I know how to change how long each flash lasts and changes to a new flash but would prefer each flash to gradually light up instead of strobing. Thanks for any help.
Code:
[color=#555555]#include "Arduino.h"
#include "SoftwareSerial.h"
#include "DFRobotDFPlayerMini.h"
int ledPin = 9; // LEDs (via MOSFET) connected to pin 9
int rxPin = 10; // DFplayer RX to Arduino pin 10
int txPin = 11; // DFplayer TX toArduinopin 11
int busyPin = 12; // DFplayer BUSY connected to pin 12
SoftwareSerial mySoftwareSerial(rxPin, txPin);
DFRobotDFPlayerMini myDFPlayer;
void setup()
{
pinMode(ledPin, OUTPUT);
pinMode(busyPin, INPUT);
mySoftwareSerial.begin(9600);
Serial.begin(115200);
Serial.println(F("Initializing DFPlayer..."));
if (!myDFPlayer.begin(mySoftwareSerial)) { //Use softwareSerial to communicate with mp3.
Serial.println(F("Unable to begin. Check connection and SD card, or reset the Arduino."));
while (true);
}
Serial.println(F("DFPlayer Mini online."));
myDFPlayer.setTimeOut(500); // Set serial communictaion time out 500ms
myDFPlayer.volume(30); // Set volume value (0~30).
myDFPlayer.EQ(DFPLAYER_EQ_BASS); // Set EQ to BASS (normal/pop/rock/jazz/classic/bass)
myDFPlayer.outputDevice(DFPLAYER_DEVICE_SD); // Set device we use SD as default
myDFPlayer.enableDAC(); // Enable On-chip DAC
}
void loop()
{
int flashCount = random (3, 15); // Min. and max. number of flashes each loop
int flashBrightnessMin = 10; // LED flash min. brightness (0-255)
int flashBrightnessMax = 255; // LED flash max. brightness (0-255)
int flashDurationMin = 1; // Min. duration of each seperate flash
int flashDurationMax = 50; // Max. duration of each seperate flash
int nextFlashDelayMin = 1; // Min, delay between each flash and the next
int nextFlashDelayMax = 150; // Max, delay between each flash and the next
int thunderDelay = random (500, 3000); // Min. and max. delay between flashing and playing sound
int thunderFile = random (1, 17); // There are 17 soundfiles: 0001.mp3 ... 0017.mp3
int loopDelay = random (5000, 30000); // Min. and max. delay between each loop
Serial.println();
Serial.print(F("Flashing, count: "));
Serial.println( flashCount );
for (int flash = 0 ; flash <= flashCount; flash += 1) { // Flashing LED strip in a loop, random count
analogWrite(ledPin, random (flashBrightnessMin, flashBrightnessMax)); // Turn LED strip on, random brightness
delay(random(flashDurationMin, flashDurationMax)); // Keep it tured on, random duration
analogWrite(ledPin, 0); // Turn the LED strip off
delay(random(nextFlashDelayMin, nextFlashDelayMax)); // Random delay before next flash
}
Serial.print(F("Pausing before playing thunder sound, milliseconds: "));
Serial.println(thunderDelay);
delay(thunderDelay);
Serial.print(F("Playing thunder sound, file number: "));
Serial.println(thunderFile);
myDFPlayer.playMp3Folder(thunderFile);
delay(1000); // Give the DFPlayer some time
while (digitalRead(busyPin) == LOW) { // Wait for the DFPlayer to finish playing the MP3 file
}
Serial.print(F("Pausing before next loop, milliseconds: "));
Serial.println(loopDelay);
delay(loopDelay);
}[/color]