I am attempting to replicate this tutorial but keep receiving the below error message. Any help is appreciated. After I get these errors fixed I intend to expand the project to 5 boards.
I have the values of the "servos" (I'm driving LEDs) set at 3000 just so the lights will be on for testing.
C:\Users\Ken Parnell\Desktop\Servo_Driver_Board_Modified\Servo_Driver_Board_Modified.ino: In function 'loop':
C:\Users\Ken Parnell\Desktop\Servo_Driver_Board_Modified\Servo_Driver_Board_Modified.ino:257:22: warning: iteration 16 invokes undefined behavior [-Waggressive-loop-optimizations]
Status[i+32] = (cmri.get_bit(i+32));
~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
C:\Users\Ken Parnell\Desktop\Servo_Driver_Board_Modified\Servo_Driver_Board_Modified.ino:236:23: note: within this loop
for (int i = 0; i < numServos; i++) {
Sketch uses 9066 bytes (28%) of program storage space. Maximum is 32256 bytes.
Global variables use 678 bytes (33%) of dynamic memory, leaving 1370 bytes for local variables. Maximum is 2048 bytes.
#include <Wire.h>
#include <Adafruit_PWMServoDriver.h>
#include <CMRI.h>
#include <Auto485.h>
#define CMRI_ADDR 1
#define DE_PIN 2
#define numServos 48 //The number of servos connected
Adafruit_PWMServoDriver pwm1 = Adafruit_PWMServoDriver(0x40); //setup the board address 0
Adafruit_PWMServoDriver pwm2 = Adafruit_PWMServoDriver(0x41); //setup the board address 0
Adafruit_PWMServoDriver pwm3 = Adafruit_PWMServoDriver(0x42); //setup the board address 0
Auto485 bus(DE_PIN); // Arduino pin 2 -> MAX485 DE and RE pins
CMRI cmri(CMRI_ADDR, 24, 48, bus);
int Status[numServos]; //Create a table to hold the status of each turnout, signal, etc.
int Throw[numServos]; //Create a table to hold the throw value for each servo
int Close[numServos]; //Create a table to hold the close value for each servo
void setup() {
Serial.begin(9600);
bus.begin(9600);
pwm1.begin();
pwm1.setPWMFreq(50); // This is the maximum PWM frequency
pwm2.begin();
pwm2.setPWMFreq(50); // This is the maximum PWM frequency
pwm3.begin();
pwm3.setPWMFreq(50); // This is the maximum PWM frequency
//SET THE THROW AND CLOSE VALUES FOR EACH SERVO BASED ON THE CALIBRATION PROCESS
//Servo connection 0 - point motor
Throw[0] = 3000;
Close[0] = 3000;
//Servo connection 0 - point motor
Throw[1] = 3000;
Close[1] = 3000;
//Servo connection 0 - point motor
Throw[2] = 3000;
Close[2] = 3000;
//Servo connection 0 - point motor
Throw[3] = 3000;
Close[3] = 3000;
//Servo connection 0 - point motor
Throw[4] = 3000;
Close[4] = 3000;
//Servo connection 0 - point motor
Throw[5] = 3000;
Close[5] = 3000;
//Servo connection 0 - point motor
Throw[6] = 3000;
Close[6] = 3000;
//Servo connection 0 - point motor
Throw[7] = 3000;
Close[7] = 3000;
//Servo connection 0 - point motor
Throw[8] = 3000;
Close[8] = 3000;
//Servo connection 0 - point motor
Throw[9] = 3000;
Close[9] = 3000;
//Servo connection 0 - point motor
Throw[10] = 3000;
Close[10] = 3000;
//Servo connection 0 - point motor
Throw[11] = 3000;
Close[11] = 3000;
//Servo connection 0 - point motor
Throw[12] = 3000;
Close[12] = 3000;
//Servo connection 0 - point motor
Throw[13] = 3000;
Close[13] = 3000;
//Servo connection 0 - point motor
Throw[14] = 3000;
Close[14] = 3000;
//Servo connection 0 - point motor
Throw[15] = 3000;
Close[15] = 3000;
//Servo connection 0 - point motor
Throw[16] = 3000;
Close[16] = 3000;
//Servo connection 0 - point motor
Throw[17] = 3000;
Close[17] = 3000;
//Servo connection 0 - point motor
Throw[18] = 3000;
Close[18] = 3000;
//Servo connection 0 - point motor
Throw[19] = 3000;
Close[19] = 3000;
//Servo connection 0 - point motor
Throw[20] = 3000;
Close[20] = 3000;
//Servo connection 0 - point motor
Throw[21] = 3000;
Close[21] = 3000;
//Servo connection 0 - point motor
Throw[22] = 3000;
Close[22] = 3000;
//Servo connection 0 - point motor
Throw[23] = 3000;
Close[23] = 3000;
//Servo connection 0 - point motor
Throw[24] = 3000;
Close[24] = 3000;
//Servo connection 0 - point motor
Throw[25] = 3000;
Close[25] = 3000;
//Servo connection 0 - point motor
Throw[26] = 3000;
Close[26] = 3000;
//Servo connection 0 - point motor
Throw[27] = 3000;
Close[27] = 3000;
//Servo connection 0 - point motor
Throw[28] = 3000;
Close[28] = 3000;
//Servo connection 0 - point motor
Throw[29] = 3000;
Close[29] = 3000;
//Servo connection 0 - point motor
Throw[30] = 3000;
Close[30] = 3000;
//Servo connection 0 - point motor
Throw[31] = 3000;
Close[31] = 3000;
//Servo connection 0 - point motor
Throw[32] = 3000;
Close[32] = 3000;
//Servo connection 0 - point motor
Throw[33] = 3000;
Close[33] = 3000;
//Servo connection 0 - point motor
Throw[34] = 3000;
Close[34] = 3000;
//Servo connection 0 - point motor
Throw[35] = 3000;
Close[35] = 3000;
//Servo connection 0 - point motor
Throw[36] = 3000;
Close[36] = 3000;
//Servo connection 0 - point motor
Throw[37] = 3000;
Close[37] = 3000;
//Servo connection 0 - point motor
Throw[38] = 3000;
Close[38] = 3000;
//Servo connection 0 - point motor
Throw[39] = 3000;
Close[39] = 3000;
//Servo connection 0 - point motor
Throw[40] = 3000;
Close[40] = 3000;
//Servo connection 0 - point motor
Throw[41] = 3000;
Close[41] = 3000;
//Servo connection 0 - point motor
Throw[43] = 3000;
Close[43] = 3000;
//Servo connection 0 - point motor
Throw[43] = 3000;
Close[43] = 3000;
//Servo connection 0 - point motor
Throw[44] = 3000;
Close[44] = 3000;
//Servo connection 0 - point motor
Throw[45] = 3000;
Close[45] = 3000;
//Servo connection 0 - point motor
Throw[46] = 3000;
Close[46] = 3000;
//Servo connection 0 - point motor
Throw[47] = 3000;
Close[47] = 3000;
//Servo connection 0 - point motor
Throw[48] = 3000;
Close[48] = 3000;
}
void loop(){
cmri.process();
for (int i = 0; i < numServos; i++) {
//BOARD 1
Status[i] = (cmri.get_bit(i));
if (Status[i] == 1){
pwm1.writeMicroseconds(i, Throw[i]);
}
else {
pwm1.writeMicroseconds(i, Close[i]);
}
//BOARD 2
Status[i+16] = (cmri.get_bit(i+16));
if (Status[i+16] == 1){
pwm2.writeMicroseconds(i, Throw[i+16]);
}
else {
pwm2.writeMicroseconds(i, Close[i+16]);
}
//BOARD 3
Status[i+32] = (cmri.get_bit(i+32));
if (Status[i+32] == 1){
pwm3.writeMicroseconds(i, Throw[i+32]);
}
else {
pwm3.writeMicroseconds(i, Close[i+32]);
}
}
}
It's telling you that when 'i' reaches 16 (on the way to 48) you will go off the end of your Status array: 16+32 == 48 and your array indexes only go up to 47.
Ok I changed "numServos" to "16" like below. It now uploads with no errors and a few minutes of testing seems to work great.
for (int i = 0; i < 16; i++) {
For the final buildout of 5 boards, is the code at bottom the correct way to build the loops? Still seems a little strange each time I add 16. Maybe I'm not understanding how the code is counting through the available pins.
It works, and isn't too bad really, so call it correct.
At some point, perhaps with as few as three and maybe five but too many more and a different approach could be taken.
It would involve using (I am thinking out loud) some kind of two dimensional array of the 5 groups of 16. Then a loop over 5 boards inside a loop over 16 pins, or vice versa (!) would cut the code size down, mebbe be considered elegant or clever, IMO who cares? I generally do not argue with success.
So if this works, fits the time and space it takes then proceed to add the add'l boards.
As for what's going on with the array indices and the addition of 16, 32 and presumably 48 and 64, trust me when I say it will take you less time to figure it out using a bit of the old brain power than it would take us to explain it and then answer questions you have about said explanation.
So I built a full build out of the project and get the same message. It seems when I go past 3 boards it doesn't like this "<16"?
C:\Users\Ken Parnell\Desktop\Servo_Driver_Board_Modified\Servo_Driver_Board_Modified.ino: In function 'loop':
C:\Users\Ken Parnell\Desktop\Servo_Driver_Board_Modified\Servo_Driver_Board_Modified.ino:115:22: warning: iteration 12 invokes undefined behavior [-Waggressive-loop-optimizations]
Status[i+48] = (cmri.get_bit(i+48));
~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
C:\Users\Ken Parnell\Desktop\Servo_Driver_Board_Modified\Servo_Driver_Board_Modified.ino:85:23: note: within this loop
for (int i = 0; i < 16; i++) {
~~^~~~
Full Project:
#include <Wire.h>
#include <Adafruit_PWMServoDriver.h>
#include <CMRI.h>
#include <Auto485.h>
#define CMRI_ADDR 1
#define DE_PIN 2
#define numServos 60 //The number of servos connected
Adafruit_PWMServoDriver pwm1 = Adafruit_PWMServoDriver(0x40); //setup the board address 0
Adafruit_PWMServoDriver pwm2 = Adafruit_PWMServoDriver(0x41); //setup the board address 0
Adafruit_PWMServoDriver pwm3 = Adafruit_PWMServoDriver(0x42); //setup the board address 0
Adafruit_PWMServoDriver pwm4 = Adafruit_PWMServoDriver(0x43); //setup the board address 0
Adafruit_PWMServoDriver pwm5 = Adafruit_PWMServoDriver(0x44); //setup the board address 0
Auto485 bus(DE_PIN); // Arduino pin 2 -> MAX485 DE and RE pins
CMRI cmri(CMRI_ADDR, 24, 48, bus);
int Status[numServos]; //Create a table to hold the status of each turnout, signal, etc.
int Throw[numServos]; //Create a table to hold the throw value for each servo
int Close[numServos]; //Create a table to hold the close value for each servo
void setup() {
Serial.begin(9600);
bus.begin(9600);
pwm1.begin();
pwm1.setPWMFreq(50); // This is the maximum PWM frequency
pwm2.begin();
pwm2.setPWMFreq(50); // This is the maximum PWM frequency
pwm3.begin();
pwm3.setPWMFreq(50); // This is the maximum PWM frequency
pwm4.begin();
pwm4.setPWMFreq(50); // This is the maximum PWM frequency
pwm5.begin();
pwm5.setPWMFreq(50); // This is the maximum PWM frequency
//SET THE THROW AND CLOSE VALUES FOR EACH SERVO BASED ON THE CALIBRATION PROCESS
//Servo connection 0 - point motor
Throw[22] = 2000;
Close[22] = 2000;
//Servo connection 0 - point motor
Throw[38] = 1000;
Close[38] = 1000;
//Servo connection 0 - point motor
Throw[39] = 1000;
Close[39] = 1000;
//Servo connection 0 - point motor
Throw[40] = 2000;
Close[40] = 2000;
//Servo connection 0 - point motor
Throw[41] = 1000;
Close[41] = 1000;
//Servo connection 0 - point motor
Throw[42] = 2000;
Close[42] = 2000;
//Servo connection 0 - point motor
Throw[48] = 2000;
Close[48] = 2000;
//Servo connection 0 - point motor
Throw[53] = 2000;
Close[53] = 2000;
//Servo connection 0 - point motor
Throw[54] = 2000;
Close[54] = 2000;
//Servo connection 0 - point motor
Throw[55] = 2000;
Close[55] = 2000;
}
void loop(){
cmri.process();
for (int i = 0; i < 16; i++) {
//BOARD 1
Status[i] = (cmri.get_bit(i));
if (Status[i] == 1){
pwm1.writeMicroseconds(i, Throw[i]);
}
else {
pwm1.writeMicroseconds(i, Close[i]);
}
//BOARD 2
Status[i+16] = (cmri.get_bit(i+16));
if (Status[i+16] == 1){
pwm2.writeMicroseconds(i, Throw[i+16]);
}
else {
pwm2.writeMicroseconds(i, Close[i+16]);
}
//BOARD 3
Status[i+32] = (cmri.get_bit(i+32));
if (Status[i+32] == 1){
pwm3.writeMicroseconds(i, Throw[i+32]);
}
else {
pwm3.writeMicroseconds(i, Close[i+32]);
}
//BOARD 4
Status[i+48] = (cmri.get_bit(i+48));
if (Status[i+48] == 1){
pwm4.writeMicroseconds(i, Throw[i+48]);
}
else {
pwm4.writeMicroseconds(i, Close[i+48]);
}
//BOARD 5
Status[i+64] = (cmri.get_bit(i+64));
if (Status[i+64] == 1){
pwm5.writeMicroseconds(i, Throw[i+64]);
}
else {
pwm5.writeMicroseconds(i, Close[i+64]);
}
}
}
Here is the completed Project. FYI if anyone stumbles on this in the future...when talking to the JMRI software, you will need to change the node to CPNODE, then add enough output driver cards to cover the 5 PCA9685.
#include <Wire.h>
#include <Adafruit_PWMServoDriver.h>
#include <CMRI.h>
#include <Auto485.h>
#define CMRI_ADDR 1
#define DE_PIN 2
#define numServos 80 //The number of servos connected
Adafruit_PWMServoDriver pwm1 = Adafruit_PWMServoDriver(0x40); //setup the board address 0
Adafruit_PWMServoDriver pwm2 = Adafruit_PWMServoDriver(0x41); //setup the board address 0
Adafruit_PWMServoDriver pwm3 = Adafruit_PWMServoDriver(0x42); //setup the board address 0
Adafruit_PWMServoDriver pwm4 = Adafruit_PWMServoDriver(0x43); //setup the board address 0
Adafruit_PWMServoDriver pwm5 = Adafruit_PWMServoDriver(0x44); //setup the board address 0
Auto485 bus(DE_PIN); // Arduino pin 2 -> MAX485 DE and RE pins
CMRI cmri(CMRI_ADDR, 16, 88, bus);
int Status[numServos]; //Create a table to hold the status of each turnout, signal, etc.
int Throw[numServos]; //Create a table to hold the throw value for each servo
int Close[numServos]; //Create a table to hold the close value for each servo
void setup() {
Serial.begin(9600);
bus.begin(9600);
pwm1.begin();
pwm1.setPWMFreq(50); // This is the maximum PWM frequency
pwm2.begin();
pwm2.setPWMFreq(50); // This is the maximum PWM frequency
pwm3.begin();
pwm3.setPWMFreq(50); // This is the maximum PWM frequency
pwm4.begin();
pwm4.setPWMFreq(50); // This is the maximum PWM frequency
pwm5.begin();
pwm5.setPWMFreq(50); // This is the maximum PWM frequency
//SET THE BRIGHTNESS VALUE OF LEDS
//PIN connection 1 - SPARE - NOT IN USE
//Throw[0] = 0; //NOT IN USE
//Close[0] = 0; //NOT IN USE
// BEGIN SIGNAL LOCATION:CP: SOUTH EDISTO ABSOLUTE SIGNALS
// vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
//PIN connection 2 - NO SIGNAL YET
Throw[1] = 0;
Close[1] = 0;
//PIN connection 3 - NO SIGNAL YET
Throw[2] = 0;
Close[2] = 0;
//PIN connection 4 - NO SIGNAL YET
Throw[3] = 0;
Close[3] = 0;
//PIN connection 5 - NO SIGNAL YET
Throw[4] = 0;
Close[4] = 0;
//PIN connection 6 - NO SIGNAL YET
Throw[5] = 0;
Close[5] = 0;
//PIN connection 7 - NO SIGNAL YET
Throw[6] = 0;
Close[6] = 0;
//PIN connection 8 - NO SIGNAL YET
Throw[7] = 0;
Close[7] = 0;
//PIN connection 9 - NO SIGNAL YET
Throw[8] = 0;
Close[8] = 0;
//PIN connection 10 - NO SIGNAL YET
Throw[9] = 0;
Close[9] = 0;
//PIN connection 11 - NO SIGNAL YET
Throw[10] = 0;
Close[10] = 0;
//PIN connection 12 - NO SIGNAL YET
Throw[11] = 0;
Close[11] = 0;
//PIN connection 13 - NO SIGNAL YET
Throw[12] = 0;
Close[12] = 0;
//PIN connection 14
Throw[13] = 1000;
Close[13] = 0;
//PIN connection 15
Throw[14] = 1000;
Close[14] = 0;
//PIN connection 16 - SPARE - NOT IN USE
Throw[15] = 0; //NOT IN USE
Close[15] = 0; //NOT IN USE
//PIN connection 17 - SPARE - NOT IN USE
Throw[16] = 0; //NOT IN USE
Close[16] = 0; //NOT IN USE
//PIN connection 18
Throw[17] = 1000;
Close[17] = 0;
//PIN connection 19
Throw[18] = 1000;
Close[18] = 0;
//PIN connection 20
Throw[19] = 1000;
Close[19] = 0;
//PIN connection 21
Throw[20] = 1000;
Close[20] = 0;
//PIN connection 22 -
Throw[21] = 1000;
Close[21] = 0;
//PIN connection 23 -
Throw[22] = 1000;
Close[22] = 0;
//PIN connection 24 -
Throw[23] = 1000;
Close[23] = 0;
//PIN connection 25 -
Throw[24] = 1000;
Close[24] = 0;
//PIN connection 26 -
Throw[25] = 1000;
Close[25] = 0;
//PIN connection 27 -
Throw[26] = 1000;
Close[26] = 0;
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
// END SIGNAL LOCATION:CP: SOUTH EDISTO ABSOLUTE SIGNALS
//
// BEGIN SIGNAL LOCATION: STONO INTERMEDIATE SIGNALS
// vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
//PIN connection 28
Throw[27] = 1000;
Close[27] = 000;
//PIN connection 29
Throw[28] = 1000;
Close[28] = 000;
//PIN connection 30
Throw[29] = 1000;
Close[29] = 000;
//PIN connection 31
Throw[30] = 1000;
Close[30] = 000;
//PIN connection 32 - SPARE - NOT IN USE
Throw[31] = 0; //NOT IN USE
Close[31] = 0; //NOT IN USE
//PIN connection 33 - SPARE - NOT IN USE
Throw[32] = 0; //NOT IN USE
Close[32] = 0; //NOT IN USE
//PIN connection 34
Throw[33] = 1000;
Close[33] = 000;
//PIN connection 35
Throw[34] = 1000;
Close[34] = 000;
//PIN connection 36 - GREEN
Throw[35] = 1000;
Close[35] = 000;
//PIN connection 37 - YELLOW
Throw[36] = 1000;
Close[36] = 000;
//PIN connection 38 - RED
Throw[37] = 1000;
Close[37] = 000;
//PIN connection 39 - GREEN
Throw[38] = 1000;
Close[38] = 000;
//PIN connection 40 - YELLOW
Throw[39] = 1000;
Close[39] = 000;
//PIN connection 41 - RED
Throw[40] = 1000;
Close[40] = 000;
//PIN connection 42 - GREEN
Throw[41] = 1000;
Close[41] = 000;
//PIN connection 43 - YELLOW
Throw[42] = 1000;
Close[42] = 000;
//PIN connection 44 - RED
Throw[43] = 1000;
Close[43] = 000;
//PIN connection 45 - GREEN
Throw[44] = 1000;
Close[44] = 000;
//PIN connection 46 - YELLOW
Throw[45] = 1000;
Close[45] = 000;
//PIN connection 47 - RED
Throw[46] = 1000;
Close[46] = 000;
//PIN connection 48 - GREEN
Throw[47] = 1000;
Close[47] = 000;
//PIN connection 50 - DAMAGED
Throw[48] = 000; //NOT IN USE
Close[48] = 000; //NOT IN USE
//PIN connection 50 - DAMAGED
Throw[49] = 000; //NOT IN USE
Close[49] = 000; //NOT IN USE
//PIN connection 51 - YELLOW
Throw[50] = 1000;
Close[50] = 000;
//PIN connection 52 - RED
Throw[51] = 1000;
Close[51] = 000;
//PIN connection 53 - GREEN
Throw[52] = 1000;
Close[52] = 000;
//PIN connection 54 - YELLOW
Throw[53] = 1000;
Close[53] = 000;
//PIN connection 55 - RED
Throw[54] = 1000;
Close[54] = 000;
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
// END SIGNAL LOCATION: CP: STONO INTERMEDIATE SIGNALS
//
// BEGIN SIGNAL LOCATION: CYPRESS INTERMEDIATE SIGNALS
// vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
//PIN connection 56 -
Throw[55] = 1000;
Close[55] = 000;
//PIN connection 57 - YELLOW
Throw[56] = 1000;
Close[56] = 000;
//PIN connection 58 - RED
Throw[57] = 1000;
Close[57] = 000;
//PIN connection 59 - YELLOW
Throw[58] = 1000;
Close[58] = 000;
//PIN connection 60 - RED
Throw[59] = 1000;
Close[59] = 000;
//PIN connection 61 - GREEN
Throw[60] = 1000;
Close[60] = 000;
//PIN connection 62 -
Throw[61] = 1000;
Close[61] = 000;
//PIN connection 63 -
Throw[62] = 1000;
Close[62] = 000;
//PIN connection 64 -
Throw[63] = 1000;
Close[63] = 000;
//PIN connection 65 -
Throw[64] = 1000;
Close[64] = 000;
//PIN connection 66 - GREEN
Throw[65] = 1000;
Close[65] = 000;
//PIN connection 67 - YELLOW
Throw[66] = 1000;
Close[66] = 000;
//PIN connection 68 -
Throw[67] = 1000;
Close[67] = 000;
//PIN connection 69 -
Throw[68] = 1000;
Close[68] = 000;
//PIN connection 70 -
Throw[69] = 1000;
Close[69] = 000;
//PIN connection 71 -
Throw[70] = 1000;
Close[70] = 00;
//PIN connection 72 -
Throw[71] = 1000;
Close[71] = 000;
//PIN connection 73 -
Throw[72] = 1000;
Close[72] = 000;
//PIN connection 74 -
Throw[73] = 1000;
Close[73] = 000;
//PIN connection 75 - GREEN
Throw[74] = 1000;
Close[74] = 000;
//PIN connection 76 -
Throw[75] = 1000;
Close[75] = 000;
//PIN connection 77 -
Throw[76] = 1000;
Close[76] = 000;
//PIN connection 78 -
Throw[77] = 1000;
Close[77] = 000;
//PIN connection 79 -
Throw[78] = 1000;
Close[78] = 000;
//PIN connection 80 -
Throw[79] = 1000;
Close[79] = 000;
//PIN connection 0 -
Throw[80] = 000;
Close[80] = 000;
}
void loop(){
cmri.process();
for (int i = 0; i < 16; i++) {
//BOARD 1
Status[i] = (cmri.get_bit(i));
if (Status[i] == 1){
pwm1.writeMicroseconds(i, Throw[i]);
}
else {
pwm1.writeMicroseconds(i, Close[i]);
}
//BOARD 2
Status[i+16] = (cmri.get_bit(i+16));
if (Status[i+16] == 1){
pwm2.writeMicroseconds(i, Throw[i+16]);
}
else {
pwm2.writeMicroseconds(i, Close[i+16]);
}
//BOARD 3
Status[i+32] = (cmri.get_bit(i+32));
if (Status[i+32] == 1){
pwm3.writeMicroseconds(i, Throw[i+32]);
}
else {
pwm3.writeMicroseconds(i, Close[i+32]);
}
//BOARD 4
Status[i+48] = (cmri.get_bit(i+48));
if (Status[i+48] == 1){
pwm4.writeMicroseconds(i, Throw[i+48]);
}
else {
pwm4.writeMicroseconds(i, Close[i+48]);
}
//BOARD 5
Status[i+64] = (cmri.get_bit(i+64));
if (Status[i+64] == 1){
pwm5.writeMicroseconds(i, Throw[i+64]);
}
else {
pwm5.writeMicroseconds(i, Close[i+64]);
}
}
}
If you continue to pursue programming, revisit this code as you learn.
There are a few things you’ll find that can make this code different.
When you learn (more) about arrays, you’ll be able to reduce the repetition of sequences of code.
When you learn (more) about functions, you’ll be able to make the code more pleasant.
For lack of a better word, I mean like pretty or easier to read as someone who didn’t write it, or yourself some time in the future. For me, my code stops making sense if I am not careful about three days after I haven’t been working with it.
When you learn (more) about structs and classes, you’ll be able to create little servo objects that encapsulate everything related to a given servo in a single place and that will impress people. And have other advantages.
But I have said and say again, I do not argue against success, you have succeeded and that’s the important part just now.