Code Style

Code Styles are for advanced users that want to have more control how the code that is generated by Automaduino looks like.

Code Style is a feature that allows you to change how your code looks. This is not relevant for beginners, but once you want to expand on the generated code it is important to know which style you prefer. The default style the Functions mode.

Functions

The default style for the editor. This code is easy to read and to edit. It is longer compared to the abridged version tho.

  • All states generate their own function based on their name.
  • To move from one state to the next the function of the following state is called.

Abridged

The abridged style is the shortest available style. Here all code is generated within the loop function - This is similar to the style that is usually found in tutorials. For more complex projects this makes the code harder to understand.

  • All states generate only the necessary Arduino function.
  • There are no explicit transitions - The code for the following state is interlocked in the loop.

Switch

The switch version is the most true to the thought of finite state automata. Here we apply a switch machine in the loop function and set a state variable in the functions to move from one state to the next. This works as once a function execution is done, the loop function will take over again and, based on the updated state, call the corresponding function. Compared to the other styles this execution is the cleanest, but also harder to understand for beginners than the Functions mode.

  • All states generate their own function based on their name.
  • A state variable is added that controls the current state of the program.
  • To move from one state to the next the state variable is manipulated in the function.
  • Once the code execution is done the loop function takes over and acts according to the current state.

See below how the code style affects the code generation for the Blink Example.

//Imports:

//Pins:
int pin_0_led = 7;

void setup() { 
pinMode(pin_0_led, OUTPUT);
}

void loop() {
function_0_led();
}

void function_0_led(){
digitalWrite(pin_0_led, HIGH);
delay(1000);
function_1_led();
}

void function_1_led(){
digitalWrite(pin_0_led, LOW);
delay(1000);
function_0_led();
}

  
//Imports:

//Pins:
int pin_0_led = 7;

void setup() { 
pinMode(pin_0_led, OUTPUT);
}

void loop() {
while(true){
digitalWrite(pin_0_led, HIGH);
delay(1000);
digitalWrite(pin_0_led, LOW);
}
}

  
//Imports:

//Pins:
int pin_0_led = 7;

int state = 0;
void setup() { 
pinMode(pin_0_led, OUTPUT);
}

void loop() {
switch(state){
case 0:
function_0_led();
break;
case 1:
function_1_led();
break;
default:
break;
}
}

void function_0_led(){
digitalWrite(pin_0_led, HIGH);
delay(1000);
state = 1;
}

void function_1_led(){
digitalWrite(pin_0_led, LOW);
delay(1000);
state = 0;
}

  
Last modified April 1, 2022: finished english documentation (1e3866c)