2

How can I access data values from the arrays in Arduino programming?

The program is given below :

 int myArraylt[24]=    {3530,1580,3880,2780,4040,11260,7935,6655,2100,5100,1450,2200,2200,5900,6180,4230,2405,3560,4535,12635,12085,3500,930,3430};
 int myArraygt[24]=    {0,0,0,0,0,0,6320,5496.9,5948,4124.1,3848.4,3573,3022.2,3297.6,3298.2,3573,4123.2,0,0,0,0,0,0};

 void setup() {

 for (int i=1;i=1;i++)
   if (myArraygt(i)>myArraylt(i))
   println( SSystem is on MG);
   else
   println( SSystem is on GRID); 
 }

 void loop() {
  // put your main code here, to run repeatedly:

 }
Mathews Sunny
  • 1,796
  • 7
  • 21
  • 31

1 Answers1

0

In your code there are few mistakes

  1. array index starts from 0 ,but in your for loop you started it from 1
  2. In the loop condition expression is checked as i=1 it runs loop only for array index 1
  3. In order to access data values from array use array[i] format(not array(i))
  4. for printing in arduino use Serial.println() ,not just println()

For accessing the array values the code should be as follows

    int myArraylt[24]=      {3530,1580,3880,2780,4040,11260,7935,6655,2100,5100,1450,2200,2200,5900,6180,4230,2405,3560,4535,12635,12085,3500,930,3430};
     int myArraygt[24]=    {0,0,0,0,0,0,6320,5496.9,5948,4124.1,3848.4,3573,3022.2,3297.6,3298.2,3573,4123.2,0,0,0,0,0,0};

     void setup() {

     for (int i=0;i<24;i++)
       if (myArraygt[i]>myArraylt[i])
           Serial.println( SSystem is on MG); 
       else
           Serial.println( SSystem is on GRID);
     }

     void loop() {
     // put your main code here, to run repeatedly:
     }

And if you want to print SSystem is on MG and SSystem is on GRID on the screen then it must be put inside double quotes as Serial.println( "SSystem is on MG"); and Serial.println( "SSystem is on GRID");

Mathews Sunny
  • 1,796
  • 7
  • 21
  • 31