Go Down

Topic: I need assistance with a project. (Read 1 time) previous topic - next topic

FrankRodelli

Alright, i've got the LED blinking an i've been messing with it. I have that down, now I need to ask a few questions. Is it possible to accomplish what I want without a bread board? and if so, what ports would I connect the push button too and how exactly would that be coded? This is the example i'm using.
Code: [Select]
const int ledPin =  13;     

int ledState = LOW;             // ledState used to set the LED
long previousMillis = 0;        // will store last time LED was updated

// the follow variables is a long because the time, measured in miliseconds,
// will quickly become a bigger number than can be stored in an int.
long interval = 50;           // interval at which to blink (milliseconds)

void setup() {
  // set the digital pin as output:
  pinMode(ledPin, OUTPUT);     
}

void loop()
{
  // here is where you'd put code that needs to be running all the time.

  // check to see if it's time to blink the LED; that is, if the
  // difference between the current time and last time you blinked
  // the LED is bigger than the interval at which you want to
  // blink the LED.
  unsigned long currentMillis = millis();

  if(currentMillis - previousMillis > interval) {
    // save the last time you blinked the LED
    previousMillis = currentMillis;   

    // if the LED is off turn it on and vice-versa:
    if (ledState == LOW)
      ledState = HIGH;
    else
      ledState = LOW;

    // set the LED with the ledState of the variable:
    digitalWrite(ledPin, ledState);
  }
}

PeterH


when I open up my trunk, I'm going to want an led to slowly turn on and then slowly turn back off when the trunk is closed.


This reminds me of the age-old question about fridge lights. If the light only fades off when the trunk is closed, how will you know? This might make more sense as a way to control the car's interior light based on door switches.
I only provide help via the forum - please do not contact me for private consultancy.

FrankRodelli

Well, yeah :p I just want it to slowly come on. I don't really need it to fade out. The issue is, my trunk doesn't have a light. I'd like to set it up with a switch because there are no sensors in my trunk to indicate when It's open and the odds are when I am opening my trunk, the rest of the door will be closed therefore the light would not come on. Is there a simple way to lets just say I hooked my led up to point a and b and my switch to c and d and the code would say if c and d= 1 (connected) then a +b =1(led on) Or is that not possible?

retrolefty


Well, yeah :p I just want it to slowly come on. I don't really need it to fade out. The issue is, my trunk doesn't have a light. I'd like to set it up with a switch because there are no sensors in my trunk to indicate when It's open and the odds are when I am opening my trunk, the rest of the door will be closed therefore the light would not come on. Is there a simple way to lets just say I hooked my led up to point a and b and my switch to c and d and the code would say if c and d= 1 (connected) then a +b =1(led on) Or is that not possible?


But what value does the arduino bring to the party? Why not a simple tilt switch mounted to the trunk lid wired to the lamp and on to +12vdc. Seems a waste of an arduino board if that is all the application requires.

Lefty

https://www.sparkfun.com/products/10289?

FrankRodelli

The reason i'm doing this in the first place is because there is NO lamp in my trunk. Instead of installing a plain light, I wanted to make an aesthetically pleasing LED arrangement to complement my subs. This is where I am. I think this should be working. I've got the LED hooked up to the GND and 13. I have a mommentary push button hooked up one end on the 5 volt spot, and the other on the #2 spot. This is what the code looks like.
Code: [Select]
const int buttonPin = 2;    
const int ledPin =  13;      


int buttonState = 0;        

void setup() {
 pinMode(ledPin, OUTPUT);      
 pinMode(buttonPin, INPUT);    
}

void loop(){
 buttonState = digitalRead(buttonPin);
 if (buttonState == HIGH) {        
   digitalWrite(ledPin, HIGH);  
 }
 else {
   digitalWrite(ledPin, LOW);
 }
}

It's really unpredictable now. It will work sometimes, and others it flicker or stay on and the button won't turn it off. Should the button be grounded? What's going on?

Go Up