Hier werden die Unterschiede zwischen zwei Versionen angezeigt.
Beide Seiten der vorigen Revision Vorhergehende Überarbeitung Nächste Überarbeitung | Vorhergehende Überarbeitung | ||
knowledgebase:arduinoide [2017/11/29 14:21] rolex |
knowledgebase:arduinoide [2017/12/19 11:38] (aktuell) rolex |
||
---|---|---|---|
Zeile 1: | Zeile 1: | ||
==== Arduino IDE syntax ==== | ==== Arduino IDE syntax ==== | ||
== General Structure == | == General Structure == | ||
- | | + | | setup() |
- | Run code once at beginning of program\\ | + | | loop() |
- | loop() | + | | # |
- | Loop code continuously// | + | | #include library |
- | # | + | |
- | Replace all references to constantName | + | |
- | #include library | + | |
- | Include library in sketch and access its functions// | + | |
== Control Structures == | == Control Structures == | ||
- | | + | | if (expression A) {do thing A} | Do thing A if expression A is true | |
- | Do thing A if expression A is true// | + | | else if (expression B) {do thing B} | Do thing B if expression A is false and expression B is true | |
- | else if (expression B) {do thing B} | + | | else {do thing C} | Do thing C if all the above " |
- | Do thing B if expression A is false and expression B is true// | + | | for(int x = 0; x < 100; x++){println(x)} |
- | else {do thing C} | + | | while(statement){expression} |
- | Do thing C if all the above " | + | | do{statement}while(expression); |
- | for(int x = 0; x < 100; x++){println(x)} | + | | switch(var){case |
- | Set x to 0, then while x is less than 100, print X and increment x by 1 | + | | break; |
- | while(statement){expression} | + | | continue; |
- | Keep doing expression while statement is true | + | | return value; |
- | do{statement}while(expression); | + | | goto label; |
- | Like while loop, except expression is evaluated after statement runs once | + | |
- | switch (var) {case 1: statement | + | == Comparison Operators == |
- | Run statement | + | | == | Equals |
- | break; | + | | != | Is not equal to | |
- | Exit a for, while, do while loop or switch statement | + | | < | Less than | |
- | continue; | + | | > |Greater than | |
- | Skip rest of current iteration of for, while, or do while loop, start next iteration | + | | < |
- | return value; | + | | >= | Greater than or equal to | |
- | Terminate the function and optionally return value to the function that called it | + | |
- | goto label; | + | == Boolean Operators |
- | Send the program flow to `label:` | + | | && |
- | Comparison Operators | + | | < |
- | == | + | | ! | Not | |
- | Equals | + | |
- | != | + | == Bitwise Operators |
- | Is not equal to | + | | & | And | |
- | < | + | | < |
- | Less than | + | | ~ | Not | |
- | > | + | | << |
- | Greater than | + | | >> |
- | <= | + | |
- | Less than or equal to | + | == Compound Operators |
- | >= | + | | x ++ | x=x+1 | |
- | Greater than or equal to | + | | x -- | x=x-1 | |
- | Boolean Operators | + | | x +=y | x=x+y | |
- | && | + | | x -=y | x=x-y | |
- | And | + | | x *=y | x=x*y | |
- | || | + | | x /=y | x=x/y | |
- | Or | + | | x %=y | x=the remainder of x/y | |
- | ! | + | | x & |
- | Not | + | |
- | Bitwise Operators | + | == Constants |
- | & | + | | HIGH/ |
- | And | + | | true/ |
- | | | + | | LED_BUILTIN |
- | Or | + | | pinMode(pin, |
- | ^ | + | | digitalWrite(pin, |
- | Xor | + | | digitalRead(pin) |
- | ~ | + | | analogReference(type) |
- | Not | + | | analogRead(pin) |
- | << | + | | analogWrite(pin, |
- | Bitshift left | + | |
- | >> | + | == Math == |
- | Bitshift right | + | | min(x, |
- | Compound Operators | + | | max(x, |
- | x ++ | + | | abs(x) |
- | x = x + 1 | + | | constrain(x, |
- | x -- | + | | map(value, |
- | x = x - 1 | + | | pow(a, |
- | x += y | + | | sqrt(x) |
- | x = x + y | + | | sin(x) / cos(x) / tan(x) |
- | x -= y | + | | randomSeed(x) |
- | x = x - y | + | | random(min, |
- | x *= y | + | |
- | x = x * y | + | == Time == |
- | x /= y | + | | millis() |
- | x = x / y | + | | micros() |
- | x %= y | + | | delay(n) |
- | x = the remainder of x / y | + | | delayMicroseconds(n) |
- | x &= y | + | |
- | x = x & y | + | \\ |
- | x |= y | + | \\ |
- | x = x | y | + | mehr auf [[https://www.arduino.cc/ |
- | Constants | + | |
- | HIGH / LOW | + | |
- | Pin input or output voltage is high or low | + | |
- | true / false | + | |
- | Boolean values | + | |
- | INPUT / INPUT_PULLUP / OUTPUT | + | |
- | Configure pin to sample voltage or provide current to other circuits | + | |
- | LED_BUILTIN | + | |
- | Pin where built-in LED is connected | + | |
- | I/O | + | |
- | pinMode(pin, | + | |
- | Set pin to either INPUT, OUTPUT, or INPUT_PULLUP | + | |
- | digitalWrite(pin, | + | |
- | Set pin to either HIGH or LOW | + | |
- | digitalRead(pin) | + | |
- | Read value of pin, which will be HIGH or LOW | + | |
- | analogReference(type) | + | |
- | Configure refence voltage used for analog input | + | |
- | analogRead(pin) | + | |
- | Return input voltage of pin as integer between 0 and 1023 | + | |
- | analogWrite(pin, | + | |
- | Output PWM wave to pin with duty cycle of value (between 0 and 255) | + | |
- | Math | + | |
- | min(x, y) | + | |
- | Return the smaller of x or y | + | |
- | max(x, y) | + | |
- | Return the greater of x or y | + | |
- | abs(x) | + | |
- | Absolute value of x | + | |
- | constrain(x, | + | |
- | Limit x to the range a-b, return a or b if x is too small or too large | + | |
- | map(value, fromLow, fromHigh, toLow, toHigh) | + | |
- | Map value from one range of numbers to another | + | |
- | pow(a, x) | + | |
- | Calculate a to the power of x | + | |
- | sqrt(x) | + | |
- | Square root of x | + | |
- | sin(x) / cos(x) / tan(x) | + | |
- | Sine, cosine and tangent of x | + | |
- | randomSeed(x) | + | |
- | Start the pseudo-random number generator at point x | + | |
- | random(min, max) | + | |
- | Generate a pseudo-random number between min (inclusive) and max (exclusive) | + | |
- | Time | + | |
- | millis() | + | |
- | Return milliseconds since program started | + | |
- | micros() | + | |
- | Return microseconds since program started | + | |
- | delay(n) | + | |
- | Pause program for n milliseconds | + | |
- | delayMicroseconds(n) | + | |
- | Pause program for n microseconds | + | |
- | Comments | + | |
- | // stuff | + | |
- | Single-line comment | + | |
- | /* many things */ | + | |
- | Multi-line comment | + |