Multidimensional array with date and numbers

Hello,

I would like to create something similar to a multidimensional array.
I would like to get this effect.

setting = [
0 => [// 0 is the day of the week, but it can be a number
‘1:25’ => 25, // key is time. The value is a number (temperature)
‘7:12’ => 22,
'15: 30 '=> 21,
'18: 00 '=> 23
'22: 25 '=> 22
]
1 => [
‘1:25’ => 25,
‘7:00’ => 21,
'15: 00 '=> 22,
'18: 00 '=> 25
'22: 25 '=> 22
]
2 => [
‘1:25’ => 25,
‘7:00’ => 21,
'15: 32 '=> 21,
'18: 40 '=> 25
'22: 25 '=> 22
]
.
.
.
e.t.c
];

Then I would like to read these values. Days of the week and time are already downloading, but I do not know how to make such a board. I would like to download these values (temperature) to a variable.
Regards

1 Like

A two dimensional array of structs is what you need. Each array element is a struct containing two fields - the time and the temperature.

I think you will find the time format that you've chosen unwieldy for time calculations. Do you have an RTC?

May I have a more detailed explanation?
Yes, I have RTC.

A more detailed explanation is futile without seeing all your code. Please post it here in code tags.

The pasted code won’t help, because my problem concerns the next stage of the “project”. The only thing I have now is to the days of the week (from 0 to 6) with which I can indicate the index.

/*****==[ Załączanie bibliotek ]== *****/
#include <Wire.h>
#include "RTClib.h"


/*****==[ RTC - Czas ]== *****/
RTC_DS3231 rtc;

/*****==[ STAŁE ]== *****/
//Przekaźnik
#define RELAY 3        // Pin dla Przekaźnika

/*****==[ ZMIENNE ]== *****/

//Definiowanie tablicy dla dni tygodnia
//Druga liczba char to ile maksymalnie znaków moze mieć jedna komórka. On niedzieli, gdyż w tej formie niedziela jest jako 0
char daysOfTheWeek[7][13] = {"Niedziela", "Poniedzialek", "Wtorek", "Sroda", "Czwartek", "Piatek", "Sobota"};


void setup () 
{
    Serial.begin(9600);
    delay(3000); // wait for console opening

    /*****==[ USTAWIANIE PINÓW ]== *****/
    pinMode(RELAY, OUTPUT);          // Ustawienie pinu RELAY jako wyjscie 

    //RTC - Czas
    if (! rtc.begin()) {
        Serial.println("Nie mozna znalezc modułu RTC");
        while (1);
    }

    if (rtc.lostPower()) {
        Serial.println("RTC stracił moc. Inicjuje ustawianie czasu");
        rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
    }

    /*****==[ WSTĘPNE USTAWIENIA ]== *****/
    digitalWrite(RELAY, LOW);
}

void loop () 
{
    digitalWrite(RELAY, LOW);
    delay(2000);
    digitalWrite(RELAY, HIGH);
    DateTime now = rtc.now();

    Serial.println("Current Date & Time: ");
    Serial.print(now.year(), DEC);
    Serial.print('/');
    Serial.print(now.month(), DEC);
    Serial.print('/');
    Serial.print(now.day(), DEC);
    Serial.print("=========");
    Serial.print(" (");
    Serial.print(daysOfTheWeek[now.dayOfTheWeek()]);
    Serial.print(") ");
    Serial.print(now.hour(), DEC);
    Serial.print(':');
    Serial.print(now.minute(), DEC);
    Serial.print(':');
    Serial.print(now.second(), DEC);
    Serial.println();
    
    Serial.println("Unix Time: ");
    Serial.print("elapsed ");
    Serial.print(now.unixtime());
    Serial.print(" seconds/");
    Serial.print(now.unixtime() / 86400L);
    Serial.println(" days since 1/1/1970");




    
    // Dodanie czasu do czasu. Dodajemy np od aktualnego czasu 7 dni 30 sekund
    // DateTime future (now + TimeSpan(7,0,0,30));
    
    // Serial.println("Aktualna godzina: ");
    // Serial.print(future.year(), DEC);
    // Serial.print('/');
    // Serial.print(future.month(), DEC);
    // Serial.print('/');
    // Serial.print(future.day(), DEC);
    // Serial.print(' ');
    // Serial.print(future.hour(), DEC);
    // Serial.print(':');
    // Serial.print(future.minute(), DEC);
    // Serial.print(':');
    // Serial.print(future.second(), DEC);
    // Serial.println();
    
    Serial.println();
    delay(2000);
}

There are probably mistakes in this, but your array would look something like:

struct calendarData {
  char timeString[8]
  int temp;
}

calendarData calendar[7][] = { {"1:25", 25}, ...
1 Like

There is no error in the code.
I use external libraries.

I will check your suggestions tomorrow. Thank you very much for today. If you ever come to Poland, I'll buy you a beer.

Hear you tomorrow.

tarzinio:
There is no error in the code.

I was referring to my code. I would like to visit Poland one day, after the pandemic of course.

Hello,
Sorry, I read quickly, and I don't know English very well. I recommend visiting Poland.