Reading
#struct ReadingA date and time: year, month, day, weekday, hour, minute and second.
| Name | Type | Description |
|---|---|---|
year | int = 2000 | The full year, such as 2026. The chip stores only two digits and Now adds 2000. |
month | int = 1 | The month, 1 to 12. |
day | int = 1 | The day of the month, 1 to 31. |
weekday | int = 1 | The day of the week, 1 to 7. Which day is 1 is up to the program. |
hour | int = 0 | The hour, 0 to 23. Now reads a chip set to 12-hour mode and converts it. |
minute | int = 0 | The minute, 0 to 59. |
second | int = 0 | The second, 0 to 59. |
import hw.i2c
import hw.ds1307
func main:
clock := ds1307.Open(i2c.Open(0))
println ds1307.ADDRESS, ds1307.Detected(clock)
r := ds1307.Make(2026, 12, 3, 4, 21, 45, 9)
println ds1307.Format(r)
println ds1307.Set(clock, r)
println ds1307.Format(ds1307.Now(clock))
println ds1307.Running(clock)
println ds1307.Halt(clock), ds1307.Running(clock)
end104 false 2026-12-03 21:45:09 true 2026-12-03 21:45:09 true true false