github.com/tinygo-org/tinygo@v0.31.3-0.20240404173401-90b0bf646c27/src/examples/echo2/echo2.go (about) 1 // This is a echo console running on the os.Stdin and os.Stdout. 2 // Stdin and os.Stdout are connected to machine.Serial in the baremetal target. 3 // 4 // Serial can be switched with the -serial option as follows 5 // 1. tinygo flash -target wioterminal -serial usb examples/echo2 6 // 2. tinygo flash -target wioterminal -serial uart examples/echo2 7 // 8 // This example will also work with standard Go. 9 package main 10 11 import ( 12 "bufio" 13 "fmt" 14 "os" 15 ) 16 17 func main() { 18 fmt.Printf("Echo console enabled. Type something then press enter:\r\n") 19 20 scanner := bufio.NewScanner(os.Stdin) 21 22 for { 23 msg := "" 24 fmt.Scanf("%s\n", &msg) 25 fmt.Printf("You typed (scanf) : %s\r\n", msg) 26 27 if scanner.Scan() { 28 fmt.Printf("You typed (scanner) : %s\r\n", scanner.Text()) 29 } 30 } 31 }