This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision | ||
|
hstarwiki:cust:gen:arduino [2016-09-09 T 23:59] admin [Advanced Syntax] |
hstarwiki:cust:gen:arduino [2017-03-03 T 17:14] (current) |
||
|---|---|---|---|
| Line 12: | Line 12: | ||
| many examples in this document show examples of code. Unless in a code box, the examples will start with $ and follow some of hte principals in the [[hstarwiki: | many examples in this document show examples of code. Unless in a code box, the examples will start with $ and follow some of hte principals in the [[hstarwiki: | ||
| - | ====== Coding Notes ====== | + | ==== Coding Notes ==== |
| IDEA!!!!!: Can write examples of if then (etc) operations of what would hapen if, and so on in the comments. | IDEA!!!!!: Can write examples of if then (etc) operations of what would hapen if, and so on in the comments. | ||
| * 2015-03-14 Left off at: | * 2015-03-14 Left off at: | ||
| - | ==== Basic scripts: ==== | + | ===== Basic scripts: ====== |
| + | Minimum for a script: | ||
| < | < | ||
| void setup() { | void setup() { | ||
| Line 59: | Line 60: | ||
| analogWrite(led, | analogWrite(led, | ||
| </ | </ | ||
| - | ==== Before void setup: ==== | + | ====== Script |
| Before setup you can define things such as int | Before setup you can define things such as int | ||
| - | * | ||
| ==== void setup ==== | ==== void setup ==== | ||
| More: | More: | ||
| ==== Within the void setup brackets {} ==== | ==== Within the void setup brackets {} ==== | ||
| - | + | ==== Numbers and more ==== | |
| - | Numbers and more etc | + | == int == |
| - | | + | * $int [var] = [x]: |
| - | * int [var] = x: | + | |
| * This will define an integer with | * This will define an integer with | ||
| * [var] | * [var] | ||
| Line 77: | Line 76: | ||
| * If larger see: | * If larger see: | ||
| * http:// | * http:// | ||
| - | * Can also make x a sensor value or other things ex | + | * Can also make x a sensor value or other things. ex: |
| * int sensorvalue = analogRead(A0); | * int sensorvalue = analogRead(A0); | ||
| - | * | + | == float == |
| - | * float | + | |
| * float [var] = [val]; | * float [var] = [val]; | ||
| * [var] | * [var] | ||
| Line 86: | Line 84: | ||
| * [val] | * [val] | ||
| * 32bit number meant for decimal point value | * 32bit number meant for decimal point value | ||
| - | * | + | == long == |
| - | * long | + | |
| * long [var] = [val][L] | * long [var] = [val][L] | ||
| * for ding larger numbers that are 32bit but integers. | * for ding larger numbers that are 32bit but integers. | ||
| Line 93: | Line 90: | ||
| * ex: | * ex: | ||
| * long speedOfLight - 186000L | * long speedOfLight - 186000L | ||
| - | * | + | |
| - | | + | ==== Before operators |
| - | * | + | const |
| - | * const | + | * $const [type] [name] = [var] |
| - | * const [type] [name] = [var] | + | |
| * A constant will not change, so you can not use operations to change the int or float | * A constant will not change, so you can not use operations to change the int or float | ||
| - | * | + | unsigned |
| - | * unsigned | + | * $unsigned [type] [name] = [var] |
| - | * unsigned [type] [name] = [var] | + | |
| * Unsigned will use the bit available per type in only positive. | * Unsigned will use the bit available per type in only positive. | ||
| * for example for int, it will used:0 to 65,535 | * for example for int, it will used:0 to 65,535 | ||
| * instead of -32,768 and 32,768 | * instead of -32,768 and 32,768 | ||
| - | * | + | ====== |
| - | * | + | |
| - | * Modes | + | * $pinMode([pin], |
| - | | + | |
| - | * pinMode([pin], | + | |
| * http:// | * http:// | ||
| * [pin] an be a number, or if defined int earlier, that int definition | * [pin] an be a number, or if defined int earlier, that int definition | ||
| Line 120: | Line 113: | ||
| * INPUT_PULLUP | * INPUT_PULLUP | ||
| * This needs more explanation but basically changes the ohm resistance for better? or Varied? inputs | * This needs more explanation but basically changes the ohm resistance for better? or Varied? inputs | ||
| - | * | + | * $digitalWrite([pin], |
| - | * digitalWrite([pin], | + | |
| * [pin] | * [pin] | ||
| * number of pin, or constant | * number of pin, or constant | ||
| Line 129: | Line 121: | ||
| * Low | * Low | ||
| * sends 0V | * sends 0V | ||
| - | * | + | read |
| - | * digitalRead([pin]) | + | * $digitalRead([pin]) |
| * will read whatever value is active on [pin], often set is INPUT | * will read whatever value is active on [pin], often set is INPUT | ||
| * may need to | * may need to | ||
| - | * | + | read analog |
| - | * analogRead([pin]) | + | * $analogRead([pin]) |
| * Will give an analog read between 0-1023 (10bit) | * Will give an analog read between 0-1023 (10bit) | ||
| - | * | + | if else |
| - | * if else | + | < |
| - | | + | if ([if formula]) |
| - | | + | { |
| - | | + | // then do this |
| - | | + | } |
| - | | + | else { |
| - | | + | // then do this |
| - | | + | } |
| + | </ | ||
| * Do not need else forumla as it will follow after if | * Do not need else forumla as it will follow after if | ||
| * can do: | * can do: | ||
| - | * else if ([if then formula) | + | < |
| - | | + | else if ([if then formula) |
| - | | + | { |
| - | | + | // Then do this |
| + | } | ||
| + | </ | ||
| * and chain together other paremiters, but be sure to end with basic else | * and chain together other paremiters, but be sure to end with basic else | ||
| * Do not need else, but watch out | * Do not need else, but watch out | ||
| + | ====== Operators ====== | ||
| * x == y (x is equal to y) !!! important to use 2 equals | * x == y (x is equal to y) !!! important to use 2 equals | ||
| * x != y (x is not equal to y) | * x != y (x is not equal to y) | ||
| Line 162: | Line 158: | ||
| * ! (equals NOT) | * ! (equals NOT) | ||
| * && (equals AND) | * && (equals AND) | ||
| - | * Serial | + | ====== |
| - | * | + | |
| * http:// | * http:// | ||
| * Some pins are auto serial (kinda like the auto 5V or GND) | * Some pins are auto serial (kinda like the auto 5V or GND) | ||
| * But you can define a pin with: | * But you can define a pin with: | ||
| - | * Serial.[options]([var]); | + | * $Serial.[options]([var]); |
| * [options] | * [options] | ||
| * .begin | * .begin | ||
| * Will beging sending output via the serial port at whatever baud rate. ex: | * Will beging sending output via the serial port at whatever baud rate. ex: | ||
| - | * Serial.begin(9600) | + | * $Serial.begin(9600) |
| * Note: This only initializes the serial communication so you most likely want to put it in the setup area. | * Note: This only initializes the serial communication so you most likely want to put it in the setup area. | ||
| * .println | * .println | ||
| Line 179: | Line 174: | ||
| * .print(" | * .print(" | ||
| * in this option, it will print text within the parenthesis | * in this option, it will print text within the parenthesis | ||
| - | * | ||
| * [baud] | * [baud] | ||
| * The baud rate of the signal. Usually 9600 | * The baud rate of the signal. Usually 9600 | ||
| - | * | ||
| - | * | ||
| - | * Readouts | ||
| - | * | ||
| - | * millis() | ||
| - | * will return the ammount of millisconds since the prgrams has started | ||
| - | | + | ====== Readouts ====== |
| + | | ||
| + | * will return the ammount of millisconds since the prgrams has started | ||
| + | ====== | ||
| * PWM = Pulse width modulation. Basically an analog modulation variable that sends an analog signal | * PWM = Pulse width modulation. Basically an analog modulation variable that sends an analog signal | ||
| * It can set the modulation at 8bit or 0-255. ex: | * It can set the modulation at 8bit or 0-255. ex: | ||
| * analogWrite(127) which is about half. | * analogWrite(127) which is about half. | ||
| - | * | + | |
| + | ====== last code ====== | ||