// https://forum.arduino.cc/t/storing-a-struct-containing-day-and-hour-plus-value/988274

# include "BitArray.h"

# define NBITS  168   // one entry per hour per day for one week
# define SIZE   1     // one bit per entry

BitArray hourlySetting;

void setDayHourFlag(unsigned char day, unsigned char hour, unsigned char onOff)
{
  hourlySetting.set(24 * day + hour, onOff);
}

unsigned char getDayHourFlag(unsigned char day, unsigned char hour)
{
  return hourlySetting.get(24 * day + hour);
}

void setup()
{
    Serial.begin(115200);
    Serial.println("hour by hour bit array test");

    hourlySetting.begin(SIZE, NBITS);
    hourlySetting.clear();      // or not

    testThisThing();
}

void testThisThing() {

  Serial.println("Starting up");
  Serial.println("Now writing");
  delay(1000);
  
  int tmp_day=0;
  int tmp_hour=0;
  while(tmp_day < 7) {
    tmp_hour=0;
    while (tmp_hour< 24) {


setDayHourFlag(tmp_day, tmp_hour, random(0, 2));
 
      
      tmp_hour++;
    };
    tmp_day++;
  }; 

  Serial.println("Now display values:");
  tmp_day=0;
  tmp_hour=0;
  while(tmp_day < 7) {
    tmp_hour=0;
    while (tmp_hour< 24) {
    	
      Serial.print("Day: " + String(tmp_day) + " Hour: " + String(tmp_hour) + "  value: ");

Serial.println(getDayHourFlag(tmp_day, tmp_hour) ? "ON" : "OFF");
 
      tmp_hour++;
    };
    tmp_day++;
  }; 

}


void loop()
{
}


// -- END OF FILE --