From Céupédia
Jump to: navigation, search

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

1 Installation

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

2 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

2.1 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 as an output pin that accepts int values.

C symbols like HIGH and LOW must be preceded with an underscore.

2.2 Switching a LED

The second example, button1.ceu, 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;

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

2.3 Parallel blinking

The third example, blink3.ceu, 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;
       loop do
           emit PIN12 => _HIGH;
           await 500ms;
           emit PIN12 => _LOW;
           await 500ms;
       loop do
           emit PIN13 => _HIGH;
           await 250ms;
           emit PIN13 => _LOW;
           await 250ms;

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

3 Applications

3.1 Ship game

For a complete application, check the following blog post and source code repository:

   $ make CEUFILE=samples/ship.ceu