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:22] 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 code continuously | |
+ | | #define X value | Replace all references to X with value at compile time | | ||
+ | | #include library | Include library in sketch and access its functions | | ||
- | | + | == Control Structures == |
- | Loop code continuously\\ | + | | if (expression A) {do thing A} | 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 {do thing C} | Do thing C if all the above " | ||
+ | | for(int x = 0; x < 100; x++){println(x)} | Set x to 0, then while x is less than 100, print X and increment x by 1 | | ||
+ | | while(statement){expression} | Keep doing expression while statement is true | | ||
+ | | do{statement}while(expression); | ||
+ | | switch(var){case X: statement X break; case Y: statement | ||
+ | | break; | Exit a for, while, do while loop or switch statement | | ||
+ | | continue; | Skip rest of current iteration of for, while, or do while loop, start next iteration | | ||
+ | | return value; | Terminate the function and optionally return value to the function that called it | | ||
+ | | goto label; |Send the program flow to `label:` | | ||
- | #define constantName value | + | == Comparison Operators == |
- | Replace all references | + | | == | Equals | |
- | # | + | | != | Is not equal to | |
- | Include library in sketch and access its functions// | + | | < | Less than | |
+ | | > |Greater than | | ||
+ | | < | ||
+ | | >= | Greater than or equal to | | ||
- | == Control Structures == | + | == Boolean |
- | if (expression A) {do thing A} | + | | && | And | |
- | Do thing A if expression A is true// | + | | <nowiki> || </nowiki> | Or | |
- | else if (expression B) {do thing B} | + | | ! | Not | |
- | Do thing B if expression A is false and expression B is true// | + | |
- | else {do thing C} | + | == Bitwise Operators |
- | Do thing C if all the above " | + | | & | And | |
- | for(int x = 0; x < 100; x++){println(x)} | + | | < |
- | Set x to 0, then while x is less than 100, print X and increment x by 1 | + | | ~ | Not | |
- | while(statement){expression} | + | | << |
- | Keep doing expression while statement is true | + | | >> |
- | do{statement}while(expression); | + | |
- | Like while loop, except expression is evaluated after statement runs once | + | == Compound Operators |
- | switch (var) {case 1: statement A break; case 2: statement B break; default: statement C break} | + | | x ++ | x=x+1 | |
- | Run statement A, B or C depending on whether var is 1, 2 or a different value | + | | x -- | x=x-1 | |
- | break; | + | | x +=y | x=x+y | |
- | Exit a for, while, do while loop or switch statement | + | | x -=y | x=x-y | |
- | continue; | + | | x *=y | x=x*y | |
- | Skip rest of current iteration of for, while, or do while loop, start next iteration | + | | x /=y | x=x/y | |
- | return value; | + | | x %=y | x=the remainder of x/y | |
- | Terminate the function and optionally return value to the function that called it | + | | x & |
- | goto label; | + | |
- | Send the program flow to `label:` | + | == Constants |
- | Comparison | + | | HIGH/ |
- | == | + | | true/ |
- | Equals | + | | LED_BUILTIN |
- | != | + | | pinMode(pin, |
- | Is not equal to | + | | digitalWrite(pin, |
- | < | + | | digitalRead(pin) |
- | Less than | + | | analogReference(type) |
- | > | + | | analogRead(pin) |
- | Greater than | + | | analogWrite(pin, |
- | <= | + | |
- | Less than or equal to | + | == Math == |
- | >= | + | | min(x, |
- | Greater than or equal to | + | | max(x, |
- | Boolean Operators | + | | abs(x) |
- | && | + | | constrain(x, |
- | And | + | | map(value, |
- | || | + | | pow(a, |
- | Or | + | | sqrt(x) |
- | ! | + | | sin(x) / cos(x) / tan(x) |
- | Not | + | | randomSeed(x) |
- | Bitwise Operators | + | | random(min, |
- | & | + | |
- | And | + | == Time == |
- | | | + | | millis() |
- | Or | + | | micros() |
- | ^ | + | | delay(n) |
- | Xor | + | | delayMicroseconds(n) |
- | ~ | + | |
- | Not | + | \\ |
- | << | + | \\ |
- | Bitshift left | + | mehr auf [[https://www.arduino.cc/ |
- | >> | + | |
- | Bitshift right | + | |
- | Compound Operators | + | |
- | x ++ | + | |
- | x = x + 1 | + | |
- | x -- | + | |
- | x = x - 1 | + | |
- | x += y | + | |
- | x = x + y | + | |
- | x -= y | + | |
- | x = x - y | + | |
- | x *= y | + | |
- | x = x * y | + | |
- | x /= y | + | |
- | x = x / y | + | |
- | x %= y | + | |
- | x = the remainder of x / y | + | |
- | x &= y | + | |
- | x = x & y | + | |
- | x |= y | + | |
- | x = x | y | + | |
- | 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 | + |