Show Posts
Pages: [1]
1  Topics / Product Design / For LED on: March 17, 2011, 02:25:31 pm
int inPin = 7;      // the number of the input pin
int reading;        // the current reading from the input pin
int previous = LOW;    // the previous reading from the input pin
int count=0; //number of times button was pressed
const int LedPin = 13;
const int LedPin2 = 12;
const int LedPin3 = 11;
const int LedPin4 = 10;
const int LedPin5 = 9;
const int LedPinG1 = 6;
const int LedPinG2 = 5;
const int LedPinG3 = 4;
const int LedPinG4 = 3;

// the follow variables are long's because the time, measured in miliseconds,
// will quickly become a bigger number than can be stored in an int.
long time = 0;      // the last time the output pin was toggled
long debounce = 200;   // the debounce time, increase if the output flickers

void setup()
{
  pinMode(inPin, INPUT);
  pinMode(LedPin, OUTPUT);
  pinMode(LedPin2, OUTPUT);
  pinMode(LedPin3, OUTPUT);
  pinMode(LedPin4, OUTPUT);
  pinMode(LedPin5, OUTPUT);
  pinMode(LedPinG1, OUTPUT);
  pinMode(LedPinG2, OUTPUT);
  pinMode(LedPinG3, OUTPUT);
  pinMode(LedPinG4, OUTPUT);
}

void loop()
{
  reading = digitalRead(inPin);

  // if we just pressed the button (i.e. the input went from LOW to HIGH),
  // and we've waited long enough since the last press to ignore any noise... 
  if (reading == HIGH && previous == LOW && millis() - time > debounce) {
    //increment count
    count++;

    // ... and remember when the last button press was
    time = millis();   
  }
  previous = reading;
if (count==0)
{
  digitalWrite(LedPin, LOW);
  digitalWrite(LedPin2, LOW);
  digitalWrite(LedPin3, LOW);
  digitalWrite(LedPin4, LOW);
  digitalWrite(LedPin5, LOW);
  digitalWrite(LedPinG1, LOW);
digitalWrite(LedPinG2, LOW);
digitalWrite(LedPinG3, LOW);
digitalWrite(LedPinG4, LOW);
}
if (count==1)
{
digitalWrite(LedPin, HIGH);
digitalWrite(LedPin2, HIGH);
digitalWrite(LedPin3, HIGH);
digitalWrite(LedPin4, HIGH);
digitalWrite(LedPin5, HIGH);
digitalWrite(LedPinG1, LOW);
digitalWrite(LedPinG2, LOW);
digitalWrite(LedPinG3, LOW);
digitalWrite(LedPinG4, LOW);
}
if (count==2)
{
  digitalWrite(LedPin, HIGH);
  digitalWrite(LedPin2, LOW);
  digitalWrite(LedPin3, HIGH);
  digitalWrite(LedPin4, HIGH);
  digitalWrite(LedPin5, HIGH);
  digitalWrite(LedPinG1, HIGH);
  digitalWrite(LedPinG2, LOW);
  digitalWrite(LedPinG3, LOW);
  digitalWrite(LedPinG4, LOW);
}
if (count==3)
{
  digitalWrite(LedPin, HIGH);
  digitalWrite(LedPin2, LOW);
  digitalWrite(LedPin3, LOW);
  digitalWrite(LedPin4, HIGH);
  digitalWrite(LedPin5, HIGH);
  digitalWrite(LedPinG1, HIGH);
digitalWrite(LedPinG2, HIGH);
digitalWrite(LedPinG3, LOW);
digitalWrite(LedPinG4, LOW);
 
}
if (count==4)
{
  digitalWrite(LedPin, HIGH);
  digitalWrite(LedPin2, LOW);
  digitalWrite(LedPin3, LOW);
  digitalWrite(LedPin4, LOW);
  digitalWrite(LedPin5, HIGH);
  digitalWrite(LedPinG1, HIGH);
digitalWrite(LedPinG2, HIGH);
digitalWrite(LedPinG3, HIGH);
digitalWrite(LedPinG4, LOW);
}
if (count==5)
  {
  digitalWrite(LedPin, HIGH);
  digitalWrite(LedPin2, LOW);
  digitalWrite(LedPin3, LOW);
  digitalWrite(LedPin4, LOW);
  digitalWrite(LedPin5, LOW);
  digitalWrite(LedPinG1, HIGH);
  digitalWrite(LedPinG2, HIGH);
digitalWrite(LedPinG3, HIGH);
digitalWrite(LedPinG4, HIGH);
    //whatever you want to do over here
    // ex [count=0; //reset count]
}
  if (count==6)
  {
    count=0;
  }
}


 
2  Using Arduino / Programming Questions / Help With Simple Countdown on: March 15, 2011, 10:17:35 am
Alright here's my problem. I have an arduino uno that I just bought and I need to have a sequence of five LED's turn on with a press of a button (first press turns on first LED, second turns on the second LED, etc). However, I also need to put in a time control where after I press the button to turn on the first LED, a timer begins to count down from one minute twenty seconds. After the time gets to one minute, I need the LED's to remain in their current state whether it be on or off, and then after an additional twenty seconds they turn off. So far, I have the LED's working, but I've spent hours trying to find some way to start a countdown with no progress whatsoever  smiley-mad . Please help.
Pages: [1]