tinygo.org/x/drivers@v0.27.1-0.20240509133757-7dbca2a54349/examples/ds1307/time/main.go (about)

     1  package main
     2  
     3  import (
     4  	"machine"
     5  	"time"
     6  
     7  	"tinygo.org/x/drivers/ds1307"
     8  )
     9  
    10  func main() {
    11  	machine.I2C0.Configure(machine.I2CConfig{})
    12  	rtc := ds1307.New(machine.I2C0)
    13  	rtc.SetTime(time.Date(2019, 5, 15, 20, 34, 12, 0, time.UTC))
    14  
    15  	for {
    16  		t, err := rtc.ReadTime()
    17  		if err != nil {
    18  			println("Error reading date:", err)
    19  			break
    20  		}
    21  		println(t.Hour(), ":", t.Minute(), ":", t.Second(), " ", t.Day(), "/", t.Month(), "/", t.Year())
    22  
    23  	}
    24  
    25  }