Skip to content

egallesio/ArduinoML-scheme

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ArduinoML implementation in Scheme

This directory is a quick and dirty implementation of ArduinoML in Scheme.

For the the implementation of the ArduinoML, we use here a simple Scheme (non hygienic) macro.

Define-application special form

Syntax

The following example exhibits the various aspects of the define-application special form:

(define-application Example_with_two_leds
  :sensors
  ((button 9))
  :actuators
  ((led1 11)
   (led2 12))
  :states
  ((on  (set! led1 "HIGH") (set! led2 "LOW"))
   (off (set! led1 "LOW")  (set! led2 "HIGH")))
  :transitions
  ((on -> off when button "HIGH")
   (off -> on when button "HIGH"))
  :initial
  off)

Using the define-application form

We have two implementations of the define-application special form:

Some tests are present in thedirectory Examples. To produce (on the standard output) the arduino code for the file Examples/example1.scm, you need to enter:

  • for STklos

    $ stklos -c -l arduino.scm -f Examples/example1.scm 
  • for Gauche

    $ gosh -I. -l arduino.scm Examples/example1.scm
  • for GNU Guile (the sed command used here are sed to

    $ guile --no-auto-compile -l arduino.scm -s Examples/example1.scm
  • for Racket (be sure to use arduino.ss instead of arduino.scm)

    $ racket -f arduino.ss -f Examples/example1.scm

Code produced

The code produced by define-application for the previous example is:

// File generated by arduinoML (Scheme)

long time = 0;
long debounce = 200;

int button = 9;
int led1 = 11;
int led2 = 12;

void setup() {
  pinMode(button, "INPUT");
  pinMode(led1, "OUTPUT");
  pinMode(led2, "OUTPUT");
}

void state_on() {
  digitalWrite(led1, HIGH);
  digitalWrite(led2, LOW);
  boolean guard =  millis() - time > debounce;
  if (digitalRead(button) == HIGH  && guard) {
    time = millis()
    state_off();
  } else {
    state_on();
  }
}

void state_off() {
  digitalWrite(led1, LOW);
  digitalWrite(led2, HIGH);
  boolean guard =  millis() - time > debounce;
  if (digitalRead(button) == HIGH  && guard) {
    time = millis()
    state_on();
  } else {
    state_off();
  }
}

void loop () {
   state_off();
}

Testing the define-application form

To run some tests with various Scheme implementations, you can type make in the current directory. This will try to launch the compilation of the files in the Examples directory with the following Scheme implementations:

  • STklos
  • Gauche
  • Gnu Guile
  • Racket

A bunch of files will be created in the OUT directory. Every file with the same prefix should have the same MD5 signature.

To clean the directory: make clean

About

An implementation of ArduinoML using Scheme

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published