|
21 | 21 | #define fim_algoritmo PREVENT_SEMICOLON_ERROR }
|
22 | 22 |
|
23 | 23 | // Recreate lasso to apear more like portugol
|
24 |
| -#define se PREVENT_SEMICOLON_ERROR if( |
| 24 | +#define se PREVENT_SEMICOLON_ERROR if( |
25 | 25 | #define entao ){
|
26 | 26 | #define senaose PREVENT_SEMICOLON_ERROR } else if (
|
27 | 27 | #define senao PREVENT_SEMICOLON_ERROR } else {
|
|
41 | 41 | // Just types
|
42 | 42 | #define numerico0() int
|
43 | 43 | #define decimal0() float
|
| 44 | +#define caractere0() char |
| 45 | +#define logico0() bool |
44 | 46 |
|
45 | 47 | // Redefine types
|
46 | 48 | #define declareType(_TYPE, _NAME) PREVENT_SEMICOLON_ERROR _TYPE _NAME;
|
47 | 49 | #define numerico1(_NAME) declareType(int, _NAME)
|
48 | 50 | #define decimal1(_NAME) declareType(float, _NAME)
|
49 |
| - |
50 |
| -// Vector Initialization |
51 |
| -#define vetor(_TYPE, _NAME, _SIZE, ...) PREVENT_SEMICOLON_ERROR _TYPE _NAME[_SIZE + 1] PREPEND_EQUAL_IF_NONEMPTY(__VA_ARGS__); |
52 |
| -//#define vetor(...) GET_MACRO(_, ##__VA_ARGS__, vetor4, vetor3, _, _, _)(__VA_ARGS__) |
| 51 | +#define caractere1(_NAME) declareType(char, _NAME) |
| 52 | +#define logico1(_NAME) declareType(bool, _NAME) |
53 | 53 |
|
54 | 54 | // Types with values
|
55 | 55 | #define declareTypeValue(_TYPE, _NAME, _VALUE) PREVENT_SEMICOLON_ERROR _TYPE _NAME = _VALUE;
|
56 | 56 | #define numerico2(_NAME, _VALUE) declareTypeValue(int, _NAME, _VALUE)
|
57 | 57 | #define decimal2(_NAME, _VALUE) declareTypeValue(float, _NAME, _VALUE)
|
| 58 | +#define caractere2(_NAME, _VALUE) declareTypeValue(char, _NAME, _VALUE) |
| 59 | +#define logico2(_NAME, _VALUE) declareTypeValue(bool, _NAME, _VALUE) |
58 | 60 |
|
59 | 61 | // Overloaded declare functions
|
60 | 62 | #define numerico(...) GET_MACRO(_, ##__VA_ARGS__, _, _, numerico2, numerico1, numerico0)(__VA_ARGS__)
|
61 | 63 | #define decimal(...) GET_MACRO(_, ##__VA_ARGS__, _, _, decimal2, decimal1, decimal0)(__VA_ARGS__)
|
| 64 | +#define caractere(...) GET_MACRO(_, ##__VA_ARGS__, _, _, caractere2, caractere1, caractere0)(__VA_ARGS__) |
| 65 | +#define logico(...) GET_MACRO(_, ##__VA_ARGS__, _, _, logico2, logico1, logico0)(__VA_ARGS__) |
| 66 | + |
| 67 | +// Vector Initialization |
| 68 | +#define vetor(_TYPE, _NAME, _SIZE, ...) PREVENT_SEMICOLON_ERROR _TYPE() _NAME[_SIZE + 1] PREPEND_EQUAL_IF_NONEMPTY(__VA_ARGS__); |
| 69 | +//#define vetor(...) GET_MACRO(_, ##__VA_ARGS__, vetor4, vetor3, _, _, _)(__VA_ARGS__) |
| 70 | + |
| 71 | +// Constantes |
| 72 | +#define constante(_TYPE, _NAME, _VALUE) PREVENT_SEMICOLON_ERROR _TYPE(const _NAME, _VALUE); |
62 | 73 |
|
63 | 74 | // And then the function to declare any number of vars
|
64 | 75 | #define declare(_TYPE, ...) PREVENT_SEMICOLON_ERROR CALL_MACRO_X_FOR_EACH(_TYPE, __VA_ARGS__)
|
|
69 | 80 |
|
70 | 81 | // For in portugol style
|
71 | 82 | #define para PREVENT_SEMICOLON_ERROR for(
|
72 |
| -#define de = |
73 |
| -#define ate(_X, _Y) ; _X <= _Y ; _X++ |
| 83 | +#define de = |
| 84 | + |
| 85 | +// Ate com e sem incremento crescente |
| 86 | +#define ateCrescente3(_X, _Y, _Z) ; _X <= _Y; _X += _Z |
| 87 | +#define ateCrescente2(_X, _Y) ateCrescente3(_X, _Y, 1) |
| 88 | +#define ateCrescente(...) GET_MACRO(_, ##__VA_ARGS__, _, ateCrescente3, ateCrescente2, _, _)(__VA_ARGS__) |
| 89 | +#define ate(...) ateCrescente(__VA_ARGS__) |
| 90 | + |
| 91 | +// Ate com e sem incremento decrescente |
| 92 | +#define ateDecrescente3(_X, _Y, _Z) ; _X >= _Y; _X -= _Z |
| 93 | +#define ateDecrescente2(_X, _Y) ateDecrescente3(_X, _Y, 1) |
| 94 | +#define ateDecrescente(...) GET_MACRO(_, ##__VA_ARGS__, _, ateDecrescente3, ateDecrescente2, _, _)(__VA_ARGS__) |
74 | 95 |
|
75 | 96 | // Basic arduino reserved function name
|
76 | 97 | #define configura void setup()
|
|
81 | 102 | #define escrevaDigital(_PIN, _STATE) PREVENT_SEMICOLON_ERROR digitalWrite(_PIN, _STATE);
|
82 | 103 | #define escrevaAnalogico(_PIN, _VALUE) PREVENT_SEMICOLON_ERROR analogWrite(_PIN, _VALUE);
|
83 | 104 | #define espera(_TIME) PREVENT_SEMICOLON_ERROR delay(_TIME);
|
84 |
| -#define tom(_TIME, _NOTE, _DURATION) PREVENT_SEMICOLON_ERROR tone(_TIME, _NOTE, _DURATION); |
85 |
| -#define semTom(_TIME) PREVENT_SEMICOLON_ERROR noTone(_TIME); |
| 105 | +#define tom(_PIN, _NOTE, _DURATION) PREVENT_SEMICOLON_ERROR tone(_PIN, _NOTE, _DURATION); |
| 106 | +#define semTom(_PIN) PREVENT_SEMICOLON_ERROR noTone(_PIN); |
| 107 | +#define limites(_VAR, _MIN, _MAX) PREVENT_SEMICOLON_ERROR constrain(_VAR, _MIN, _MAX); |
| 108 | +#define mapeie(_VAR, _MIN1, _MAX1, _MIN2, _MAX2) PREVENT_SEMICOLON_ERROR mapeie(_VAR, _MIN1, _MAX1, _MIN2, _MAX2) |
86 | 109 |
|
87 | 110 | // Basic functions with return
|
88 | 111 | #define leiaAnalogico(_PIN) analogRead(_PIN);
|
89 | 112 | #define leiaDigital(_PIN) digitalRead(_PIN);
|
90 | 113 |
|
91 |
| -// Methods |
| 114 | +// Methods as functions |
92 | 115 | #define comecar begin
|
93 |
| -#define imprime(_TEXT) println(_TEXT); |
94 |
| -#define imprimeln(_TEXT) print(_TEXT); |
| 116 | +#define comeca(_OBJECT, _SPEED) PREVENT_SEMICOLON_ERROR _OBJECT.begin(_SPEED); |
| 117 | + |
| 118 | +#define imprimir print |
| 119 | +#define imprime(_OBJECT, _TEXT) PREVENT_SEMICOLON_ERROR _OBJECT.print(_TEXT); |
| 120 | + |
| 121 | +#define imprimirln println |
| 122 | +#define imprimeln(_OBJECT, _TEXT) PREVENT_SEMICOLON_ERROR _OBJECT.println(_TEXT); |
| 123 | + |
| 124 | +#define disponivel available() |
| 125 | +#define estaDisponivel(_OBJECT) _OBJECT.available(); |
| 126 | + |
| 127 | +#define ler read |
| 128 | +#define le(_OBJECT) _OBJECT.read(); |
| 129 | +#define leCaractere le(Serial) |
| 130 | + |
| 131 | +#define escrever(_OBJECT, _CHAR) PREVENT_SEMICOLON_ERROR _OBJECT.write(_CHAR); |
| 132 | +#define escreve write |
95 | 133 |
|
96 | 134 | // Avoid errors on objects
|
97 |
| -#define Serial PREVENT_SEMICOLON_ERROR Serial |
| 135 | +//#define Serial PREVENT_SEMICOLON_ERROR Serial |
98 | 136 |
|
99 | 137 | // Constants
|
100 | 138 | #define ALTO HIGH
|
|
0 commit comments