Hardware
In Kog, a pin is a signal. useButton watches a GPIO input, useAnalogRead
streams ADC millivolts, and useDigitalWrite drives an output. All three are
fine-grained reactive values, so a pin edge updates the UI the same way
useState does. The same code runs unchanged on a real board.
The simulator gives you virtual hardware: press the button to drive GPIO pin 0 (BOOT on a real board), and drag the slider to feed millivolts into the ADC on pin 34 (the light sensor on a CYD).
Hold the button. Each press bumps the counter, cycles the RGB LED through
red → green → blue (pins 4/16/17, the CYD's onboard LED, active-low), and logs
to the console panel. Move the slider and watch the adc: … mV readout track
it. This is the shipped examples/hardware-demo, seeded from source.
Discrete LEDs and PWM brightness
Hold BOOT to light the red LED. Move the ADC slider to set the green LED's brightness. Disable LEDs turns both off. These are actual GPIO and PWM outputs observed from the simulator's hardware state, rather than colored dots driven directly by UI state.
useDigitalRead exposes the raw input level, useDigitalWrite returns an accessor and setter, and usePWM owns a native PWM channel. Its duty method accepts a fraction from 0 to 1. The CYD's LEDs are active-low, so a duty of 1 is off. These hooks claim their pins at mount and release them at unmount; the gpio(number) helper validates a pin identifier.
Studio and widgets automatically discover pins claimed by the running app, including watched digital inputs, subscribed ADC inputs, and PWM outputs. Input controls inject GPIO edges and ADC samples; output indicators read digital levels or PWM duty. CYD pins 4/16/17 appear as active-low red, green, and blue LEDs. For other outputs, choose an LED color and polarity or use Connect an RGB LED to assign its three channels. On a real board, choose pins that are not reserved by display, flash, or other peripherals.
Owning hardware resources directly
The same behavior can be built with the imperative API. This version claims each pin, reads its initial state, registers edge and ADC subscriptions, and creates a PWM channel. Its effect cleanup stops subscriptions, closes PWM, and releases every successful claim. A hardware error appears on screen with its stable code.
For imperative claim/release, digitalRead/digitalWrite, watch, analogRead, adc.subscribe, and pwm.open, see the complete hardware guide. I2C and SPI require a real attached peripheral; browser controls do not pretend to emulate a sensor bus. Always close channels, stop subscriptions, and release claims in effect cleanup.