Storing value in 2d array variable during runtime in c++

  arrays, c++, multidimensional-array

My main code is .ino file for STM32F103C8T6 with STM32 official core. I have also included my library files of .h file and .cpp file.

I want store a values in 2d array called uint32_t Page[15][14]; in .h file of my library

How to store a value in 2d array variable during runtime. I have posted my code below. For me the code below is perfect, but still did not print the value stored in the array by calling the function HatriX_Signal with correct parameters. Kindly let me know what is wrong in my code below.

// .ino file

#include "HATRIX.h"

HATRIX Hatrix;

void setup()
{
    Hatrix.HATRIX_INIT(115200);  
}

void loop()
{
    Hatrix.HatriX_Signal(Hatrix.Temperature_Signal, 0x66, Hatrix.Page[2][0]);
    Serial.println(Hatrix.Page[2][0]);
    Serial.println(Hatrix.Page[2][0] / 100);
}
// .h file


#ifndef HATRIX_H
#define HATRIX_H

#include "Arduino.h"
#include "Thermo_Couple_Input.h"

#define Number_of_Pages 15
#define Number_of_Bytes_Per_Page 64

class HATRIX
{
  public:
    Thermo_Couple_Input TC_IN;
    uint32_t Page[Number_of_Pages][(Number_of_Bytes_Per_Page / 4) - 2];
    enum Signal { Temperature_Signal,
                  Pressure_Signal,
                  Co2_Signal,
                  Analog_Industrial_Input_Signal,
                  General_Purpose_Output_Signal,
                  PWM_Power_Signal,
                  PWM_Voltage_Signal
                };

    void HATRIX_INIT(uint32_t bauderate);
    void HatriX_Signal(uint8_t Signal, uint8_t I2C_Address, uint32_t Page);
};

#endif
// .cpp file


#include "HATRIX.h"

void HATRIX::HATRIX_INIT(uint32_t bauderate)
{
    Serial.begin(bauderate); 
}

// brief Note: The value we get from Thermocouple is float value. So, we multiply the value with 100 and store it in specified static uint32_t Page by user.
// param enum_Signal choose accordingly from enum signal: { Hatrix.Temperature_Signal ,
//                                                           Hatrix.Pressure_Signal ,
//                                                           Hatrix.Co2_Signal ,
//                                                           Hatrix.Analog_Industrial_Input_Signal ,
//                                                           Hatrix.General_Purpose_Output_Signal ,
//                                                           Hatrix.PWM_Power_Signal ,
//                                                           Hatrix.PWM_Voltage_Signal };
// param I2C_Address Address of I2C to get the temperature from desired Thermocouple.
// param Page Give the Page details to store your value. example: Hatrix.Page[4][3]
void HATRIX::HatriX_Signal(uint8_t signal, uint8_t I2C_Address, uint32_t Page) 
{
    if(signal == Temperature_Signal);
    {
        TC_IN.Thermo_Couple_Input_Channel(I2C_Address);
        TC_IN.fThermocoupleTemperature = TC_IN.fThermocoupleTemperature * 100;
        Serial.println("Page");
        Serial.println(Page);
        Page = TC_IN.fThermocoupleTemperature;
        Serial.println(Page);
    }
}

Source: Windows Questions C++

LEAVE A COMMENT