I'm pretty bad at coding (I know the basics), and I'm trying to create an array of servos in Arduino to control via Serial with Processing. I vaguely remember something about Arduino microcontrollers having really limited memory, so I'm not sure if creating an array of Servo objects would work. Here's the code I have so far:
#include <Servo.h>
Servo[] servos = new Servo[6]; //holds the servo objects
int[] servoPos = {90,112,149,45,75,8}; //holds the current position of each servo
char serialVal; //store the serialValue received from serial
void setup()
{
for(int i = 0; i < servos.length; i++) //attach servos to pins
{
servos[i].attach(i+8);
}
Serial.begin(115200); //initialize serial
}
Would an Arduino Uno board be able to support this array and utilize it like in Java? Before now, I've been creating each object separately, which was very inefficient and time-consuming to type and read.
Also, if there's anything that would stop this code from executing, please tell me. I appreciate your help.
My advice is to fire up your Arduino IDE and give it a try. First off you're going to find that you have some problems in your code:
Your array syntax is incorrect. For example:
should be written:
I guess this
servos.length
is a Java thing? Instead you should determine that value by:After you get it to compile you'll see a message in the black console window at the bottom of the Arduino IDE window:
So that will give you some idea of the memory usage. To check free memory at run time I use this library: https://github.com/McNeight/MemoryFree