Using a counter to stop my loop?

I started a counter that adds each time the reset() function runs within each letter. I set up a conditional to where if the counter becomes greater than 27, it should run a stop function makes the code idle. I don't know why my code keeps running even after the counter surpasses 27. Any suggestions? Go easy, I'm trying.

void Alphabet(){ //my main function
if (i < 27) {
A();
B();
C();
D();
E();
Eff();
G();
H();
I();
J();
K();
L();
M();
N();
O();
P();
Q();
R();
S();
T();
U();
V();
W();
X();
Y();
Z();
}
else if(i>27){ //my else statment, I tried using a normal else but it wouldn't work
Serial.print("Now I Know My ABCs");
stop();
}
}

void Reset() { // my reset function
botpinky.write(90);
toppinky.write(90);
botring.write(90);
topring.write(90);
botbird.write(90);
topbird.write(90);
botpoint.write(90);
toppoint.write(90);
botthumb.write(90);
topthumb.write(90);
wristrot.write(90);
wristang.write(90);
delay(pause);
i = ++i;
Serial.print(i);
}
void A() { //example of a letter function
botpinky.write(0);
toppinky.write(0);
botring.write(0);
topring.write(0);
botbird.write(0);
topbird.write(0);
botpoint.write(0);
toppoint.write(0);
botthumb.write(90);
topthumb.write(90);
wristrot.write(90);
wristang.write(90);
delay(pause);
Reset();
}

Update, it ran to 52 and then executed my else if command

Is this Irish?

This does not "run" at all.

Working on sign language?

Please use code tags when posting code, and post all of it.

yes, building robotic hand that does different gestures and signs

#include <Servo.h>
int i = 0;
int pause = 1000;
Servo botpinky;
Servo toppinky;
Servo botring;
Servo topring;
Servo botbird;
Servo topbird;
Servo botpoint;
Servo toppoint;
Servo wristang;
Servo wristrot;
Servo botthumb;
Servo topthumb;

void setup() {
  Serial.begin(9600);
  botpinky.attach(1);
  toppinky.attach(2);
  botring.attach(3);
  topring.attach(4);
  botbird.attach(5);
  topbird.attach(6);
  botpoint.attach(7);
  toppoint.attach(8);
  wristang.attach(9);
  wristrot.attach(10);
  botthumb.attach(12);
  topthumb.attach(13);
}

void loop(){
      Alphabet();
    } 

void stop() {
   while(1) { /* spin and do nothing */ };
}

void Alphabet(){
    if (i < 27) {
      A();
      // B();
      // C();
      // D();
      // E();
      // Eff();
      // G();
      // H();
      // I();
      // J();
      // K();
      // L();
      // M();
      // N();
      // O();
      // P();
      // Q();
      // R();
      // S();
      // T();
      // U();
      // V();
      // W();
      // X();
      // Y();
      // Z();
    }
      else if(i>27){
          Serial.print("Now I Know My ABCs");
          stop();
      }
    }
  
void Reset() {
  botpinky.write(0);
  toppinky.write(0);
  botring.write(0);
  topring.write(0);
  botbird.write(0);
  topbird.write(0);
  botpoint.write(0);
  toppoint.write(0);
  botthumb.write(0);
  topthumb.write(0);
  wristrot.write(0);
  wristang.write(0);  
  delay(pause);
  i = ++i;
  Serial.print(i);
}
void A() {
  botpinky.write(90);
  toppinky.write(90);
  botring.write(90);
  topring.write(90);
  botbird.write(0);
  topbird.write(0);
  botpoint.write(0);
  toppoint.write(0);
  botthumb.write(0);
  topthumb.write(0);
  wristrot.write(0);
  wristang.write(0);  
  delay(pause);
  Reset();
}

That's just showing the first letter.

I had to use Eff because F() is a command I guess

Very good idea. You can simulate it on WOKWI.COM... Use an Arduino with 12 PWM pins.


I love it

Any idea about the conditional?

What about it? Does it work for you?

It seems to not be working, my counter runs past 27 and my alphabet function continues on.

The scope of "i" is only within "Reset()"... so "i" will always be "0" an all the other functions... make "i" global and see if that works.

The variable "i" is declared and defined as global, but this i = ++i; is not a good idea.

To increment i, Just write ++i; or i++;

my counter runs past 27

There is nothing in the program to reset it.

How do you know it runs past 27? With

and

it looks like once i==27 it will fail both conditionals and endless loop.

Maybe try:

      else if(i>=27){

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