Go Down

Topic: Flash and Fade (Read 1 time) previous topic - next topic

BulldogLowell

at this point, he may be better to go back to pseudo code:

it looks like you may want to fade up/down when your analog pin returns greater than 630, yes?

it looks also like you want to turn on a 2nd LED all the time but then only for a finite interval of time once the analog pin returns  less than 630, yes?

it also looks like you want all of the LEDs off when the analog pin returns full voltage, or 1023, yes?

edgaryo


at this point, he may be better to go back to pseudo code:

it looks like you may want to fade up/down when your analog pin returns greater than 630, yes?

it looks also like you want to turn on a 2nd LED all the time but then only for a finite interval of time once the analog pin returns  less than 630, yes?

it also looks like you want all of the LEDs off when the analog pin returns full voltage, or 1023, yes?


yes the value of sensor is > 630 then all leds is off
when sensor value is < 630 , first led is flash , and another led is fadeing . But ONE TIME . After the loop is repet

edgaryo

#17
Jul 17, 2014, 11:51 pm Last Edit: Jul 17, 2014, 11:54 pm by edgaryo Reason: 1
And the first led is important to stay on 100 ms ( only flash , like a camera flash )

BulldogLowell


And the first led is important to stay on 100 ms ( only flash , like a camera flash )


OK, then look at this:

Code: [Select]

byte ledPin = 13; // This led is flash
int led = 9;           // this led is fadeing
int brightness = 0;    // how bright the LED is
int fadeAmount = 5;    // how many points to fade the LED by
int turnLedOffAfterTime = 100;

void setup()
{
  pinMode( ledPin, OUTPUT );
}

void loop()
{
  if ( analogRead( A0 ) < 630)
  {
    flashLedPinOnce();
    fadePinNine();
  }
  else
  {
    allPinsOff();
  }
}

void flashLedPinOnce()
{
 
}

void fadePinNine()
{
 
}

void allPinsOff()
{
 
}


we are going to build off of this.  Does it look OK?  Do we need to add a condition regarding the high pin reading of A0?



edgaryo



And the first led is important to stay on 100 ms ( only flash , like a camera flash )


OK, then look at this:

Code: [Select]

byte ledPin = 13; // This led is flash
int led = 9;           // this led is fadeing
int brightness = 0;    // how bright the LED is
int fadeAmount = 5;    // how many points to fade the LED by
int turnLedOffAfterTime = 100;

void setup()
{
  pinMode( ledPin, OUTPUT );
}

void loop()
{
  if ( analogRead( A0 ) < 630)
  {
    flashLedPinOnce();
    fadePinNine();
  }
  else
  {
    allPinsOff();
  }
}

void flashLedPinOnce()
{
 
}

void fadePinNine()
{
 
}

void allPinsOff()
{
 
}


we are going to build off of this.  Does it look OK?  Do we need to add a condition regarding the high pin reading of A0?





is very ok ! This is all wath i need :D .

BulldogLowell

OK, we will fade the pin in this example...

look at what we did here. and try it.  It should fade your led (but not flash ledPin yet) and stop when your value of A0 gets higher than your magic number 630.

Code: [Select]
byte ledPin = 13; // This led is flash
int led = 9;           // this led is fadeing
int brightness = 0;    // how bright the LED is
int fadeAmount = 5;    // how many points to fade the LED by
int turnLedOffAfterTime = 100;

void setup()
{
  pinMode( ledPin, OUTPUT );
}

void loop()
{
  if ( analogRead(A0) < 630)
  {
    flashLedPinOnce();
    fadePinNine();
  }
  else
  {
    allPinsOff();
  }
}

void flashLedPinOnce()
{
 
}

void fadePinNine()
{
  brightness = brightness + fadeAmount;
  analogWrite(led, brightness);
  if (brightness == 0 || brightness == 255);
  fadeAmount = -fadeAmount ;
}

void allPinsOff()
{
  digitalWrite(led, LOW);
}

edgaryo

is fadeing but is in a loop , and is not stop . . .  i need to stop , to fade one time . Then i active another date sensor , led is fade another time . . .  is like flash , but is not flashing is fade . . .   Just one time, and is repet after i active the sensor , not how long is active sensor .

BulldogLowell

#22
Jul 18, 2014, 12:39 am Last Edit: Jul 18, 2014, 12:41 am by BulldogLowell Reason: 1
OOPS, had to edit...

OK,

Look at this and look at the Flash only, is this what you want?

look at what we did, we added a timer to the flash...

Code: [Select]
byte ledPin = 13; // This led is flash
int led = 9;           // this led is fadeing
int brightness = 0;    // how bright the LED is
int fadeAmount = 5;    // how many points to fade the LED by
unsigned long turnLedOffAfterTime = 100UL;
unsigned long startTime;
boolean readyToFlash = true;
void setup()
{
  pinMode( ledPin, OUTPUT );
}

void loop()
{
  if ( analogRead(A0) < 630)
  {
    if (readyToFlash)
    {
      startTime = millis();
      flashLedPinOnce();
    }
    fadePinNine();
  }
  else
  {
    allPinsOff();
    readyToFlash = true;
  }
}

void flashLedPinOnce()
{
  digitalWrite(ledPin, HIGH);
  if (millis() - startTime >= turnLedOffAfterTime)
  {
    digitalWrite(ledPin, LOW);
    readyToFlash = false;
  }
}

void fadePinNine()
{
  brightness = brightness + fadeAmount;
  analogWrite(led, brightness);
  if (brightness == 0 || brightness == 255);
  fadeAmount = -fadeAmount ;
}

void allPinsOff()
{
  digitalWrite(ledPin, LOW);
  digitalWrite(led, LOW);
}


we can make the fade once too... check this first!

edgaryo

now the flas is not work wery good , because the led is not flash with all his intensity  ( just some time is flash with all intensity ).

BulldogLowell

yeah, sorry.

Try this for flashing:

Code: [Select]
byte ledPin = 13; // This led is flash
int led = 9;           // this led is fadeing
int brightness = 0;    // how bright the LED is
int fadeAmount = 5;    // how many points to fade the LED by
unsigned long turnLedOffAfterTime = 100UL;
unsigned long startTime;
boolean readyToFlash = true;
boolean flashing = false;
void setup()
{
  pinMode( ledPin, OUTPUT );
}

void loop()
{
  if ( analogRead(A0) < 630)
  {
    if (readyToFlash)
    {
      if (flashing = false) startTime = millis();
      flashLedPinOnce();
    }
    fadePinNine();
  }
  else
  {
    allPinsOff();
    readyToFlash = true;
  }
}

void flashLedPinOnce()
{
  flashing = true;
  digitalWrite(ledPin, HIGH);
  if (millis() - startTime >= turnLedOffAfterTime)
  {
    digitalWrite(ledPin, LOW);
    readyToFlash = false;
    flashing = false;
  }
}

void fadePinNine()
{
  brightness = brightness + fadeAmount;
  analogWrite(led, brightness);
  if (brightness == 0 || brightness == 255);
  fadeAmount = -fadeAmount ;
}

void allPinsOff()
{
  digitalWrite(ledPin, LOW);
  digitalWrite(led, LOW);
}

edgaryo

no , is not working , is have only 30 % from his intensity

BulldogLowell

Quote
no , is not working , is have only 30 % from his intensity


Are you talking flash led or fade led?

forget about the fade for now, but i fixed that line too.
does the led blink only once when the sensor is below 630?

Code: [Select]
byte ledPin = 13; // This led is flash
int led = 9;           // this led is fadeing
int brightness = 0;    // how bright the LED is
int fadeAmount = 5;    // how many points to fade the LED by
unsigned long turnLedOffAfterTime = 100UL;
unsigned long startTime;
boolean readyToFlash = true;
boolean flashing = false;
void setup()
{
  pinMode( ledPin, OUTPUT );
}

void loop()
{
  if ( analogRead(A0) < 630)
  {
    if (readyToFlash)
    {
      if (flashing = false) startTime = millis();
      flashLedPinOnce();
    }
    fadePinNine();
  }
  else
  {
    allPinsOff();
    readyToFlash = true;
  }
}

void flashLedPinOnce()
{
  flashing = true;
  digitalWrite(ledPin, HIGH);
  if (millis() - startTime >= turnLedOffAfterTime)
  {
    digitalWrite(ledPin, LOW);
    readyToFlash = false;
    flashing = false;
  }
}

void fadePinNine()
{
  brightness = brightness + fadeAmount;
  analogWrite(led, brightness);
  if (brightness == 0 || brightness == 255) fadeAmount = (-fadeAmount);
}

void allPinsOff()
{
  digitalWrite(ledPin, LOW);
  digitalWrite(led, LOW);
}

edgaryo

yes i say about the FLASHING LED :( ... if you want i can make you a video to see :| ....

edgaryo

is work but intensity is the problem :(

BulldogLowell

#29
Jul 18, 2014, 01:08 am Last Edit: Jul 18, 2014, 01:22 am by BulldogLowell Reason: 1

is work but intensity is the problem :(

yes i say about the FLASHING LED :( ... if you want i can make you a video to see :| ....


well... we will look when we are done with fade.

See if this fades your LED right, once up and down...

Code: [Select]
byte ledPin = 13; // This led is flash
int led = 9;           // this led is fadeing
int brightness = 0;    // how bright the LED is
int fadeAmount = 5;    // how many points to fade the LED by
unsigned long turnLedOffAfterTime = 100UL;
unsigned long startTime;
boolean readyToFlash = true;
boolean flashing = false;
boolean fadeOn;
void setup()
{
 pinMode( ledPin, OUTPUT );
}

void loop()
{
 if ( analogRead(A0) < 630)
 {
   if (readyToFlash)
   {
     if (flashing = false) startTime = millis();
     flashLedPinOnce();
   }
   if (fadeOn == true) fadePinNine();
 }
 else
 {
   allPinsOff();
   readyToFlash = true;
   fadeOn = true;
 }
}

void flashLedPinOnce()
{
 flashing = true;
 digitalWrite(ledPin, HIGH);
 if (millis() - startTime >= turnLedOffAfterTime)
 {
   digitalWrite(ledPin, LOW);
   readyToFlash = false;
   flashing = false;
 }
}

void fadePinNine()
{
 brightness = brightness + fadeAmount;
 analogWrite(led, brightness);
 if (brightness == 0 || brightness == 255) fadeAmount = (-fadeAmount);
 if (brightness == 0)  fadeOn = false;
}

void allPinsOff()
{
 digitalWrite(ledPin, LOW);
 digitalWrite(led, LOW);
}

Go Up