User Tools

Site Tools


hstarwiki:cust:gen:arduino

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
hstarwiki:cust:gen:arduino [2016-09-09 T 23:40]
admin
hstarwiki:cust:gen:arduino [2017-03-03 T 17:14] (current)
Line 2: Line 2:
 Things you need: Things you need:
   * Arduino   * Arduino
-  * Power supply or Printer USB cable+  * Printer USB cable (Type B)
   * Arduino Software   * Arduino Software
 For linux you can run the software from bash or make a script. It is good to do sudo so you have all permissions for ports For linux you can run the software from bash or make a script. It is good to do sudo so you have all permissions for ports
   * $arduino   * $arduino
  
 +After running the program, you can make or upload scripts. then comile and load
  
-====== Coding Notes ======+==== This document ==== 
 +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:linux|linux]] page on this wiki. 
 + 
 +==== 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:http://arduino.cc/en/Tutorial/AnalogReadSerial   * 2015-03-14 Left off at:http://arduino.cc/en/Tutorial/AnalogReadSerial
  
-==== Basic scripts: ====+===== Basic scripts: ====== 
 +Minimum for a script:
 <code> <code>
 void setup() {                    void setup() {                   
Line 19: Line 24:
  }  }
 </code>  </code> 
-==== Basic Sytax ====+====== Basic Sytax ======
 == No Code == == No Code ==
-  * /* +<code> 
-  you can write notes that will not be part of the scripte with forward slash star +/* 
-  then star forward slash to end + you can write notes that will not be part of the scripte with forward slash star 
-  */ +then star forward slash to end 
-  * // You can also do just forward slash, forward slash space for a single line +*/ 
-  End of line+</code> 
 +  * %%//%% You can also do just forward slash, forward slash space for a single line 
 +End of line
   * Use semicolen at the end of each line, ex:   * Use semicolen at the end of each line, ex:
-  * pinMode(13, OUTPUT);+  * $pinMode(13, OUTPUT);
 == Pins: == == Pins: ==
-Unless othersiwse stated, pins are just indicated by numbers such as:+Unless othersiwse stated, pins are just indicated by numbers such as this indicated pin 13 on the actual board:
   * pinMode(13, OUTPUT);   * pinMode(13, OUTPUT);
-  * delay([milliseconds]) 
  
-==== Advanced Syntax ====+== Other: == 
 +  * $delay([milliseconds]); 
 +  * This sets a delay  
 + 
 +====== Advanced Syntax ======
 == Cast == == Cast ==
 Cast is a way of converting one type of data, to another type, Cast is a way of converting one type of data, to another type,
   * such as float to int   * such as float to int
-  * ([type])[var] +  * $([type])[var] 
   * type is things like float or int   * type is things like float or int
   * var is any variable or constant   * var is any variable or constant
   * Example (to change a float brightness to a int brightness   * Example (to change a float brightness to a int brightness
-  * float bright = sensorValue * (255.0 / 1023.0); +<code> 
-  int bint; // a way to define an int name, but give no value +float bright = sensorValue * (255.0 / 1023.0); 
-  float bflo; // define float name, but give no value +int bint; // a way to define an int name, but give no value 
-  bflo = bright; // sets what value the float is +float bflo; // define float name, but give no value 
-  bint = (int)bflo; // this is the cast directive  +bflo = bright; // sets what value the float is 
-  analogWrite(led, bint); // for this example, it would cast the light as an int through a pwm pin and allow it to be an integer between 0-255 +bint = (int)bflo; // this is the cast directive  
-   +analogWrite(led, bint); // for this example, it would cast the light as an int through a pwm pin and allow it to be an integer between 0-255 
-  * Before void setup:  +</code> 
-   +====== Script setup: ====== 
-  Before setup you can define things such as int +  
-  *  +Before setup you can define things such as int 
-  * void setup +==== void setup ==== 
-  *  +More:http://arduino.cc/en/Reference/Setup"The setup() function is called when a sketch starts. Use it to initialize variables, pin modes, start using libraries, etc. The setup function will only run once, after each powerup or reset of the Arduino board. " 
-  * More:http://arduino.cc/en/Reference/Setup +==== Within the void setup brackets {} ==== 
-  * "The setup() function is called when a sketch starts. Use it to initialize variables, pin modes, start using libraries, etc. The setup function will only run once, after each powerup or reset of the Arduino board. " +==== Numbers and more ==== 
-  Within the void setup brackets {} +== int == 
-  *  +  * $int [var] = [x]:
-  * Numbers and more etc +
-  *  +
-  * int +
-  * int [var] = x:+
   * This will define an integer with   * This will define an integer with
   * [var]   * [var]
Line 70: Line 76:
   * If larger see:   * If larger see:
   * http://arduino.cc/en/Reference/Int   * http://arduino.cc/en/Reference/Int
-  * Can also make x a sensor value or other things ex+  * Can also make x a sensor value or other thingsex:
   * int sensorvalue = analogRead(A0);   * int sensorvalue = analogRead(A0);
-  *  +== float ==
-  * float+
   * float [var] = [val];   * float [var] = [val];
   * [var]   * [var]
Line 79: 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 86: Line 90:
   * ex:   * ex:
   * long speedOfLight - 186000L   * long speedOfLight - 186000L
-  *  + 
-  Before operators: +==== 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 ====== 
-  *  + 
-  * Modes +  * $pinMode([pin], [configuration]);
-   +
-  * pinMode([pin], [configuration]);+
   * http://arduino.cc/en/Tutorial/DigitalPins   * http://arduino.cc/en/Tutorial/DigitalPins
   * [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 113: 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], [value])
-  * digitalWrite([pin], [value])+
   * [pin]   * [pin]
   * number of pin, or constant   * number of pin, or constant
Line 122: 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 +<code> 
-  if ([if formula]) +if ([if formula]) 
-  +
-  *  // then do this + // then do this 
-  +
-  else { +else { 
-  // then do this +// then do this 
-  }+} 
 +</code>
   * 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) +<code> 
-  +else if ([if then formula) 
-  // Then do this +
-  }+// Then do this 
 +} 
 +</code>
   * 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 155: Line 158:
   * ! (equals NOT)   * ! (equals NOT)
   * && (equals AND)   * && (equals AND)
-  * Serial +====== Serial ======
-  * +
   * http://arduino.cc/en/Reference/Serial   * http://arduino.cc/en/Reference/Serial
   * 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 172: Line 174:
   * .print("[text]")   * .print("[text]")
   * 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 
  
-  * Glossery:+====== Readouts ====== 
 +  $millis() 
 +  * will return the ammount of millisconds since the prgrams has started 
 +====== Glossery: ======
   * 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 ====== 
hstarwiki/cust/gen/arduino.1473464400.txt.gz · Last modified: 2017-03-03 T 17:15 (external edit)