Go Down

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

edgaryo

no , is not fade ... is stay only on or off

edgaryo

so... what we doing now :(  ?

BillHo


BulldogLowell


so... what we doing now :(  ?


I think it is time to see your hardware configuration...

edgaryo



so... what we doing now :(  ?


I think it is time to see your hardware configuration...



i have :
-Arduino UNO
-2 LEDs ( 5mm )
-Distance sensor : http://www.pololu.com/product/1132

BulldogLowell

#35
Jul 18, 2014, 02:56 pm Last Edit: Jul 19, 2014, 12:13 am by BulldogLowell Reason: 1
not familiar with that sensor...

So, put some debug in the code and look at the serial monitor to see what's happening when you get close/far from the sensor.

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

Now is WORKING ! But is work only if i stay with sensor activ . I want to activ sensor a 0,5 second and led 1 flash and led 2 to fade

BulldogLowell

So, you can change that all in the variables at the top of the sketch.


edgaryo


So, you can change that all in the variables at the top of the sketch.




No i want to say , i want to i activ the sensor 0.5 sec ( exemple ) and i want led with fade to make his loop , i mean his cycle . Now is make his cycle if i stay with sensor activ how hold the cycle ... I want to give a impulse to the sensor and led with fade to make his cycle

BulldogLowell

Do you mean to take a sensor reading each half second only. Then light the LEDs according to the reading?


edgaryo

if I act for half a second sensor, light to fade makes the cycle after cycle stand off until the next actuation of the sensor

BulldogLowell


if I act for half a second sensor, light to fade makes the cycle after cycle stand off until the next actuation of the sensor


Sorry, please help me understand. I think you want the sensor to wait while the LEDs are busy and then wait a half second before you want to take the next sensor reading.

edgaryo

no ... ... If sensor active Led is fadeing one time ; if is not activ Led is off .
But if activate sensor 1 milisecond the Led is going to fadeing . Now you understand what i want ? :(

BulldogLowell

You want to delay the flashing unless the signal is detected for more than some period of time. One half second.

Yes?

edgaryo

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 .

Go Up