Go Down

### Topic: Flash and Fade (Read 7396 times)previous topic - next topic

#### BulldogLowell

#15
##### Jul 17, 2014, 11:42 pm
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

#16
##### Jul 17, 2014, 11:50 pm

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 pmLast 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

#18
##### Jul 18, 2014, 12:22 am

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 flashint led = 9;           // this led is fadeingint brightness = 0;    // how bright the LED isint fadeAmount = 5;    // how many points to fade the LED byint 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

#19
##### Jul 18, 2014, 12:26 am

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 flashint led = 9;           // this led is fadeingint brightness = 0;    // how bright the LED isint fadeAmount = 5;    // how many points to fade the LED byint 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 .

#### BulldogLowell

#20
##### Jul 18, 2014, 12:30 am
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 flashint led = 9;           // this led is fadeingint brightness = 0;    // how bright the LED isint fadeAmount = 5;    // how many points to fade the LED byint 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

#21
##### Jul 18, 2014, 12:38 am
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 amLast Edit: Jul 18, 2014, 12:41 am by BulldogLowell Reason: 1

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 flashint led = 9;           // this led is fadeingint brightness = 0;    // how bright the LED isint fadeAmount = 5;    // how many points to fade the LED byunsigned 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

#23
##### Jul 18, 2014, 12:44 am
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

#24
##### Jul 18, 2014, 12:51 am
yeah, sorry.

Try this for flashing:

Code: [Select]
`byte ledPin = 13; // This led is flashint led = 9;           // this led is fadeingint brightness = 0;    // how bright the LED isint fadeAmount = 5;    // how many points to fade the LED byunsigned 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

#25
##### Jul 18, 2014, 12:55 am
no , is not working , is have only 30 % from his intensity

#### BulldogLowell

#26
##### Jul 18, 2014, 01:00 am
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 flashint led = 9;           // this led is fadeingint brightness = 0;    // how bright the LED isint fadeAmount = 5;    // how many points to fade the LED byunsigned 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

#27
##### Jul 18, 2014, 01:05 am
yes i say about the FLASHING LED ... if you want i can make you a video to see :| ....

#### edgaryo

#28
##### Jul 18, 2014, 01:06 am
is work but intensity is the problem

#### BulldogLowell

#29
##### Jul 18, 2014, 01:08 amLast 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.

`byte ledPin = 13; // This led is flashint led = 9;           // this led is fadeingint brightness = 0;    // how bright the LED isint fadeAmount = 5;    // how many points to fade the LED byunsigned 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);}`