KryonOSDocs
Hardware & Peripherals

Hardware GPIO

Direct digital/analog pin control, interrupts, and hardware timings from JavaScript.

4. Hardware GPIO (General Purpose Input/Output)

KryonOS enables direct hardware control of the ESP32 microcontroller pins via System.gpio.

Constants

  • System.gpio.INPUT
  • System.gpio.OUTPUT
  • System.gpio.INPUT_PULLUP
  • System.gpio.HIGH
  • System.gpio.LOW

Functions

System.gpio.pinMode(pin, mode)

  • Parameters: pin (Integer hardware pin number), mode (GPIO Constant)
  • Description: Sets the physical electrical state of an ESP32 pin (e.g. setting pin 2 to OUTPUT to drive an LED).

System.gpio.digitalWrite(pin, state)

  • Parameters: pin (Integer), state (HIGH or LOW)
  • Description: Outputs 3.3V (HIGH) or 0V (LOW) to a specific pin.

System.gpio.digitalRead(pin)

  • Parameters: pin (Integer)
  • Returns: Integer (1 for HIGH, 0 for LOW)
  • Description: Reads the physical voltage state of a pin.

System.gpio.analogRead(pin)

  • Parameters: pin (Integer)
  • Returns: Integer (0 to 4095)
  • Description: Triggers the ESP32 12-bit Analog-to-Digital Converter (ADC) to read a continuous voltage level.

System.gpio.analogWrite(pin, pwmValue)

  • Parameters: pin (Integer), pwmValue (0 to 255)
  • Description: Initiates an automatic hardware PWM (Pulse Width Modulation) signal on a pin. Useful for motor control or dimming LEDs.

System.gpio.pulseIn(pin, state, [timeout])

  • Parameters: pin (Integer), state (HIGH or LOW), timeout (Optional Integer in microseconds, defaults to 1,000,000)
  • Returns: Integer (Length of the pulse in microseconds, or 0 if timeout occurred)
  • Description: Native Hardware Pulse Measurement. Suspends the JS engine and delegates to the C++ Kernel to accurately measure the duration of an incoming hardware pulse. This bypasses the JavaScript execution overhead entirely, giving you absolute microsecond precision (crucial for reading HC-SR04 ultrasonic sensors).