Pages: [1]   Go Down
Author Topic: Hallo, ich habe ein Problem mit meinem Code. Der Code wird immer wieder wiederho  (Read 487 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


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();

}
Logged

Offline Offline
Newbie
*
Karma: 1
Posts: 30
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Forum Moderator
BZ (I)
Offline Offline
Brattain Member
*****
Karma: 234
Posts: 20196
+39 349 2158303
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

0
Offline Offline
Edison Member
*
Karma: 20
Posts: 1980
Wo ein Wille ist, da ist auch ein Weg !
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Grüezi Mitenand,

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

Was ist ein Code-Tag ?
Logged

Mein Arduino Projekte Blog:
http://ardu-megatank.blogspot.de/

Bavaria
Offline Offline
Newbie
*
Karma: 2
Posts: 39
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 smiley-wink
« Last Edit: July 04, 2013, 01:47:09 am by jubi40 » Logged

Pages: [1]   Go Up
Jump to: