github.com/tinygo-org/tinygo@v0.31.3-0.20240404173401-90b0bf646c27/src/examples/uart/uart.go (about)

     1  // This reads from UART1 and outputs to default serial, usually UART0 or USB.
     2  // Example of how to work with UARTs other than the default.
     3  package main
     4  
     5  import (
     6  	"machine"
     7  	"time"
     8  )
     9  
    10  var (
    11  	uart = machine.UART1
    12  	tx   = machine.UART1_TX_PIN
    13  	rx   = machine.UART1_RX_PIN
    14  )
    15  
    16  func main() {
    17  	uart.Configure(machine.UARTConfig{TX: tx, RX: rx})
    18  	for {
    19  		if uart.Buffered() > 0 {
    20  			data, _ := uart.ReadByte()
    21  			print(string(data))
    22  		}
    23  		time.Sleep(10 * time.Millisecond)
    24  	}
    25  }