Monday, October 15, 2018

Oct 15 2018
Arduino BASICS
-Pin13 is the only one that already contains a resistor

void setup () {
                 statements;
                  }
-defines pins to use and rules for the loop.
-kinda like a style sheet from CSS

void loop () {
                 statements;
                  }
-Defines what we do with the pins we're using


-use "//" to make the rest of a line a comment that doesn't affect the script.
-use "/*" and end with "*/" to create an entire block of comments.
-Comments help you keep track of what piece of code does what.

VARIABLES
type     variableName ;
type     variableName = value,      <-----can define what type of variable and its value at the same time

lowercaseUppercase <-----known as Camel Case

4 BIG TYPES: using correct type makes Arduino run much smoother and saves space

byte
-A whole number from 0 to 255

int
-A positive or neg number from -32000 to 32000

long
-A positive or neg number that exists in a large range(from pos to neg billions)

float
-A value measured to the decimal point, either positive or negative


SCOPES
3 different types:
global - placing a declaration outside of setup and loop, allows it to be a rule that applies to all of the code.

function -

local - exists on the most specific level



Array-A list or collection that you can call on for different information.
-arrays have a type

int      myArray[]={val0, val1, val2,...}; <--- directly defining values in list

int      myArray2[5];   <-----says make room for a list of five integers, number in square brackets defines number of objects in list.

int      myArray2[5]; <----declared statement, would be located in setup
x=myArray2[2];  <------code finds 2nd value in list, x is an assignment, would be located in loop

color ranges are measured in bytes;
255,255,255 is white
0,0,0 is black

A fourloop is a mini function inside the loop that performs a list of functions in order.

void loop() {
for (int i=0; i<7; i++) {
  analogWrite(ledPin, flicker[i]);
  delay(200);
}
}

i++ means move up a level






No comments:

Post a Comment