Fehler beim kompilieren eines Ampelprogramms

Hallo,

iam trying to write a program fore some trafficlights, so that people can cross the street.

i tryed to run it but it has issues compiling.

can anybodey help please.

grettings :smile:

#define FUSSGRUEN 5
#define FUSSROT 6

#define AUTOGRUEN 8
#define AUTOGELB 9
#define AUTOROT 10

#define TASTER 2

#define GRUEN 3
#define GELB 2
#define ROT 1

long Timer = 0;

void setup() {
  // put your setup code here, to run once:
  pinMode(FUSSGRUEN, OUTPUT);
  pinMode(FUSSROT, OUTPUT);
  pinMode(AUTOGRUEN, OUTPUT);
  pinMode(AUTOGELB, OUTPUT);
  pinMode(AUTOROT, OUTPUT);
  pinMode(TASTER, INPUT);


}

void loop() {
  // put your main code here, to run repeatedly:
  while (TASTER = LOW)
  {
    Schalten(0, GRUEN);
    Schalten(1, ROT);
  }

  if (TASTER != 0)
  {
    Schalten(0, GELB);
    Timer = millis() + 2000;
    Schalten(0, ROT);
    Timer = millis() + 2000;
    Schalten(1, GRUEN);
    Timer = millis() + 6000;
    Schalten(1, ROT);
    Timer = millis() + 2000;
    Schalten(0, GELB);
    Timer = millis() + 2000;
    Schalten(0, GRUEN);
  }
}
void Schalten(byte Ampel, byte Farbe)
{

  byte pinGRUEN = 0; byte pinGELB = 0; byte pinROT = 0;


  if (Ampel == 0)
  {
    pinGRUEN = AUTOGRUEN;
    pinGELB = AUTOGELB;
    pinROT = AUTOROT;
  }

  if (Ampel == 1)
  {
    pinGRUEN = FUSSGRUEN;
    pinROT = FUSSROT;
    pinGELB = LOW;
  }

  switch (Farbe)
  {
    case ROT:
      digitalWrite(pinGRUEN, LOW);
      digitalWrite(pinGELB, LOW);
      digitalWrite(pinROT, HIGH);
      break;

    case GELB:
      digitalWrite(pinGRUEN, LOW);
      digitalWrite(pinGELB, HIGH);
      digitalWrite(pinROT, LOW);
      break;

    case GRUEN:
      digitalWrite(pinGRUEN, HIGH);
      digitalWrite(pinGELB, LOW);
      digitalWrite(pinROT, LOW);
      break;
  }
}

this is the error:

Arduino: 1.8.13 (Windows 10), Board: "Arduino Uno"

In file included from sketch\Ampel_selbstvesuch.ino.cpp:1:0:

C:\Users\Stefanie\Documents\Arduino\Ampel\Ampel_selbstvesuch\Ampel_selbstvesuch.ino: In function 'void loop()':

C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Arduino.h:41:14: error: lvalue required as left operand of assignment

#define LOW 0x0

          ^

C:\Users\Stefanie\Documents\Arduino\Ampel\Ampel_selbstvesuch\Ampel_selbstvesuch.ino:30:19: note: in expansion of macro 'LOW'

while (TASTER = LOW)

               ^~~

exit status 1

Fehler beim Kompilieren für das Board Arduino Uno.

It should be
while(TASTER == LOW)

TASTER=LOW is an assignment but an assignment is not possible, because TASTER is a constant , defined as '2'

P.S. wenn Du schon den Thementitel auf deutsch schreibst, kannst Du auch gleich im deutschen Forumsteil posten.Hier versteht das ja kaum jemand.

Hallo Marco,
vielen Dank. Du hast Recht, das war der Fehler.

Mach ich nächstes Mal. Dachte so hat man evtl. mehr Reichweite.

Danke für die schnelle Antwort und Grüße.

Dann muss aber auch der Titel auf englisch sein.

Another advice: Even if it compiles now without error, I don't think that it does what you intend it to do. As it is now you compare two constants, what does not make much sense.
I think what you intend to do is
while( digitalRead(TASTER) == LOW)

Thats right, i changed it. Thanks again :smile:

void loop() {
  if (digitalRead(TASTER))
  {
    Schalten(0, GRUEN);
    Schalten(1, ROT);
  }

  else
  {

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.