Go Down

Topic: Hallo, ich habe ein Problem mit meinem Code. Der Code wird immer wieder wiederho (Read 660 times) previous topic - next topic

buiya


int carRed = 12;                                              // LED connected to digital pin 12
int carYellow = 11;                                           // LED connected to digital pin 11
int carGreen = 10;                                            // LED connected to digital pin 10
int pedRed = 9;                                               // LED connected to digital pin 9
int pedGreen = 8;                                             // LED connected to digital pin 8
int button = 2;                                               // Button connected to digital pin 2
int crossTime = 5000;
unsigned long changeTime;

int x;

void setup(){
  pinMode(carRed, OUTPUT);                                    // sets the digital pin as output
  pinMode(carYellow, OUTPUT);                                 // sets the digital pin as output
  pinMode(carGreen, OUTPUT);                                  // sets the digital pin as output
  pinMode(pedRed, OUTPUT);                                    // sets the digital pin as output
  pinMode(pedGreen, OUTPUT);                                  // sets the digital pin as output
  pinMode(button, INPUT);                                     // sets the Button as input
  digitalWrite(carGreen, HIGH);                               // set the ledpin to HIGH (5 volts)
  digitalWrite(pedRed, HIGH);                                 // set the ledpin to HIGH (5 volts)

}

void loop(){                                                  // creates the loop that your Arduino will repeat over & over
  int state = digitalRead(button);
  if (state == HIGH && (millis() - changeTime) > 5000){
      changeLights();
  }
}
void changeLights(){                                          // the commands that make the leds light up in a specific order

  digitalWrite(carGreen, LOW);                                // set the ledpin to LOW (0 volts)
  digitalWrite(carYellow, HIGH);                              // set the ledpin to HIGH (5 volts)
  delay(2000);                                                // causes the Arduino to wait for 2000 milliseconds before continuing on to the next line
  digitalWrite(carYellow, LOW);                               // set the ledpin to LOW (0 volts)
  digitalWrite(carRed, HIGH);                                 // set the ledpin to HIGH (5 volts)
  delay(1000);                                                // causes the Arduino to wait for 1000 milliseconds before continuing on to the next line
  digitalWrite(pedRed, LOW);                                  // set the ledpin to LOW (0 volts)
  digitalWrite(pedGreen, HIGH);                               // set the ledpin to HIGH (5 volts)
  delay(crossTime);                                           // causes the Arduino to wait for the specified number of milliseconds before continuing on to the next line
  for(int x=0; x<10; x++){
    digitalWrite(pedGreen, HIGH);                             // set the ledpin to HIGH (5 volts)
    delay(250);                                               // causes the Arduino to wait for 250 milliseconds before continuing on to the next line
    digitalWrite(pedGreen, LOW);                              // set the ledpin to LOW (0 volts)
    delay(250);                                               // causes the Arduino to wait for 250 milliseconds before continuing on to the next line
}
  digitalWrite(pedRed, HIGH);                                 // set the ledpin to HIGH (5 volts)
  delay(500);                                                 // causes the Arduino to wait for 500 milliseconds before continuing on to the next line
  digitalWrite(carYellow, HIGH);                              // set the ledpin to HIGH (5 volts)
  digitalWrite(carRed, LOW);
  delay(1000);                                                // causes the Arduino to wait for 1000 milliseconds before continuing on to the next line
  digitalWrite(carGreen, HIGH);                               // set the ledpin to HIGH (5 volts)
  digitalWrite(carYellow, LOW);
  changeTime = millis();

}

-Holger-

Jepp ... Und zwar nach 5 sec.

Willst du das nicht? Deine Vorstellung und Beschreibung, was du machen willst, ist ja etwas knapp gehalten ;-)

P.S.: Es gibt Code-Tags zum Einfügen von Code...

uwefed

Yann etwas Benehmen bitte.
1) benutze CODE TAGs (Ikone "#")
2) sei etwas freundlich und nimm Dir die Zeit Dein Problem zu beschreiben.
3) ein Gruß ist kein unmöglicher Luxus.
Grüße Uwe

Megaionstorm

Grüezi Mitenand,

möchte für meine Frage keinen neuen Thread eröffnen.

Was ist ein Code-Tag ?
Mein Arduino Projekte Blog:
http://ardu-megatank.blogspot.de/

jubi40

Servus Megaionstorm,

das kannst du hier sehr gut erklärt nachlesen:
http://arduino.cc/forum/index.php/topic,148850.msg1118324.html#post_codetags

ulli.

[edit:] ...aber wie man an deinem Megatank-Thread sieht, kennst du die Code-Tags schon ;)

Go Up