1. Home
  2. /
  3. Tinygo
  4. /
  5. Read Analog Sensor

Read Analog Sensor - Tinygo Typing CST Test

Loading…

Read Analog Sensor — Tinygo Code

Read a potentiometer on pin A0 and print the value to the serial console.

package main

import (
	"machine"
	"time"
	"fmt"
)

func main() {
	sensor := machine.ADC{Pin: machine.A0}
	sensor.Configure()
	for {
		value := sensor.Get()
		fmt.Println("Sensor value:", value)
		time.Sleep(200 * time.Millisecond)
	}
}

Tinygo Language Guide

TinyGo is a Go compiler designed for small devices, microcontrollers, WebAssembly, and other constrained environments. It enables developers to write Go code that can run efficiently on hardware with limited resources.

Primary Use Cases

  • ▸Programming microcontrollers and IoT devices in Go
  • ▸Compiling Go code to WebAssembly for web applications
  • ▸Rapid prototyping of embedded hardware projects
  • ▸Creating low-memory, low-power applications
  • ▸Teaching and experimenting with Go on constrained hardware

Notable Features

  • ▸Small runtime footprint optimized for microcontrollers
  • ▸Cross-compilation to multiple architectures
  • ▸Support for WebAssembly output
  • ▸Integration with Arduino and other embedded boards
  • ▸Subset of Go standard library tailored for constrained devices

Origin & Creator

TinyGo was created by Jonathan Wright and contributors to extend the Go programming language to microcontrollers and WebAssembly in the 2010s.

Industrial Note

TinyGo is niche within embedded systems, IoT development, and WebAssembly applications where full Go runtime is too heavy or memory-limited devices are used.

More Tinygo Typing Exercises

Blink an LEDControl Servo Motor

Practice Other Languages

CReactPythonC++RustTypeScriptKotlinPHPJavaC#RubyMqlCqlN1qlCypher