mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-06 20:13:40 +00:00
atmega2560: support UART1-3
+ example for uart
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
// 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)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user