mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-05 03:27:48 +00:00
c119721e3b
+ example for uart
26 lines
471 B
Go
26 lines
471 B
Go
// This reads from UART1 and outputs to default serial, usually UART0 or USB.
|
|
// Example of how to work with UARTs other than the default.
|
|
package main
|
|
|
|
import (
|
|
"machine"
|
|
"time"
|
|
)
|
|
|
|
var (
|
|
uart = machine.UART1
|
|
tx = machine.UART1_TX_PIN
|
|
rx = machine.UART1_RX_PIN
|
|
)
|
|
|
|
func main() {
|
|
uart.Configure(machine.UARTConfig{TX: tx, RX: rx})
|
|
for {
|
|
if uart.Buffered() > 0 {
|
|
data, _ := uart.ReadByte()
|
|
print(string(data))
|
|
}
|
|
time.Sleep(10 * time.Millisecond)
|
|
}
|
|
}
|