by Caleb Helbling
Juniper is a functional reactive programming (FRP) language for the Arduino

Juniper is a functional reactive programming language for the Arduino that transpiles to Arduino compatible C++. The goal is to make concurrent Arduino programs easy to write and reason about. Arduino devices are typically too memory constrained to support operating systems, context switches, or coroutines. This adds an extra level of difficulty when writing these systems.

Juniper is designed to bring many functional programming features to the Arduino, including algebraic datatypes, type inference, type level integers (a flavor of dependent types), anonymous functions/lambdas and much more. Juniper supports inline C++, which makes it easy to interact with existing C++ Arduino drivers.

module Blink2
open(Io, Time)

/* In this example we have two LEDs blinking at different rates */

let boardLedA : uint16 = 13
let boardLedB : uint16 = 9

let mut timerStateA = Time:state
let mut timerStateB = Time:state

let mut ledStateA = low()
let mut ledStateB = low()

fun blink(interval, pin, inout timerState, inout ledState) =
    Time:every(interval, inout timerState) |>
    Signal:toggle(low(), high(), inout ledState) |>
    Io:digOut(pin)

fun loop() = {
    blink(1000, boardLedA, inout timerStateA, inout ledStateA)
    blink(700, boardLedB, inout timerStateB, inout ledStateB)
}

fun setup() = {
    Io:setPinMode(boardLedA, Io:output())
    Io:setPinMode(boardLedB, Io:output())
}
Information updated 11/26/23
Note: This entry has not yet been moderated.
View Comments