Skip to main content

Wire

digitalWrite, digitalRead, pinMode functions are provided for Arduino-like digital IO.

pinMode

Sets the pin input/output and pull up/down mode.

import { gpio } from "@devicescript/core"
import { GPIOMode } from "@devicescript/core"
import { pinMode } from "@devicescript/gpio"

const pin = gpio(0)
pinMode(pin, GPIOMode.Output)

digitalWrite

For digital output, you can use digitalWrite function.

import { gpio } from "@devicescript/core"
import { HIGH, GPIOMode } from "@devicescript/core"
import { pinMode, digitalWrite } from "@devicescript/gpio"

const pin = gpio(0)
pinMode(pin, GPIOMode.Output)

digitalWrite(pin, true)
digitalWrite(pin, 1)
digitalWrite(pin, HIGH)

digitalRead

For digital input, you can use digitalRead function.

import { gpio } from "@devicescript/core"
import { GPIOMode } from "@devicescript/core"
import { pinMode, digitalRead } from "@devicescript/gpio"

const pin = gpio(0)
pinMode(pin, GPIOMode.Input)

const value = digitalRead(pin)

subscribeDigital

You can also subscribe to digital input changes.

import { gpio } from "@devicescript/core"
import { GPIOMode } from "@devicescript/core"
import { pinMode, subscribeDigital } from "@devicescript/gpio"

const pin = gpio(0)
pinMode(pin, GPIOMode.Input)

subscribeDigital(pin, value => console.data({ value }))