-
Notifications
You must be signed in to change notification settings - Fork 0
Home
You can use this DSL either in a file or in interactive mode (iex
).
In both case, start with:
use ArduinoML
This imports all the DSL (functions, macros, operators).
You initialize your application with:
application "My super app!" # Initializes an application named "My super app!".
You can declare your sensors and actuators this way:
sensor button: 1 # The sensor :button is on the pin #1.
actuator led: 2 # The actuator :led is on the pin #2.
If you have analogical bricks, then you just need to precise it:
sensor temperature: 3, type: :analogic # The analogical sensor :temperature is on the pin #3.
actuator buzzer: 4, type: :analogic # The analogical actuator :buzzer in on the pin #4.
The DSL describe state machines running on Arduino cards. You will need to declare states and transitions.
# There is a state :released. On entry of this state, we turn the LED off.
state :released, on_entry: :led ~> :low
# There is a state :pressed. On entry of this state, we turn the LED on.
state :pressed, on_entry: :led ~> :high
# When we press the button and the state machine is in state :released, then it goes to :pressed.
transition from: :released, to: :pressed, when: is_high?(:button)
# When we release the button and the state machine is in state :pressed, then it goes to :released.
transition from: :pressed, to: :released, when: is_low?(:button)
An action is the setup of an actuator. Be careful with the values you put in because you cannot put analogical values into digital actuators and digital values into analogical actuators.
## DIGITAL.
# Set the LED to LOW level.
:led ~> :low
# Set the LED to HIGH level.
:led ~> :high
# Set the LED to the level of the button.
:led <~ :button
## ANALOGICAL
# Set the buzzer to level 4.
:buzzer ~> 4
# Set the buzzer to the level of the temperature.
:buzzer <~ :temperature
An assertions is something you want to verify on a sensor. Like the actions, be careful about the nature of the signal.
## DIGITAL
# Is the button at HIGH level?
is_high?(:button)
# Is the button at LOW level?
is_low?(:button)
# Are button #1 and button #2 at the same level?
:button1 <~> :button2
## DIGITAL
# Is the temperature lower than 57?
:temperature < 57
# Is the temperature equal to 57?
:temperature <~> 57
# Is the temperature greater than 57?
:temperature > 57
# Are temperature #1 and temperature #2 at the same level?
:temperature1 <~> :temperature2
Announce that you finished your description with:
finished! :show_me # Print the C code on the standard output.
# OR
finished! save_into: "path/to/code.c" # Save the C code into a file.
This will check the application validity before starting the code production.