Quantcast
Channel: Sensors - Arduino Forum
Viewing all articles
Browse latest Browse all 1069

Hello, I wanted to increase the current hours, but there is an error and I do not know what it is

$
0
0
#include <Adafruit_SSD1306.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <RTClib.h>
RTC_DS3231 rtc;
byte settings = 0;
byte off_zzz = 0;
int m = 0;
int h = 0; 
#define settings_button 3
#define off_button 4
#define zero_button 2
#define light_button 6
#define zzz_pin 5
#define light_rely 7
#define led 8
#define water_low 12
#define water_high 11
#define water_analog 10
#define x_button A1
#define y_button A0
int x_read;
int y_read;
Adafruit_SSD1306 display(128,64,&Wire, -1);
void setup() {
  Wire.begin();
  rtc.begin();
  DateTime now = DateTime(2024, 9, 20, 23, 33, 0);
  rtc.adjust(now);
display.begin(SSD1306_SWITCHCAPVCC, 0x3c);
display.setTextColor(WHITE);

pinMode(zero_button, INPUT);
pinMode(settings_button, INPUT);
pinMode(off_button, INPUT);
pinMode(light_button, INPUT);
pinMode(zzz_pin, OUTPUT);
pinMode(light_rely, OUTPUT);
pinMode(led, OUTPUT);
pinMode(water_low, OUTPUT);
pinMode(water_high, OUTPUT);
pinMode(water_analog, OUTPUT);
}

void loop() {
  DateTime now = rtc.now();
  x_read = analogRead(x_button);
  y_read = analogRead(y_button);
display.clearDisplay();
display.setTextSize(3);
display.setCursor(0,0);
display.print(now.hour());display.print(":");
display.print(now.minute());
display.setTextSize(2);
display.setCursor(90,6);
display.print(now.second());
display.setTextSize(3);
display.setCursor(10,32);
display.print(h);display.print(":");
display.print(m);
display.display();
// إذا كان إكس أو واي أصغر من 200 أوأكبر من 900
if(digitalRead(settings_button) == 1){
  settings = settings+1;
}
if(settings == 1){
  digitalWrite(led, 1);
  display.setCursor(110,0);
  display.print("!");
  if(x_read > 900){
    now.minute()++;
    rtc.adjust(now);
  }
//   if(x_read < 200){

//   }
//   if(y_read > 900){

//   }
//   if(y_read < 200){

//   }
//   if(zero_button == 1){

//   }
// }
// if(settings == 2){
//   display.setCursor(110,0);
//   display.print(" ");
//   display.setCursor(110,32);
//   display.print("!");
//   if(x_read > 900){
//     m++;
//     if(m == 60){
//   m = 0;
//  }
//   }
//   if(x_read < 200){
//     m--;
//      if(m == -1){
//   m = 59;
//  }
//   }
//   if(y_read > 900){
//     h--;
//     if(h == -1){
//   h = 23;
//  }
//   }
//   if(y_read < 200){
//     h++;
//     if(h == 24){
//   h = 0;
//  }
//   }
// }
// if(settings == 3){
//    display.setCursor(110,32);
//   display.print(" ");
//   digitalWrite(led, 0);
//   settings = 0;
// } 
 display.display();
 
 
 

delay(200);
}

3 posts - 3 participants

Read full topic


Viewing all articles
Browse latest Browse all 1069

Trending Articles