Function can't execute completely

I'm writing function which consist of number of arrays however the function don't execute.

float vIns[18];
#define tacSwitch 2
#define xBase 5
float vL[18]; 
float iL[18];
float load[18];
float vcal = 4.640;
bool J = 1;

void setup(){
  pinMode( vIns, INPUT);
  pinMode(tacSwitch, INPUT_PULLUP);
  pinMode(xBase, OUTPUT);    }

  void loop(){

    J = digitalRead(tacSwitch);                         // is switch triggered? 1=NO 0 = yes  
    if(J == 0){
      ircalc();
      }
}
"void ircalc(){                     //function is ircalc                          
  digitalWrite(xBase, HIGH);      //xBase is input pullup                    
    for (int i=0; i<=17; i++){
   vL[i] = (analogRead(vIns[i])*vcal)/1023;          // vL is an array,  vIns is an array
   }
    for (int i=0; i<=17; i++){
       load[i]=5;                                               //load is an array
     }
   for (int i=0; i=17; i++){
  iL[i] = vL[i]/load[i];                                   //ilL is an array, 
  }                             
  digitalWrite(xBase, LOW); " 

if the xBase goes high then it remain high the rest of function don't run.

Your code is incomplete, and so cannot compile.

I'm writing function which consist of number of arrays

...which you forgot to post.

It's also not an installation or troubleshooting issue.

Not going well, is it?

Your topic was MOVED to its current forum category as it is more suitable than the original

Please post a complete sketch that illustrates the problem rather than an isolated snippet of code with no context

for (int i=0; i=17; i++)

Whoops !

What will be the values of i in this for loop ?

the analog readings from vIns array
vL[i] = (analogRead(vIns[i])*vcal)/1023;

If that is a reply to my post #4 then you have missed the point of my question

Let me put it another way.

for (int i=0; i=17; i++)

How many iterations of the for loop will occur ?

18 iterations should occur

Try this

void setup()
{
  Serial.begin(115200);
  for (int i = 0; i = 17; i++)
  {
    Serial.println(i);
  }
}

void loop()
{
}
1 Like

i try your suggestion in the setup its work however in the loop where i call a function "ircalc" it does not work.


    J = digitalRead(tacSwitch);                         // is switch triggered? 1=NO 0 = yes  
    if(J == 0){
      ircalc();
      }
}
"void ircalc(){                     //function is ircalc                          
  digitalWrite(xBase, HIGH);      //xBase is input pullup                    
    for (int i=0; i<=17; i++){
   vL[i] = (analogRead(vIns[i])*vcal)/1023;          // vL is an array,  vIns is an array
   }
    for (int i=0; i<=17; i++){
       load[i]=5;                                               //load is an array
     }
   for (int i=0; i=17; i++){
  iL[i] = vL[i]/load[i];                                   //ilL is an array, 
  }                             
  digitalWrite(xBase, LOW); 

Still oops

I don't imagine the compiler was happy about those double quotes.

yes

So, why didn't you fix it?
Leaving the same bug in is just wasting time.

the double quotes is not in the original code

What about the incorrect for loop ?

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