#define OLED_ADRS 0x3C //SA0=L(SA0=H の場合は 0x3D) int DisplayON = 0x0F, ClearDisplay = 0x01, ReturnHome = 0x02; int DS1307_ADDRESS=0x68; int val=0; byte command; void setup() { Wire.begin(); //Wire ライブラリを初期化し、I2C マスタとしてバスに接続 init_oled(); printTime(); setDay(); setTime(); } void loop() { writeData(r_sec); writeCommand(0x20+0x80); //2 行目の先頭 contrast_max(); //輝度を最大に設定 while(1){} } //----main end---- void writeData(byte t_data) { Wire.beginTransmission(OLED_ADRS); Wire.write(0x40); Wire.write(t_data); Wire.endTransmission(); delay(1); } void writeCommand(byte t_command) { Wire.beginTransmission(OLED_ADRS); Wire.write(0x00); Wire.write(t_command); Wire.endTransmission(); delay(10); } void contrast_max(){ writeCommand(0x2a);//RE=1 writeCommand(0x79);//SD=1 writeCommand(0x81);//コントラストセット writeCommand(0xFF);//輝度MAX writeCommand(0x78);//SD を0にもどす writeCommand(0x28); //2C=高文字 28=ノーマル delay(100); } void setTime(){ byte hour=(Serial.read()<<4); hour=hour+(Serial.read()&0x0F); byte minute=(Serial.read()<<4); minute=minute+(Serial.read()&0x0F); byte sec=(Serial.read()<<4); sec=sec+(Serial.read()&0x0F); Wire.beginTransmission(DS1307_ADDRESS); Wire.write(val); Wire.write(sec); Wire.write(minute); Wire.write(hour); Wire.endTransmission(); } void setDay(){ byte year=(Serial.read()<<4); year=year+(Serial.read()&0x0F); byte month=(Serial.read()<<4); month=month+(Serial.read()&0x0F); byte day=(Serial.read()<<4); day=day+(Serial.read()&0x0F); byte day_of_week=(Serial.read()&0x0F); Wire.beginTransmission(DS1307_ADDRESS); Wire.write(0x03); Wire.write(day_of_week); Wire.write(day); Wire.write(month); Wire.write(year); Wire.endTransmission(); } void printTime(){ Wire.beginTransmission(DS1307_ADDRESS); Wire.write(val); Wire.endTransmission(); Wire.requestFrom(DS1307_ADDRESS,7); byte r_sec=Wire.read(); byte r_minute=Wire.read(); byte r_hour=Wire.read(); byte r_day_of_week=Wire.read(); byte r_date=Wire.read(); byte r_month=Wire.read(); byte r_year=Wire.read(); } void init_oled() { delay(100); writeCommand(ClearDisplay); // Clear Display delay(20); writeCommand(ReturnHome); // ReturnHome delay(2); writeCommand(DisplayON); // Send Display on command delay(2); writeCommand(ClearDisplay); // Clear Display delay(20); } コード ```RTC(DS1307)とOLEDディスプレイ(so1602aw)のコードを参考にしてr_secを表示するコードを作ってみたのですがうまくいきません。 何が間違っていますか? #include <Wire.h> #define OLED_ADRS 0x3C //SA0=L(SA0=H の場合は 0x3D) int DisplayON = 0x0F, ClearDisplay = 0x01, ReturnHome = 0x02; int DS1307_ADDRESS=0x68; int val=0; byte command; void setup() { Wire.begin(); //Wire ライブラリを初期化し、I2C マスタとしてバスに接続 init_oled(); printTime(); setDay(); setTime(); } void loop() { writeData(r_sec); writeCommand(0x20+0x80); //2 行目の先頭 contrast_max(); //輝度を最大に設定 while(1){} } //----main end---- void writeData(byte t_data) { Wire.beginTransmission(OLED_ADRS); Wire.write(0x40); Wire.write(t_data); Wire.endTransmission(); delay(1); } void writeCommand(byte t_command) { Wire.beginTransmission(OLED_ADRS); Wire.write(0x00); Wire.write(t_command); Wire.endTransmission(); delay(10); } void contrast_max(){ writeCommand(0x2a);//RE=1 writeCommand(0x79);//SD=1 writeCommand(0x81);//コントラストセット writeCommand(0xFF);//輝度MAX writeCommand(0x78);//SD を0にもどす writeCommand(0x28); //2C=高文字 28=ノーマル delay(100); } void setTime(){ byte hour=(Serial.read()<<4); hour=hour+(Serial.read()&0x0F); byte minute=(Serial.read()<<4); minute=minute+(Serial.read()&0x0F); byte sec=(Serial.read()<<4); sec=sec+(Serial.read()&0x0F); Wire.beginTransmission(DS1307_ADDRESS); Wire.write(val); Wire.write(sec); Wire.write(minute); Wire.write(hour); Wire.endTransmission(); } void setDay(){ byte year=(Serial.read()<<4); year=year+(Serial.read()&0x0F); byte month=(Serial.read()<<4); month=month+(Serial.read()&0x0F); byte day=(Serial.read()<<4); day=day+(Serial.read()&0x0F); byte day_of_week=(Serial.read()&0x0F); Wire.beginTransmission(DS1307_ADDRESS); Wire.write(0x03); Wire.write(day_of_week); Wire.write(day); Wire.write(month); Wire.write(year); Wire.endTransmission(); } void printTime(){ Wire.beginTransmission(DS1307_ADDRESS); Wire.write(val); Wire.endTransmission(); Wire.requestFrom(DS1307_ADDRESS,7); byte r_sec=Wire.read(); byte r_minute=Wire.read(); byte r_hour=Wire.read(); byte r_day_of_week=Wire.read(); byte r_date=Wire.read(); byte r_month=Wire.read(); byte r_year=Wire.read(); } void init_oled() { delay(100); writeCommand(ClearDisplay); // Clear Display delay(20); writeCommand(ReturnHome); // ReturnHome delay(2); writeCommand(DisplayON); // Send Display on command delay(2); writeCommand(ClearDisplay); // Clear Display delay(20); }