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

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

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

so... what we doing now smiley-sad  ?
Logged

SG
Offline Offline
God Member
*****
Karma: 11
Posts: 532
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Read this
http://gammon.com.au/blink
Logged

Offline Offline
Edison Member
*
Karma: 53
Posts: 1003
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

so... what we doing now smiley-sad  ?

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

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

so... what we doing now smiley-sad  ?

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
Logged

Offline Offline
Edison Member
*
Karma: 53
Posts: 1003
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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);
}
« Last Edit: July 18, 2014, 05:13:23 pm by BulldogLowell » Logged

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

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
Logged

Offline Offline
Edison Member
*
Karma: 53
Posts: 1003
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Logged

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

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
Logged

Offline Offline
Edison Member
*
Karma: 53
Posts: 1003
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Logged

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

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
Logged

Offline Offline
Edison Member
*
Karma: 53
Posts: 1003
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

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

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

Offline Offline
Edison Member
*
Karma: 53
Posts: 1003
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Yes?
Logged

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

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

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