Céu-Arduino supports the development of Arduino applications in the programming language Céu:
- Source Code: https://github.com/fsantanna/ceu-arduino/
- Documentation: http://fsantanna.github.io/ceu-arduino/
- Chat: https://gitter.im/fsantanna/ceu
Arduino Arduino is an open-source project that created microcontroller-based kits for building digital devices and interactive objects that can sense and control physical devices.
Céu is a reactive language that aims to offer a higher-level and safer alternative to C:
Céu-Arduino empowers the development of Arduino applications with the following extensions:
- Awaiting events in direct/sequential style.
- Parallel lines of execution with
- safe abortion;
- deterministic behavior (in contrast with threads).
- Asynchronous loops for heavy computations.
- Interrupt-driven operation mode (optional and experimental).
- Seamless integration with standard Arduino (e.g.,
arduino-1.5 or higher:
$ git clone https://github.com/fsantanna/ceu-arduino $ cd ceu-arduino/
Compile and Upload
Makefile to point to your
ceu directory and then run
$ gedit Makefile $ make
Certify that your Arduino is connected to the USB.
If necessary, configure the variables in the
The default example blinks the on-board LED every second.
To compile and upload another application, run
make and set
$ make CEU_SRC=<path-to-ceu-application>
samples/ directory contains a number of examples.
Blinking a LED
blink-01.ceu assumes that a LED is connected to pin 13.
The program is an infinite
loop that intercalates between turning the LED
on and off in intervals of 1 second:
#include "arduino/arduino.ceu" // include standard declarations output int PIN_13; // PIN_13 is an output pin loop do // an infinite loop that: emit PIN_13(HIGH); // - turns the LED on await 1s; // - awaits 1 second emit PIN_13(LOW); // - turns the LED off await 1s; // - awaits another 1 second end // - repeats
Switching a LED
button-01.ceu requires a simple circuit with a switch button
connected to pin 2.
The program waits for changes on pin 2 (the switch), copying its value to pin 13 (the LED):
#include "arduino/arduino.ceu" input int PIN_02; output int PIN_13; emit PIN_13(LOW); loop do var int v = await PIN_02; emit PIN_13(v); end
Blinking in Parallel
blink-03.ceu requires two additional LEDs connected to
pins 11 and 12.
The program blinks the LEDs with different frequencies, in parallel:
#include "arduino/arduino.ceu" output int PIN_11; output int PIN_12; output int PIN_13; par do loop do emit PIN_11(HIGH); await 1s; emit PIN_11(LOW); await 1s; end with loop do emit PIN_12(HIGH); await 500ms; emit PIN_12(LOW); await 500ms; end with loop do emit PIN_13(HIGH); await 250ms; emit PIN_13(LOW); await 250ms; end end
Fading a LED
pwm-01.ceu assumes that a LED is connected to pin 11.
The program fades the LED from
255 and from
0 in two
#include "arduino/arduino.ceu" output u8 PWM_11; loop do var int i; loop i in [0->255] do emit PWM_11(i); await 5ms; end loop i in [0<-255] do emit PWM_11(i); await 5ms; end end
serial-01.ceu reads and write bytes from and to the serial in a
#include "arduino/arduino.ceu" input byte SERIAL; loop do var byte c = await SERIAL; _Serial.write(c); end
Céu can directly use standard Arduino functionality by prefixing its symbols
with an underscore (e.g.,
Switching a LED with Interrupts
isr-01.ceu is equivalent to
button-01.ceu but uses interrupts
instead of polling:
#include "arduino/arduino.ceu" input int PIN_02; output int PIN_13; spawn async/isr [_digitalPinToInterrupt(2),_CHANGE] do emit PIN_02(_digitalRead(2)); end emit PIN_13(LOW); loop do var int v = await PIN_02; emit PIN_13(v); end
async/isr is an interrupt service routine written in Céu.
It is attached to the interrupt number for pin 2
_digitalPinToInterrupt(2)) and is triggered whenever the pin changes value
The routine emits a
PIN_02 input to the application.
Examples that use interrupts have to be compiled with
make CEU_ISR=true CEU_SRC=samples/isr-01.ceu
Interrupts with Drivers
isr-08.ceu uses the interrupt drivers
pin-02.ceu from the library.
The program blinks the LED connected to pin 13 until the button connected to pin 02 is clicked. After another click, the blinking restarts.
#include "arduino/isr/timer.ceu" // timer ISR #include "arduino/isr/pin-02.ceu" // pin-02 ISR output int PIN_13; loop do watching PIN_02 do // aborts on click var int x = 0; every 500ms do // blinks every 500ms x = 1 - x; emit PIN_13(x); end end await 500ms; // debouncing await PIN_02; // restarts await 500ms; // debouncing end
The Game "Ship"
ship.ceu is described in a blog post: