switch(page_num)
{
case 1:
lcd.clear();
lcd.setCursor(4, 0);
lcd.print(rtc.getTimeStr());
// Display abbreviated Day-of-Week in the lower left corner
lcd.setCursor(0, 1);
lcd.print(rtc.getDOWStr(FORMAT_SHORT));
// Display date in the lower right corner
lcd.setCursor(6, 1);
lcd.print(rtc.getDateStr());
// Wait one second before repeating :)
delay (1000);
break;
case 2:
lcd.setCursor(0, 0);
lcd.print("test");
break;
}
}
void rtc_setup(int yr, int mnth, int dy, int hr, int mnt, int scnd, int dyow)
{
rtc.setDOW(dyow); // Set Day-of-Week to FRIDAY
rtc.setTime(hr, mnt, scnd); // Set the time to 12:00:00 (24hr format)
rtc.setDate(dy, mnth, yr); // Set the date to August 6th, 2010
}
include
include
include
include
const int sd_cs = 10;
const int rtc_clk = 6; const int rtc_dat = 5; const int rtc_rst = 4;
const int joystick_x = A0; const int joystick_y = A1; const int joystick_sw = 3;
const int com_tx = 0; const int com_rx = 7; const int com_dtr = 2; const int com_dtr_led = 9;
//int jostick_x_axix; //int jostick_y_axix; //int jostick_sw_state;
const int min_page_num = 1; const int max_page_num = 2;
SoftwareSerial com(com_rx, com_tx); LiquidCrystal_I2C lcd(0x3F, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); DS1302 rtc(rtc_rst, rtc_dat, rtc_clk);
void setup() {
pinMode(joystick_x, INPUT); pinMode(joystick_y, INPUT); pinMode(joystick_sw, INPUT); pinMode(com_dtr, INPUT); pinMode(com_dtr_led, OUTPUT);
//joystick_x_axix = map(analogRead(joystick_x), 0, 1023, 0, 100); //joystick_y_axix = map(analogRead(joystick_y), 0, 1023, -50, 50); //joystick_sw_state = digitalRead(joystick_sw);
digitalWrite(com_dtr_led, HIGH);
rtc.halt(false); rtc.writeProtect(false);
lcd.begin(16, 2); com.begin(115200); Serial.begin(9600);
if(digitalRead(com_dtr) == HIGH) { digitalWrite(com_dtr_led, HIGH); }
rtc_setup(2019, 02, 03, 17, 00, 00, SUNDAY); //comment this line out if you are uploaded the code once }
void loop() { int joystick_x_axix = map(analogRead(joystick_x), 0, 1023, 0, 100); int joystick_y_axix = map(analogRead(joystick_y), 0, 1023, -50, 50); int joystick_sw_state = digitalRead(joystick_sw);
int page_num = 1;
if(joystick_x_axix >= 10) { if(!page_num > max_page_num) { page_num++; } else { page_num = min_page_num; } } else if(joystick_x_axix <= -10) { if(!page_num < min_page_num) { page_num--; } else { page_num = max_page_num;
} }
switch(page_num) { case 1: lcd.clear(); lcd.setCursor(4, 0); lcd.print(rtc.getTimeStr());
} }
void rtc_setup(int yr, int mnth, int dy, int hr, int mnt, int scnd, int dyow) { rtc.setDOW(dyow); // Set Day-of-Week to FRIDAY rtc.setTime(hr, mnt, scnd); // Set the time to 12:00:00 (24hr format) rtc.setDate(dy, mnth, yr); // Set the date to August 6th, 2010 }
bigproj.zip