mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-03 02:27:48 +00:00
65b085a5d5
Signed-off-by: deadprogram <ron@hybridgroup.com>
43 lines
816 B
Go
43 lines
816 B
Go
// This is a echo console running on the device UART.
|
|
// Connect using default baudrate for this hardware, 8-N-1 with your terminal program.
|
|
package main
|
|
|
|
import (
|
|
"machine"
|
|
"time"
|
|
)
|
|
|
|
var (
|
|
uart = machine.Serial
|
|
)
|
|
|
|
func main() {
|
|
// use default settings for UART
|
|
uart.Configure(machine.UARTConfig{})
|
|
uart.Write([]byte("Echo console enabled. Type something then press enter:\r\n"))
|
|
|
|
input := make([]byte, 64)
|
|
i := 0
|
|
for {
|
|
if uart.Buffered() > 0 {
|
|
data, _ := uart.ReadByte()
|
|
|
|
switch data {
|
|
case 13:
|
|
// return key
|
|
uart.Write([]byte("\r\n"))
|
|
uart.Write([]byte("You typed: "))
|
|
uart.Write(input[:i])
|
|
uart.Write([]byte("\r\n"))
|
|
i = 0
|
|
default:
|
|
// just echo the character
|
|
uart.WriteByte(data)
|
|
input[i] = data
|
|
i++
|
|
}
|
|
}
|
|
time.Sleep(10 * time.Millisecond)
|
|
}
|
|
}
|