The Arduino Uno is a popular platform for “physical computing” and first steps in embedded computing. It is based on an 8-bit Atmega microcontroller and ships with a powerful hardware abstraction library. Currently, the Mita Arduino Uno platform supports basic functionality, namely working with buttons and GPIO pins.
Sensor: button_one (Button)
Modalities
Name | Description |
is_pressed : bool |
True if the button is pressed in this very right moment. False otherwise. |
Events
Name | Description |
pressed |
Fires after the button was pressed. |
released |
Fires after the button was released. |
Sensor: button_two (Button)
Modalities
Name | Description |
is_pressed : bool |
True if the button is pressed in this very right moment. False otherwise. |
Events
Name | Description |
pressed |
Fires after the button was pressed. |
released |
Fires after the button was released. |
Buses: GPIO
Can be used to write and read digital ports, as known from the Arduino Uno
Signals
Name | Description | Parameters |
pinMode : bool |
|
##Example
This example uses the first button connected to the hardware Pin 1 and two leds connected to pin 12 and 13. The yellow led can get turned off by pressing the button one and turned off again by pressing the button again. The red led will get turned on for one second and then turned off for one second.
package main;
import platforms.arduino.uno;
setup hmi : GPIO {
var yellow = pinMode(p13, OUTPUT);
var red = pinMode(p12, OUTPUT);
}
every button_one.pressed {
if(hmi.yellow.read() == false) {
hmi.yellow.write(true);
} else {
hmi.yellow.write(false);
}
}
every 1 second {
if(hmi.red.read() == false) {
hmi.red.write(true);
} else {
hmi.red.write(false);
}
}
##Interrupt controlled event loop
Instead of using an event queue, as the XDK 110 does, we have implemented a control with boolean flags. Each event, such as timed events or the pressed and released event, are captured in their own ISR. Within the context of the ISR single flags will be set for each occurred event. The flags will be handled in an endless loop, after the initialization of the Arduino Uno.
In the example a flag will be used for the event of 1 second and the pressed event of the button_one.
while(1) {
if (getHandleEvery1Second1_flag() == true){
setHandleEvery1Second1_flag(false);
HandleEvery1Second1();
}
if (getHandleEveryButton_onePressed1_flag() == true){
setHandleEveryButton_onePressed1_flag(false);
HandleEveryButton_onePressed1();
}
}
As mentioned before, the flags are set in the ISR:
ISR(INT1_vect){
volatile int oldState = 0;
volatile int currentState = 0;
oldState = (PIND & _BV(PIND3)) > 0 ? HIGH : LOW;
// delay for debounce could be placed here
currentState = (PIND & _BV(PIND3)) > 0 ? HIGH : LOW;
if (LOW == oldState && LOW == currentState) {
ButtonTwoPressed(true);
} else if (HIGH == oldState && HIGH == currentState){
ButtonTwoReleased(true);
}
}
##How to use the Arduino Uno platform
Mita-generated code for the Arduino platform requires a small runtime library which is located in the Arduino platform package /org.eclipse.mita.platform.arduino.uno/ArduinoMitaRuntime. To use this runtime, and to compile/flash the generated code, we have found the AVR Plugin handy. We have listed the steps we use below:
- Create a new C Project
- Choose an AVR project
- Set up the atmega 328p (Arduino Uno)
- Add a new file with .mita extension
- After creating a .mita file, a wizard will be opened to convert as the project as a Xtext project. Click on Yes. You also can edit the nature in the .project file.
- Add Paths & Symbols (src-gen, base and folder, which contains the ArduinoMitaRuntime files). Therefore, right click the project and open the Properties. Open C/C++ Build and open Paths & Symbols.
- Set up Programmer - can be found in the project properties under AVR
- Create your application
- Compile & flash