Arduino |
|
Arduino Home |
|
NeoPixel by Adafruit |
|
|
Arduino
Basics
1. Programs are called sketches and have a
file extension of .ino. They must
be in a folder named the same as the file.
2. There are two functions in a sketch:
setup() – This function is called when a sketch starts. Use it to
initialize pin modes, serial communications, start using libraries, etc.
loop() – After creating a setup() function, which initializes and sets
the initial values, the loop() function loops forever. Use this for the
main loop of your sketch (program).
3. Once a program/sketch has been uploaded to an Arduino, it stays on it
until a new one is loaded. The board can be powered by a battery after the
sketch is loaded.
4. Using the Arduino
- Under Tools menu, check that Board is set to “Arduino/Genuino
Uno” or "Arduino/Genuino Mega or Mega 2560" for the larger board.
- Under Tools menu, the Port usually needs to be set to the highest
numbered COM Port
- Under Help menu, select Reference to see all the commands
- Under File menu, look at some the Examples
5. Pseudo Random Numbers
Seed random # generator in setup: randomSeed(analogRead(0));
Generate a random # between 0 and 9: random(10);
6. Serial Monitor
This allows you to send data from your board back to your computer. Click on
the Serial Monitor icon on the right side of the toolbar.
Initialize serial monitor in setup():
Serial.begin(9600);
Output text:
Serial.println("Hello World!");
Output numbers/variables:
Serial.println(A);
#include <Adafruit_NeoPixel.h>
int NumPixels = 16; // set this to number of pixels
on your ring
// setup() runs once at the beginning
|
#include <QTRSensors.h> void Reverse (int
LeftSpeed, int RightSpeed) // range 0-255 |