arduino uno starter kit Projekt 10 Zoetrop

Hallo,

ich bin absoluter Anfänger. Ich habe Projekt 10 Zoetrop gebastelt und den Sktech abgeschrieben.

Aber in Zeile 48 kommt eine Fehlermeldung.

Siehe Anhang

Vielen Dank an den der mir hilft.

Gruß Christoph

In English:

Hi,

am working at arduino uno starter kit Project 10 Zoetrop

In source code lline 48, the last “else” line, there the Compiler says something is wrong.

I do not find out what it is.

Please help

projekt_10.ino (1.67 KB)

You have a misplaced } and a space in a variable name (onOffSwitch State) that should not be there.

See the comments in the code. It compiles now.

const int controlPin1 = 2;  //1
const int controlPin2 = 3;  //2
const int enablePin = 9;//3
const int directionSwitchPin = 4; //4
const int onOffSwitchStateSwitchPin = 5;   //5
const int potPin = A0;  //6
int onOffSwitchState = 0;   //7
int previousOnOffSwitchState = 0;   //8
int directionSwitchState = 0;
int previousDirectionSwitchState = 0;
int motorEnabled = 0;
int motorSpeed = 0;
int motorDirection = 1;



void setup()
{
   pinMode(directionSwitchPin, INPUT);
   pinMode(onOffSwitchStateSwitchPin, INPUT);
   pinMode(controlPin1, OUTPUT);
   pinMode(controlPin2, OUTPUT);
   pinMode(enablePin, OUTPUT);

   digitalWrite(enablePin, LOW);



}

void loop()     //22
{
   onOffSwitchState =
      digitalRead(onOffSwitchStateSwitchPin);
   delay(1);
   directionSwitchState =
      digitalRead(directionSwitchPin);
   motorSpeed = analogRead(potPin) / 4; //26

   if (onOffSwitchState != previousOnOffSwitchState)
   {
      if (onOffSwitchState == HIGH)
      {
         motorEnabled = !motorEnabled;
      }
   }                                            //31
   if (directionSwitchState != previousDirectionSwitchState)
   {
      if (directionSwitchState == HIGH)
      {
         motorDirection = !motorDirection;                        //34
      }
   }
   if (motorDirection == 1)
   {
      digitalWrite(controlPin1, HIGH);  // remove stray } **********
      digitalWrite(controlPin2, LOW);                               //39
   }
   else
   {
      digitalWrite(controlPin1, LOW);
      digitalWrite(controlPin2, HIGH);

   }                      //44
   if (motorEnabled == 1)
   {
      analogWrite(enablePin, motorSpeed);
   }
   else
   {
      analogWrite(enablePin, 0);
   }          //50
   previousDirectionSwitchState = directionSwitchState;
   previousOnOffSwitchState = onOffSwitchState; // removed space ***********
}

If you use the autoformat tool in the IDE (ctrl t or Tools, Auto Format) to properly indent your code, you can see where the else is out of place.

See how your code is now neatly indented and posted in code tags?

If you follow the posting guidelines in the how to use this forum-please read sticky you will save everyone time and get better and faster help. Make it easy on the volunteers that offer assistance.