// Test for the "Day Of The Week" register of the DS1307 in Wokwi.
// This Wokwi project: https://wokwi.com/projects/391618588603523073
//
// The Day of the Week is defined as 1...7.
// A value of 0 is not used.
// Which number belongs to which day is user defined.
// The number increases at midnight and number 7 becomes number 1.
//

#include <Wire.h>

void setup() 
{
  Serial.begin(115200);
  Wire.begin();

  Serial.print("Test Hours    : ");
  TestRegister(2, 1, 6);
  Serial.print("Test Month    : ");
  TestRegister(5, 1, 6);
  Serial.print("Test Year     : ");
  TestRegister(6, 0, 5);
  Serial.print("Test DayOfWeek: ");
  TestRegister(3, 1, 6);
  Serial.print("Test MonthDay : ");
  TestRegister(4, 1, 6);
}

void loop()
{
  delay(10);
}

void TestRegister(int reg, int startValue, int endValue)
{
  for(int i=startValue; i<endValue; i++)
  {
    Serial.print(i);
    Serial.print("=");

    Wire.beginTransmission(0x68);
    Wire.write(reg);
    Wire.write(i);
    Wire.endTransmission();

    delay(10);     // probably not needed

    Wire.beginTransmission(0x68);
    Wire.write(reg);
    Wire.endTransmission();  // add 'false' for repeated start

    Wire.requestFrom(0x68,1);
    int j = Wire.read();
    Serial.print(j);
    Serial.print(", ");
  }
  Serial.println();
}
GND5VSDASCLSQWRTCDS1307+