Forum: Mikrocontroller und Digitale Elektronik Arduino While Schleife funktionert nicht


von Arduinooo (Gast)


Lesenswert?

Hallo!

Ich habe ein Problem mit einer While Schleife in meinem Programm.
Ich möchte einen Schrittmotor eine bestimmte Anzahl an Schritten laufen 
lassen (100 Schritte).

Mein Programm:
1
#include <Stepper.h>
2
const int stepsPerRevolution = 2048;  // here go the 2048 steps
3
                                      // for your motor
4
5
// initialize the stepper library on pins 8 through 11 -> IN1, IN2, IN3, IN4
6
// as shown above, we need to exchange wire 2&3, which we do in the constructor
7
Stepper myStepper(stepsPerRevolution, 2, 3, 4, 5);
8
int stepCount = 0;         // number of steps the motor has taken
9
10
void setup()
11
12
{
13
14
 // initialize the serial port:
15
  Serial.begin(9600);
16
17
}
18
19
 
20
21
 
22
void loop() 
23
24
{
25
26
while (stepCount < 100);
27
{
28
 myStepper.step(1);
29
   Serial.print("steps: ");
30
   Serial.println(stepCount);
31
   stepCount++;}
32
33
34
  
35
}

Leider funktioniert das Programm nicht. Es passiert nichts.
Ersetze ich das while durch ein IF läuft der Motor dauerhaft, auch wenn 
das while auskommentiert wird läuft er ganz normal.
Ich bin schon am verzweifeln.

Wisst ihr woran das liegen könnte?

Danke! :)

von Arduinoquäler (Gast)


Lesenswert?

Arduinooo schrieb:
1
while (stepCount < 100);
2
//---------------------^------

Die While-Gültigkeit ist am ";" zu Ende.

Ich vermute das willst du nicht.

von rhf (Gast)


Lesenswert?

Hallo,

>> while (stepCount < 100);

Entferne mal das Semikolon hinter der while-Anweisung.

rhf

von Arduinooo (Gast)


Lesenswert?

Danke!

Manchmal sieht man die einfachsten Fehler nicht ;).
Jetzt funktioniert es :).


Arduinooo

Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.