I’m new in programming arduino, but in programming not so, but I have a little problem I can’t recognize what happens.
I’m trying to create a spider with 4 legs, and move it.
I have created a class named “Spider” and a class named “Leg”, when creating new Spider, it will create 4 Legs, for I can move them separately by Leg classes.
In Leg class I have some values, like: updateInterval, isMoving, lastPosition, etc. All legs have 3 servo motors.
So my problem is, when the program is starting, I’m setting the lastPosition to 90, and now while testing, if I write a command to move Forward or Backward, the value of position is are curious, sometimes 350, sometimes 427, and other curious values.
At the start it must be 90, and if moving forward then +10, if backward then -10. I don’t know where those values come from… So frustrating thing…
I’m testing the new values, if bigger then 180 than will be 180, if lesser then 0, than will be 0 for secure.
After I start the program and giving a command to move forward I got:
Trying to move forward
Trying to move backward
Attached the program codes, please help me.
Leg.cpp (2.46 KB)
Spider.cpp (1.38 KB)
spider.ino (942 Bytes)