Hello.
I hope someone here can help me.
I am trying to build a "Best before date- calculator" for my work using a Pi pico, an RTC-module(DS1307) and an 2x16 lcd display.
(we are making sandwishes and other food on our own so we have to mark them with date... )
I can get todays date to be displayed on the LCD so everything works so far![Wink ;)]()
My problem is that I want to, when I push a button, change the date to go 5 days ahead of todays date and then display it to the LCD...
I have tried to serach in different places on the net but couldn't find any solutions so I ask here to see if someone here is able to help me![Smile :)]()
here is the code that I'm using:
The code "works" but when I push the button it shows the same date as at the start, It's just the text that changes.
I know that it is because I have the same string (date, month, year) on both the main loop and the function but I can't figure out hove to change the function to display the date 5 days forward...![Sad :(]()
Any suggestions anyone?
I hope someone here can help me.
I am trying to build a "Best before date- calculator" for my work using a Pi pico, an RTC-module(DS1307) and an 2x16 lcd display.
(we are making sandwishes and other food on our own so we have to mark them with date... )
I can get todays date to be displayed on the LCD so everything works so far

My problem is that I want to, when I push a button, change the date to go 5 days ahead of todays date and then display it to the LCD...
I have tried to serach in different places on the net but couldn't find any solutions so I ask here to see if someone here is able to help me

here is the code that I'm using:
Code:
from machine import I2C, Pinfrom urtc import DS1307from time import sleep# from datetime import date, timedeltafrom pico_i2c_lcd import I2cLcdi2c_lcd = I2C(id=1,scl=Pin(3),sda=Pin(2),freq=100000)lcd = I2cLcd(i2c_lcd, 0x27, 2, 16)i2c_rtc = I2C(0,scl = Pin(17),sda = Pin(16),freq = 400000)result = I2C.scan(i2c_rtc)rtc = DS1307(i2c_rtc)(year,month,date,day,hour,minute,second,p1)=rtc.datetime()button = machine.Pin(14, machine.Pin.IN, machine.Pin.PULL_UP)def plusnio(): lcd.clear() lcd.move_to(3,0) lcd.putstr("Bast Fore") lcd.move_to(0,1) lcd.putstr("Datum:") lcd.move_to(6,1) lcd.putstr(str(date) + "/" + str(month) + "/" + str(year)) sleep(5)while True: (year,month,date,day,hour,minute,second,p1)=rtc.datetime() lcd.move_to(3,0) lcd.putstr("Valkommen") lcd.move_to(0,1) lcd.putstr("Datum:") lcd.move_to(6,1) lcd.putstr(str(date) + "/" + str(month) + "/" + str(year)) if button.value() ==0: plusnio() sleep(0)
I know that it is because I have the same string (date, month, year) on both the main loop and the function but I can't figure out hove to change the function to display the date 5 days forward...

Any suggestions anyone?
Statistics: Posted by per.danielsson — Wed Nov 27, 2024 10:20 am