Pages: 1 [2] 3 4   Go Down
Author Topic: Flash and Fade  (Read 752 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
God Member
*****
Karma: 53
Posts: 984
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 54
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 54
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

And the first led is important to stay on 100 ms ( only flash , like a camera flash )
« Last Edit: July 17, 2014, 04:54:40 pm by edgaryo » Logged

Offline Offline
God Member
*****
Karma: 53
Posts: 984
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

OK, then look at this:

Code:
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?


Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 54
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

OK, then look at this:

Code:
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 smiley-grin .
Logged

Offline Offline
God Member
*****
Karma: 53
Posts: 984
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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);
}
Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 54
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 .
Logged

Offline Offline
God Member
*****
Karma: 53
Posts: 984
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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!
« Last Edit: July 17, 2014, 05:41:42 pm by BulldogLowell » Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 54
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 ).
Logged

Offline Offline
God Member
*****
Karma: 53
Posts: 984
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

yeah, sorry.

Try this for flashing:

Code:
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);
}
Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 54
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Offline Offline
God Member
*****
Karma: 53
Posts: 984
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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);
}
Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 54
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

yes i say about the FLASHING LED smiley-sad ... if you want i can make you a video to see smiley-neutral ....
Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 54
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

is work but intensity is the problem smiley-sad
Logged

Offline Offline
God Member
*****
Karma: 53
Posts: 984
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

is work but intensity is the problem smiley-sad
yes i say about the FLASHING LED smiley-sad ... if you want i can make you a video to see smiley-neutral ....

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

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

Code:
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);
}
« Last Edit: July 17, 2014, 06:22:41 pm by BulldogLowell » Logged

Pages: 1 [2] 3 4   Go Up
Jump to: