Arduino

This page is about running the Céu programming language under the Arduino platform.

Installation
You can either download a virtual machine preloaded with Céu, or install it manually from the git repository:


 * Céu in a Box virtual machine
 * https://github.com/fsantanna/ceu-arduino

Examples
The distribution comes with some samples ready for playing with Céu.

After the installation, open a terminal window and adjust the Makefile to refer to your board:

$ cd ceu-arduino/ $ vi Makefile

Blinking a LED
The first example, blink1.ceu, assumes that a LED is connected to pin 13:

output int PIN13;             // PIN13 is an output pin loop do                       // an infinite loop that: emit PIN13 => _HIGH;      //   - turns the LED on        await 1s;                  //   - awaits 1 second emit PIN13 => _LOW;       //   - turns the LED off await 1s;                 //   - awaits another 1 second end                           //   - repeats

To compile and upload it to your board, run the following command:

$ make CEUFILE=samples/blink1.ceu

Observe the behavior of the program in the video on the right.

The program is a loop that sets PIN13 to HIGH, then awaits 1 second, then sets PIN13 to LOW, then awaits another second, and repeats the process over and over.

Just like with regular Arduino programming, every pin must be configured to work in input or output mode. Céu uses input and output events for this purpose. In the example, the first line configures PIN13</tt> as an output pin that accepts int</tt> values.

C symbols like HIGH</tt> and LOW</tt> must be preceded with an underscore.

Switching a LED
The second example, button1.ceu</tt>, requires a simple circuit with a switch button connected to pin 2.

$ make CEUFILE=samples/button1.ceu

The program waits for changes on pin 2 (the switch), copying its value to pin 13 (the LED):

input int PIN02; output int PIN13; emit PIN13 => _HIGH; loop do       int v = await PIN02; emit PIN13 => v;   end

Now, we also use an input event to read int</tt> values from PIN2</tt>. Whenever its value changes, the command await PIN02</tt> resumes and sets v</tt>, which is copied to PIN13</tt>.

Parallel blinking
The third example, blink3.ceu</tt>, requires two additional LEDs connected to pins 11 and 12.

$ make CEUFILE=samples/blink3.ceu

The program blinks three LEDs with different frequencies, in parallel:

output int PIN11; output int PIN12; output int PIN13; par do       loop do            emit PIN11 => _HIGH; await 1s; emit PIN11 => _LOW; await 1s; end with loop do           emit PIN12 => _HIGH; await 500ms; emit PIN12 => _LOW; await 500ms; end with loop do           emit PIN13 => _HIGH; await 250ms; emit PIN13 => _LOW; await 250ms; end end

The par</tt> statement of Céu allows that multiple lines of execution run concurrently in the same program.

Ship game
For a more complete example, check the following blog post:


 * http://thesynchronousblog.wordpress.com/2012/07/08/ceu-arduino/