I can’t google for things I likely don’t yet know the terminology for, so it’s kind of difficult to explain what I want to do;
-
I have three arrays, named PMP1, PMP2, and PMP3
-
I want to call the correct array based on a given integer.
-
The prefix is “PMP” and int pumpid is 1; how do I use this to call array PMP1?
code snippet;
typedef struct
{
unsigned int PMPdosage = 30; // Dosage in ml.
unsigned int PMPremaining = 480; // Capacity remaining.
unsigned int PMP_speed = 1000; // Runtime needed for 1ml.
byte PMP_Time1[2] = { 00,00 }; // First dosing time.
byte PMP_Time2[2] = { 25,00 }; // Second dosing time.
byte PMP_Days1[7]{ 0,0,0,0,0,0,0 }; // First dosing days.
byte PMP_Days2[7]{ 0,0,0,0,0,0,0 }; // Second dosing days.
} PMP1, PMP2, PMP3;
void Pumpcmd(byte cmd, byte pumpid, unsigned int ml)
{
// THIS IS WHERE IM HAVING TROUBLE:
if(cmd == 3) PMP+pumpid.PMP_dosage = ml
}
Just turn your pumps into an array.
struct PumpDetails {
unsigned int PMPdosage = 30; // Dosage in ml.
unsigned int PMPremaining = 480; // Capacity remaining.
unsigned int PMP_speed = 1000; // Runtime needed for 1ml.
byte PMP_Time1[2] = {00, 00}; // First dosing time.
byte PMP_Time2[2] = {25, 00}; // Second dosing time.
byte PMP_Days1[7]{0, 0, 0, 0, 0, 0, 0}; // First dosing days.
byte PMP_Days2[7]{0, 0, 0, 0, 0, 0, 0}; // Second dosing days.
};
PumpDetails PMP[3];
void Pumpcmd(byte cmd, byte pumpid, unsigned int ml) {
if (cmd == 3) PMP[pumpid-1].PMPdosage = ml; // subtract 1 because array starts at 0
}
I can’t edit my post, but please subtract 1 rather than add one to the array index. The last code line should read “if (cmd == 3) PMP[pumpid-1].PMPdosage = ml; // add 1 because array starts at 0”
Sorry you can’t edit your post. Not sure what settings we have in this forum. But anyway I fixed it and changed “add” to “subtract” in the comment