Go Down

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

BulldogLowell

Sorry, I thought that's what we just wrote.

Are you talking about a new input?  Very confused here....


edgaryo

nooo , i was compare my sensor with a button :D , only that . :D

BulldogLowell

Quote
no , i want all in real time , no delay . I want when is active sensor , one led is make a flash , and another led to fade . That's all . The sensor is like a buton , if i push him ( but i not keep him down , just one clik ) one led is make a flash and the other is make fade .


this is what we wrote.  The processor will sense a change in the level
Code: [Select]
if ( analogRead(A0) < 630)
without any delays in the code.  We are not using delays here.

Perhaps you can put into this what you mean, even if it is not correct:

Code: [Select]
void loop()
{
  if ( analogRead(A0) < 630)
  {
    Serial.println("close to sensor");
    if (readyToFlash)
    {
      if (flashing = false) startTime = millis();
      Serial.println("FLASH");
      flashLedPinOnce();
    }
    if (fadeOn == true) fadePinNine();
  }
  else
  {
    Serial.println("far from sensor");
    allPinsOff();
    readyToFlash = true;
    fadeOn = true;
  }
}


AWOL

Code: [Select]
if (flashing = false)
Oops
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

BulldogLowell


Code: [Select]
if (flashing = false)
Oops


thank you... good eye.  Perhaps that was his issue.  fixed here:

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()
{
  Serial.begin(9600);
  pinMode( ledPin, OUTPUT );
}

void loop()
{
  if ( analogRead(A0) < 630)
  {
    Serial.println("close to sensor");
    if (readyToFlash)
    {
      if (flashing == false) startTime = millis();
      Serial.println("FLASH");
      flashLedPinOnce();
    }
    if (fadeOn == true) fadePinNine();
  }
  else
  {
    Serial.println("far from sensor");
    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);
}

edgaryo

this code is not working . Is not work the Flash :(

AWOL

Quote
this code

I can't see your code.
I can't see a description of what it is doing.
Sorry, can't help you.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy