mirror of
https://github.com/arduino/Arduino.git
synced 2025-02-28 22:54:20 +01:00
Fix typos in the comments of the built-in examples
This commit is contained in:
parent
86c6103142
commit
a71b40351f
build/shared/examples
01.Basics
AnalogReadSerial
Blink
DigitalReadSerial
ReadAnalogVoltage
02.Digital
BlinkWithoutDelay
Debounce
DigitalInputPullup
StateChangeDetection
03.Analog
AnalogInOutSerial
AnalogInput
AnalogWriteMega
Smoothing
04.Communication
ASCIITable
Dimmer
Graph
Midi
MultiSerial
PhysicalPixel
SerialCallResponse
SerialCallResponseASCII
SerialEvent
SerialPassthrough
VirtualColorMixer
05.Control
Arrays
WhileStatementConditional
switchCase
switchCase2
06.Sensors
07.Display/RowColumnScanning
08.Strings
StringAdditionOperator
StringAppendOperator
StringCaseChanges
StringCharacters
StringComparisonOperators
StringConstructors
StringIndexOf
StringLengthTrim
StringReplace
09.USB
Keyboard
Mouse/JoystickMouseControl
10.StarterKit_BasicKit
p02_SpaceshipInterface
p03_LoveOMeter
p04_ColorMixingLamp
p05_ServoMoodIndicator
p06_LightTheremin
p07_Keyboard
p08_DigitalHourglass
p09_MotorizedPinwheel
p10_Zoetrope
p11_CrystalBall
p12_KnockLock
p13_TouchSensorLamp
p14_TweakTheArduinoLogo
p15_HackingButtons
11.ArduinoISP/ArduinoISP
@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
AnalogReadSerial
|
AnalogReadSerial
|
||||||
Reads an analog input on pin 0, prints the result to the serial monitor.
|
Reads an analog input on pin 0, prints the result to the Serial Monitor.
|
||||||
Graphical representation is available using serial plotter (Tools > Serial Plotter menu)
|
Graphical representation is available using Serial Plotter (Tools > Serial Plotter menu)
|
||||||
Attach the center pin of a potentiometer to pin A0, and the outside pins to +5V and ground.
|
Attach the center pin of a potentiometer to pin A0, and the outside pins to +5V and ground.
|
||||||
|
|
||||||
This example code is in the public domain.
|
This example code is in the public domain.
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
/*
|
/*
|
||||||
Blink
|
Blink
|
||||||
Turns on an LED on for one second, then off for one second, repeatedly.
|
Turns an LED on for one second, then off for one second, repeatedly.
|
||||||
|
|
||||||
Most Arduinos have an on-board LED you can control. On the UNO, MEGA and ZERO
|
Most Arduinos have an on-board LED you can control. On the UNO, MEGA and ZERO
|
||||||
it is attached to digital pin 13, on MKR1000 on pin 6. LED_BUILTIN is set to
|
it is attached to digital pin 13, on MKR1000 on pin 6. LED_BUILTIN is set to
|
||||||
the correct LED pin independent of which board is used.
|
the correct LED pin independent of which board is used.
|
||||||
If you want to know what pin the on-board LED is connected to on your Arduino model, check
|
If you want to know what pin the on-board LED is connected to on your Arduino model, check
|
||||||
the Technical Specs of your board at https://www.arduino.cc/en/Main/Products
|
the Technical Specs of your board at https://www.arduino.cc/en/Main/Products
|
||||||
|
|
||||||
This example code is in the public domain.
|
This example code is in the public domain.
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
DigitalReadSerial
|
DigitalReadSerial
|
||||||
Reads a digital input on pin 2, prints the result to the serial monitor
|
Reads a digital input on pin 2, prints the result to the Serial Monitor
|
||||||
|
|
||||||
This example code is in the public domain.
|
This example code is in the public domain.
|
||||||
*/
|
*/
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
ReadAnalogVoltage
|
ReadAnalogVoltage
|
||||||
Reads an analog input on pin 0, converts it to voltage, and prints the result to the serial monitor.
|
Reads an analog input on pin 0, converts it to voltage, and prints the result to the Serial Monitor.
|
||||||
Graphical representation is available using serial plotter (Tools > Serial Plotter menu)
|
Graphical representation is available using Serial Plotter (Tools > Serial Plotter menu)
|
||||||
Attach the center pin of a potentiometer to pin A0, and the outside pins to +5V and ground.
|
Attach the center pin of a potentiometer to pin A0, and the outside pins to +5V and ground.
|
||||||
|
|
||||||
This example code is in the public domain.
|
This example code is in the public domain.
|
||||||
|
@ -1 +1 @@
|
|||||||
Reads an analog input and prints the voltage to the serial monitor.
|
Reads an analog input and prints the voltage to the Serial Monitor.
|
@ -10,7 +10,7 @@
|
|||||||
it is attached to digital pin 13, on MKR1000 on pin 6. LED_BUILTIN is set to
|
it is attached to digital pin 13, on MKR1000 on pin 6. LED_BUILTIN is set to
|
||||||
the correct LED pin independent of which board is used.
|
the correct LED pin independent of which board is used.
|
||||||
If you want to know what pin the on-board LED is connected to on your Arduino model, check
|
If you want to know what pin the on-board LED is connected to on your Arduino model, check
|
||||||
the Technical Specs of your board at https://www.arduino.cc/en/Main/Products
|
the Technical Specs of your board at https://www.arduino.cc/en/Main/Products
|
||||||
|
|
||||||
created 2005
|
created 2005
|
||||||
by David A. Mellis
|
by David A. Mellis
|
||||||
@ -27,17 +27,17 @@
|
|||||||
http://www.arduino.cc/en/Tutorial/BlinkWithoutDelay
|
http://www.arduino.cc/en/Tutorial/BlinkWithoutDelay
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// constants won't change. Used here to set a pin number :
|
// constants won't change. Used here to set a pin number:
|
||||||
const int ledPin = LED_BUILTIN;// the number of the LED pin
|
const int ledPin = LED_BUILTIN;// the number of the LED pin
|
||||||
|
|
||||||
// Variables will change :
|
// Variables will change:
|
||||||
int ledState = LOW; // ledState used to set the LED
|
int ledState = LOW; // ledState used to set the LED
|
||||||
|
|
||||||
// Generally, you should use "unsigned long" for variables that hold time
|
// Generally, you should use "unsigned long" for variables that hold time
|
||||||
// The value will quickly become too large for an int to store
|
// The value will quickly become too large for an int to store
|
||||||
unsigned long previousMillis = 0; // will store last time LED was updated
|
unsigned long previousMillis = 0; // will store last time LED was updated
|
||||||
|
|
||||||
// constants won't change :
|
// constants won't change:
|
||||||
const long interval = 1000; // interval at which to blink (milliseconds)
|
const long interval = 1000; // interval at which to blink (milliseconds)
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
|
@ -40,7 +40,7 @@ int ledState = HIGH; // the current state of the output pin
|
|||||||
int buttonState; // the current reading from the input pin
|
int buttonState; // the current reading from the input pin
|
||||||
int lastButtonState = LOW; // the previous reading from the input pin
|
int lastButtonState = LOW; // the previous reading from the input pin
|
||||||
|
|
||||||
// the following variables are unsigned long's because the time, measured in miliseconds,
|
// the following variables are unsigned longs because the time, measured in milliseconds,
|
||||||
// will quickly become a bigger number than can be stored in an int.
|
// will quickly become a bigger number than can be stored in an int.
|
||||||
unsigned long lastDebounceTime = 0; // the last time the output pin was toggled
|
unsigned long lastDebounceTime = 0; // the last time the output pin was toggled
|
||||||
unsigned long debounceDelay = 50; // the debounce time; increase if the output flickers
|
unsigned long debounceDelay = 50; // the debounce time; increase if the output flickers
|
||||||
@ -58,7 +58,7 @@ void loop() {
|
|||||||
int reading = digitalRead(buttonPin);
|
int reading = digitalRead(buttonPin);
|
||||||
|
|
||||||
// check to see if you just pressed the button
|
// check to see if you just pressed the button
|
||||||
// (i.e. the input went from LOW to HIGH), and you've waited
|
// (i.e. the input went from LOW to HIGH), and you've waited
|
||||||
// long enough since the last press to ignore any noise:
|
// long enough since the last press to ignore any noise:
|
||||||
|
|
||||||
// If the switch changed, due to noise or pressing:
|
// If the switch changed, due to noise or pressing:
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
/*
|
/*
|
||||||
Input Pullup Serial
|
Input Pull-up Serial
|
||||||
|
|
||||||
This example demonstrates the use of pinMode(INPUT_PULLUP). It reads a
|
This example demonstrates the use of pinMode(INPUT_PULLUP). It reads a
|
||||||
digital input on pin 2 and prints the results to the serial monitor.
|
digital input on pin 2 and prints the results to the Serial Monitor.
|
||||||
|
|
||||||
The circuit:
|
The circuit:
|
||||||
* Momentary switch attached from pin 2 to ground
|
* Momentary switch attached from pin 2 to ground
|
||||||
@ -24,7 +24,7 @@
|
|||||||
void setup() {
|
void setup() {
|
||||||
//start serial connection
|
//start serial connection
|
||||||
Serial.begin(9600);
|
Serial.begin(9600);
|
||||||
//configure pin2 as an input and enable the internal pull-up resistor
|
//configure pin 2 as an input and enable the internal pull-up resistor
|
||||||
pinMode(2, INPUT_PULLUP);
|
pinMode(2, INPUT_PULLUP);
|
||||||
pinMode(13, OUTPUT);
|
pinMode(13, OUTPUT);
|
||||||
|
|
||||||
@ -36,7 +36,7 @@ void loop() {
|
|||||||
//print out the value of the pushbutton
|
//print out the value of the pushbutton
|
||||||
Serial.println(sensorVal);
|
Serial.println(sensorVal);
|
||||||
|
|
||||||
// Keep in mind the pullup means the pushbutton's
|
// Keep in mind the pull-up means the pushbutton's
|
||||||
// logic is inverted. It goes HIGH when it's open,
|
// logic is inverted. It goes HIGH when it's open,
|
||||||
// and LOW when it's pressed. Turn on pin 13 when the
|
// and LOW when it's pressed. Turn on pin 13 when the
|
||||||
// button's pressed, and off when it's not:
|
// button's pressed, and off when it's not:
|
||||||
|
@ -53,21 +53,21 @@ void loop() {
|
|||||||
// if the state has changed, increment the counter
|
// if the state has changed, increment the counter
|
||||||
if (buttonState == HIGH) {
|
if (buttonState == HIGH) {
|
||||||
// if the current state is HIGH then the button
|
// if the current state is HIGH then the button
|
||||||
// wend from off to on:
|
// went from off to on:
|
||||||
buttonPushCounter++;
|
buttonPushCounter++;
|
||||||
Serial.println("on");
|
Serial.println("on");
|
||||||
Serial.print("number of button pushes: ");
|
Serial.print("number of button pushes: ");
|
||||||
Serial.println(buttonPushCounter);
|
Serial.println(buttonPushCounter);
|
||||||
} else {
|
} else {
|
||||||
// if the current state is LOW then the button
|
// if the current state is LOW then the button
|
||||||
// wend from on to off:
|
// went from on to off:
|
||||||
Serial.println("off");
|
Serial.println("off");
|
||||||
}
|
}
|
||||||
// Delay a little bit to avoid bouncing
|
// Delay a little bit to avoid bouncing
|
||||||
delay(50);
|
delay(50);
|
||||||
}
|
}
|
||||||
// save the current state as the last state,
|
// save the current state as the last state,
|
||||||
//for next time through the loop
|
// for next time through the loop
|
||||||
lastButtonState = buttonState;
|
lastButtonState = buttonState;
|
||||||
|
|
||||||
|
|
||||||
|
@ -2,8 +2,8 @@
|
|||||||
Analog input, analog output, serial output
|
Analog input, analog output, serial output
|
||||||
|
|
||||||
Reads an analog input pin, maps the result to a range from 0 to 255
|
Reads an analog input pin, maps the result to a range from 0 to 255
|
||||||
and uses the result to set the pulsewidth modulation (PWM) of an output pin.
|
and uses the result to set the pulse width modulation (PWM) of an output pin.
|
||||||
Also prints the results to the serial monitor.
|
Also prints the results to the Serial Monitor.
|
||||||
|
|
||||||
The circuit:
|
The circuit:
|
||||||
* potentiometer connected to analog pin 0.
|
* potentiometer connected to analog pin 0.
|
||||||
@ -40,7 +40,7 @@ void loop() {
|
|||||||
// change the analog out value:
|
// change the analog out value:
|
||||||
analogWrite(analogOutPin, outputValue);
|
analogWrite(analogOutPin, outputValue);
|
||||||
|
|
||||||
// print the results to the serial monitor:
|
// print the results to the Serial Monitor:
|
||||||
Serial.print("sensor = ");
|
Serial.print("sensor = ");
|
||||||
Serial.print(sensorValue);
|
Serial.print(sensorValue);
|
||||||
Serial.print("\t output = ");
|
Serial.print("\t output = ");
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
Analog Input
|
Analog Input
|
||||||
Demonstrates analog input by reading an analog sensor on analog pin 0 and
|
Demonstrates analog input by reading an analog sensor on analog pin 0 and
|
||||||
turning on and off a light emitting diode(LED) connected to digital pin 13.
|
turning on and off a light emitting diode(LED) connected to digital pin 13.
|
||||||
The amount of time the LED will be on and off depends on
|
The amount of time the LED will be on and off depends on
|
||||||
the value obtained by analogRead().
|
the value obtained by analogRead().
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
Mega analogWrite() test
|
Mega analogWrite() test
|
||||||
|
|
||||||
This sketch fades LEDs up and down one at a time on digital pins 2 through 13.
|
This sketch fades LEDs up and down one at a time on digital pins 2 through 13.
|
||||||
This sketch was written for the Arduino Mega, and will not work on previous boards.
|
This sketch was written for the Arduino Mega, and will not work on other boards.
|
||||||
|
|
||||||
The circuit:
|
The circuit:
|
||||||
* LEDs attached from pins 2 through 13 to ground.
|
* LEDs attached from pins 2 through 13 to ground.
|
||||||
@ -34,7 +34,7 @@ void loop() {
|
|||||||
analogWrite(thisPin, brightness);
|
analogWrite(thisPin, brightness);
|
||||||
delay(2);
|
delay(2);
|
||||||
}
|
}
|
||||||
// fade the LED on thisPin from brithstest to off:
|
// fade the LED on thisPin from brightest to off:
|
||||||
for (int brightness = 255; brightness >= 0; brightness--) {
|
for (int brightness = 255; brightness >= 0; brightness--) {
|
||||||
analogWrite(thisPin, brightness);
|
analogWrite(thisPin, brightness);
|
||||||
delay(2);
|
delay(2);
|
||||||
|
@ -24,7 +24,7 @@
|
|||||||
// Define the number of samples to keep track of. The higher the number,
|
// Define the number of samples to keep track of. The higher the number,
|
||||||
// the more the readings will be smoothed, but the slower the output will
|
// the more the readings will be smoothed, but the slower the output will
|
||||||
// respond to the input. Using a constant rather than a normal variable lets
|
// respond to the input. Using a constant rather than a normal variable lets
|
||||||
// use this value to determine the size of the readings array.
|
// us use this value to determine the size of the readings array.
|
||||||
const int numReadings = 10;
|
const int numReadings = 10;
|
||||||
|
|
||||||
int readings[numReadings]; // the readings from the analog input
|
int readings[numReadings]; // the readings from the analog input
|
||||||
|
@ -33,22 +33,22 @@ void setup() {
|
|||||||
// first visible ASCIIcharacter '!' is number 33:
|
// first visible ASCIIcharacter '!' is number 33:
|
||||||
int thisByte = 33;
|
int thisByte = 33;
|
||||||
// you can also write ASCII characters in single quotes.
|
// you can also write ASCII characters in single quotes.
|
||||||
// for example. '!' is the same as 33, so you could also use this:
|
// for example, '!' is the same as 33, so you could also use this:
|
||||||
//int thisByte = '!';
|
// int thisByte = '!';
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
// prints value unaltered, i.e. the raw binary version of the
|
// prints value unaltered, i.e. the raw binary version of the
|
||||||
// byte. The serial monitor interprets all bytes as
|
// byte. The Serial Monitor interprets all bytes as
|
||||||
// ASCII, so 33, the first number, will show up as '!'
|
// ASCII, so 33, the first number, will show up as '!'
|
||||||
Serial.write(thisByte);
|
Serial.write(thisByte);
|
||||||
|
|
||||||
Serial.print(", dec: ");
|
Serial.print(", dec: ");
|
||||||
// prints value as string as an ASCII-encoded decimal (base 10).
|
// prints value as string as an ASCII-encoded decimal (base 10).
|
||||||
// Decimal is the default format for Serial.print() and Serial.println(),
|
// Decimal is the default format for Serial.print() and Serial.println(),
|
||||||
// so no modifier is needed:
|
// so no modifier is needed:
|
||||||
Serial.print(thisByte);
|
Serial.print(thisByte);
|
||||||
// But you can declare the modifier for decimal if you want to.
|
// But you can declare the modifier for decimal if you want to.
|
||||||
//this also works if you uncomment it:
|
// this also works if you uncomment it:
|
||||||
|
|
||||||
// Serial.print(thisByte, DEC);
|
// Serial.print(thisByte, DEC);
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
Dimmer
|
Dimmer
|
||||||
|
|
||||||
Demonstrates the sending data from the computer to the Arduino board,
|
Demonstrates sending data from the computer to the Arduino board,
|
||||||
in this case to control the brightness of an LED. The data is sent
|
in this case to control the brightness of an LED. The data is sent
|
||||||
in individual bytes, each of which ranges from 0 to 255. Arduino
|
in individual bytes, each of which ranges from 0 to 255. Arduino
|
||||||
reads these bytes and uses them to set the brightness of the LED.
|
reads these bytes and uses them to set the brightness of the LED.
|
||||||
@ -45,7 +45,7 @@ void loop() {
|
|||||||
/* Processing code for this example
|
/* Processing code for this example
|
||||||
// Dimmer - sends bytes over a serial port
|
// Dimmer - sends bytes over a serial port
|
||||||
// by David A. Mellis
|
// by David A. Mellis
|
||||||
//This example code is in the public domain.
|
// This example code is in the public domain.
|
||||||
|
|
||||||
import processing.serial.*;
|
import processing.serial.*;
|
||||||
Serial port;
|
Serial port;
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
a USB cable. Bytes are sent one after another (serially) from the Arduino
|
a USB cable. Bytes are sent one after another (serially) from the Arduino
|
||||||
to the computer.
|
to the computer.
|
||||||
|
|
||||||
You can use the Arduino serial monitor to view the sent data, or it can
|
You can use the Arduino Serial Monitor to view the sent data, or it can
|
||||||
be read by Processing, PD, Max/MSP, or any other program capable of reading
|
be read by Processing, PD, Max/MSP, or any other program capable of reading
|
||||||
data from a serial port. The Processing code below graphs the data received
|
data from a serial port. The Processing code below graphs the data received
|
||||||
so you can see the value of the analog input changing over time.
|
so you can see the value of the analog input changing over time.
|
||||||
@ -67,15 +67,15 @@ void setup () {
|
|||||||
// if using Processing 2.1 or later, use Serial.printArray()
|
// if using Processing 2.1 or later, use Serial.printArray()
|
||||||
println(Serial.list());
|
println(Serial.list());
|
||||||
|
|
||||||
// I know that the first port in the serial list on my mac
|
// I know that the first port in the serial list on my Mac
|
||||||
// is always my Arduino, so I open Serial.list()[0].
|
// is always my Arduino, so I open Serial.list()[0].
|
||||||
// Open whatever port is the one you're using.
|
// Open whatever port is the one you're using.
|
||||||
myPort = new Serial(this, Serial.list()[0], 9600);
|
myPort = new Serial(this, Serial.list()[0], 9600);
|
||||||
|
|
||||||
// don't generate a serialEvent() unless you get a newline character:
|
// don't generate a serialEvent() unless you get a newline character:
|
||||||
myPort.bufferUntil('\n');
|
myPort.bufferUntil('\n');
|
||||||
|
|
||||||
// set inital background:
|
// set initial background:
|
||||||
background(0);
|
background(0);
|
||||||
}
|
}
|
||||||
void draw () {
|
void draw () {
|
||||||
|
@ -23,7 +23,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
// Set MIDI baud rate:
|
// Set MIDI baud rate:
|
||||||
Serial.begin(31250);
|
Serial.begin(31250);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -39,8 +39,8 @@ void loop() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// plays a MIDI note. Doesn't check to see that
|
// plays a MIDI note. Doesn't check to see that
|
||||||
// cmd is greater than 127, or that data values are less than 127:
|
// cmd is greater than 127, or that data values are less than 127:
|
||||||
void noteOn(int cmd, int pitch, int velocity) {
|
void noteOn(int cmd, int pitch, int velocity) {
|
||||||
Serial.write(cmd);
|
Serial.write(cmd);
|
||||||
Serial.write(pitch);
|
Serial.write(pitch);
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
Multple Serial test
|
Multiple Serial test
|
||||||
|
|
||||||
Receives from the main serial port, sends to the others.
|
Receives from the main serial port, sends to the others.
|
||||||
Receives from serial port 1, sends to the main serial (Serial 0).
|
Receives from serial port 1, sends to the main serial (Serial 0).
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
it receives the character 'H', and turns off the LED when it
|
it receives the character 'H', and turns off the LED when it
|
||||||
receives the character 'L'.
|
receives the character 'L'.
|
||||||
|
|
||||||
The data can be sent from the Arduino serial monitor, or another
|
The data can be sent from the Arduino Serial Monitor, or another
|
||||||
program like Processing (see code below), Flash (via a serial-net
|
program like Processing (see code below), Flash (via a serial-net
|
||||||
proxy), PD, or Max/MSP.
|
proxy), PD, or Max/MSP.
|
||||||
|
|
||||||
@ -51,7 +51,7 @@ void loop() {
|
|||||||
|
|
||||||
/* Processing code for this example
|
/* Processing code for this example
|
||||||
|
|
||||||
// mouseover serial
|
// mouse over serial
|
||||||
|
|
||||||
// Demonstrates how to send data to the Arduino I/O board, in order to
|
// Demonstrates how to send data to the Arduino I/O board, in order to
|
||||||
// turn ON a light if the mouse is over a square and turn it off
|
// turn ON a light if the mouse is over a square and turn it off
|
||||||
@ -108,7 +108,7 @@ void loop() {
|
|||||||
port.write('H');
|
port.write('H');
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// return the box to it's inactive state:
|
// return the box to its inactive state:
|
||||||
stroke(153);
|
stroke(153);
|
||||||
fill(153);
|
fill(153);
|
||||||
// send an 'L' to turn the LED off:
|
// send an 'L' to turn the LED off:
|
||||||
|
@ -51,7 +51,7 @@ void loop() {
|
|||||||
delay(10);
|
delay(10);
|
||||||
// read second analog input, divide by 4 to make the range 0-255:
|
// read second analog input, divide by 4 to make the range 0-255:
|
||||||
secondSensor = analogRead(1) / 4;
|
secondSensor = analogRead(1) / 4;
|
||||||
// read switch, map it to 0 or 255L
|
// read switch, map it to 0 or 255L
|
||||||
thirdSensor = map(digitalRead(2), 0, 1, 0, 255);
|
thirdSensor = map(digitalRead(2), 0, 1, 0, 255);
|
||||||
// send sensor values:
|
// send sensor values:
|
||||||
Serial.write(firstSensor);
|
Serial.write(firstSensor);
|
||||||
@ -94,8 +94,8 @@ void setup() {
|
|||||||
// if using Processing 2.1 or later, use Serial.printArray()
|
// if using Processing 2.1 or later, use Serial.printArray()
|
||||||
println(Serial.list());
|
println(Serial.list());
|
||||||
|
|
||||||
// I know that the first port in the serial list on my mac
|
// I know that the first port in the serial list on my Mac
|
||||||
// is always my FTDI adaptor, so I open Serial.list()[0].
|
// is always my FTDI adaptor, so I open Serial.list()[0].
|
||||||
// On Windows machines, this generally opens COM1.
|
// On Windows machines, this generally opens COM1.
|
||||||
// Open whatever port is the one you're using.
|
// Open whatever port is the one you're using.
|
||||||
String portName = Serial.list()[0];
|
String portName = Serial.list()[0];
|
||||||
|
@ -54,7 +54,7 @@ void loop() {
|
|||||||
firstSensor = analogRead(A0);
|
firstSensor = analogRead(A0);
|
||||||
// read second analog input:
|
// read second analog input:
|
||||||
secondSensor = analogRead(A1);
|
secondSensor = analogRead(A1);
|
||||||
// read switch, map it to 0 or 255L
|
// read switch, map it to 0 or 255
|
||||||
thirdSensor = map(digitalRead(2), 0, 1, 0, 255);
|
thirdSensor = map(digitalRead(2), 0, 1, 0, 255);
|
||||||
// send sensor values:
|
// send sensor values:
|
||||||
Serial.print(firstSensor);
|
Serial.print(firstSensor);
|
||||||
@ -92,8 +92,8 @@ void setup() {
|
|||||||
// if using Processing 2.1 or later, use Serial.printArray()
|
// if using Processing 2.1 or later, use Serial.printArray()
|
||||||
println(Serial.list());
|
println(Serial.list());
|
||||||
|
|
||||||
// I know that the first port in the serial list on my mac
|
// I know that the first port in the serial list on my Mac
|
||||||
// is always my Arduino module, so I open Serial.list()[0].
|
// is always my Arduino board, so I open Serial.list()[0].
|
||||||
// Change the 0 to the appropriate number of the serial port
|
// Change the 0 to the appropriate number of the serial port
|
||||||
// that your microcontroller is attached to.
|
// that your microcontroller is attached to.
|
||||||
myPort = new Serial(this, Serial.list()[0], 9600);
|
myPort = new Serial(this, Serial.list()[0], 9600);
|
||||||
@ -112,7 +112,7 @@ void draw() {
|
|||||||
ellipse(xpos, ypos, 20, 20);
|
ellipse(xpos, ypos, 20, 20);
|
||||||
}
|
}
|
||||||
|
|
||||||
// serialEvent method is run automatically by the Processing applet
|
// serialEvent method is run automatically by the Processing applet
|
||||||
// whenever the buffer reaches the byte value set in the bufferUntil()
|
// whenever the buffer reaches the byte value set in the bufferUntil()
|
||||||
// method in the setup():
|
// method in the setup():
|
||||||
|
|
||||||
|
@ -20,7 +20,7 @@
|
|||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
String inputString = ""; // a string to hold incoming data
|
String inputString = ""; // a String to hold incoming data
|
||||||
boolean stringComplete = false; // whether the string is complete
|
boolean stringComplete = false; // whether the string is complete
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
the Arduino UNO (commonly used to interact with devices/shields that
|
the Arduino UNO (commonly used to interact with devices/shields that
|
||||||
require configuration via serial AT commands) will not work by default.
|
require configuration via serial AT commands) will not work by default.
|
||||||
|
|
||||||
This sketch allows you to emulate the serial passthrough behaviour.
|
This sketch allows you to emulate the serial passthrough behaviour.
|
||||||
Any text you type in the IDE Serial monitor will be written
|
Any text you type in the IDE Serial monitor will be written
|
||||||
out to the serial port on Digital pins 0 and 1, and vice-versa.
|
out to the serial port on Digital pins 0 and 1, and vice-versa.
|
||||||
|
|
||||||
|
@ -51,8 +51,8 @@ void setup() {
|
|||||||
// if using Processing 2.1 or later, use Serial.printArray()
|
// if using Processing 2.1 or later, use Serial.printArray()
|
||||||
println(Serial.list());
|
println(Serial.list());
|
||||||
|
|
||||||
// I know that the first port in the serial list on my mac
|
// I know that the first port in the serial list on my Mac
|
||||||
// is always my Arduino, so I open Serial.list()[0].
|
// is always my Arduino, so I open Serial.list()[0].
|
||||||
// Open whatever port is the one you're using.
|
// Open whatever port is the one you're using.
|
||||||
myPort = new Serial(this, Serial.list()[0], 9600);
|
myPort = new Serial(this, Serial.list()[0], 9600);
|
||||||
// don't generate a serialEvent() unless you get a newline character:
|
// don't generate a serialEvent() unless you get a newline character:
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
Arrays
|
Arrays
|
||||||
|
|
||||||
Demonstrates the use of an array to hold pin numbers
|
Demonstrates the use of an array to hold pin numbers
|
||||||
in order to iterate over the pins in a sequence.
|
in order to iterate over the pins in a sequence.
|
||||||
Lights multiple LEDs in sequence, then in reverse.
|
Lights multiple LEDs in sequence, then in reverse.
|
||||||
|
|
||||||
|
@ -4,13 +4,13 @@
|
|||||||
This example demonstrates the use of while() statements.
|
This example demonstrates the use of while() statements.
|
||||||
|
|
||||||
While the pushbutton is pressed, the sketch runs the calibration routine.
|
While the pushbutton is pressed, the sketch runs the calibration routine.
|
||||||
The sensor readings during the while loop define the minimum and maximum
|
The sensor readings during the while loop define the minimum and maximum
|
||||||
of expected values from the photo resistor.
|
of expected values from the photoresistor.
|
||||||
|
|
||||||
This is a variation on the calibrate example.
|
This is a variation on the calibrate example.
|
||||||
|
|
||||||
The circuit:
|
The circuit:
|
||||||
* photo resistor connected from +5V to analog in pin 0
|
* photoresistor connected from +5V to analog in pin 0
|
||||||
* 10K resistor connected from ground to analog in pin 0
|
* 10K resistor connected from ground to analog in pin 0
|
||||||
* LED connected from digital pin 9 to ground through 220 ohm resistor
|
* LED connected from digital pin 9 to ground through 220 ohm resistor
|
||||||
* pushbutton attached from pin 2 to +5V
|
* pushbutton attached from pin 2 to +5V
|
||||||
|
@ -5,9 +5,9 @@
|
|||||||
statement allows you to choose from among a set of discrete values
|
statement allows you to choose from among a set of discrete values
|
||||||
of a variable. It's like a series of if statements.
|
of a variable. It's like a series of if statements.
|
||||||
|
|
||||||
To see this sketch in action, but the board and sensor in a well-lit
|
To see this sketch in action, put the board and sensor in a well-lit
|
||||||
room, open the serial monitor, and and move your hand gradually
|
room, open the Serial Monitor, and move your hand gradually down
|
||||||
down over the sensor.
|
over the sensor.
|
||||||
|
|
||||||
The circuit:
|
The circuit:
|
||||||
* photoresistor from analog in 0 to +5V
|
* photoresistor from analog in 0 to +5V
|
||||||
|
@ -35,7 +35,7 @@ void loop() {
|
|||||||
int inByte = Serial.read();
|
int inByte = Serial.read();
|
||||||
// do something different depending on the character received.
|
// do something different depending on the character received.
|
||||||
// The switch statement expects single number values for each case;
|
// The switch statement expects single number values for each case;
|
||||||
// in this exmaple, though, you're using single quotes to tell
|
// in this example, though, you're using single quotes to tell
|
||||||
// the controller to get the ASCII value for the character. For
|
// the controller to get the ASCII value for the character. For
|
||||||
// example 'a' = 97, 'b' = 98, and so forth:
|
// example 'a' = 97, 'b' = 98, and so forth:
|
||||||
|
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
Reads an Analog Devices ADXL3xx accelerometer and communicates the
|
Reads an Analog Devices ADXL3xx accelerometer and communicates the
|
||||||
acceleration to the computer. The pins used are designed to be easily
|
acceleration to the computer. The pins used are designed to be easily
|
||||||
compatible with the breakout boards from Sparkfun, available from:
|
compatible with the breakout boards from SparkFun, available from:
|
||||||
http://www.sparkfun.com/commerce/categories.php?c=80
|
http://www.sparkfun.com/commerce/categories.php?c=80
|
||||||
|
|
||||||
http://www.arduino.cc/en/Tutorial/ADXL3xx
|
http://www.arduino.cc/en/Tutorial/ADXL3xx
|
||||||
|
@ -23,7 +23,7 @@
|
|||||||
|
|
||||||
|
|
||||||
// these constants won't change:
|
// these constants won't change:
|
||||||
const int ledPin = 13; // led connected to digital pin 13
|
const int ledPin = 13; // LED connected to digital pin 13
|
||||||
const int knockSensor = A0; // the piezo is connected to analog pin 0
|
const int knockSensor = A0; // the piezo is connected to analog pin 0
|
||||||
const int threshold = 100; // threshold value to decide when the detected sound is a knock or not
|
const int threshold = 100; // threshold value to decide when the detected sound is a knock or not
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
Memsic2125
|
Memsic2125
|
||||||
|
|
||||||
Read the Memsic 2125 two-axis accelerometer. Converts the
|
Read the Memsic 2125 two-axis accelerometer. Converts the
|
||||||
pulses output by the 2125 into milli-g's (1/1000 of earth's
|
pulses output by the 2125 into milli-g's (1/1000 of Earth's
|
||||||
gravity) and prints them over the serial connection to the
|
gravity) and prints them over the serial connection to the
|
||||||
computer.
|
computer.
|
||||||
|
|
||||||
@ -48,7 +48,7 @@ void loop() {
|
|||||||
|
|
||||||
// convert the pulse width into acceleration
|
// convert the pulse width into acceleration
|
||||||
// accelerationX and accelerationY are in milli-g's:
|
// accelerationX and accelerationY are in milli-g's:
|
||||||
// earth's gravity is 1000 milli-g's, or 1g.
|
// Earth's gravity is 1000 milli-g's, or 1 g.
|
||||||
accelerationX = ((pulseX / 10) - 500) * 8;
|
accelerationX = ((pulseX / 10) - 500) * 8;
|
||||||
accelerationY = ((pulseY / 10) - 500) * 8;
|
accelerationY = ((pulseY / 10) - 500) * 8;
|
||||||
|
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
modified 30 Aug 2011
|
modified 30 Aug 2011
|
||||||
by Tom Igoe
|
by Tom Igoe
|
||||||
|
|
||||||
This example works for the Lumex LDM-24488NI Matrix. See
|
This example works for the Lumex LDM-24488NI Matrix. See
|
||||||
http://sigma.octopart.com/140413/datasheet/Lumex-LDM-24488NI.pdf
|
http://sigma.octopart.com/140413/datasheet/Lumex-LDM-24488NI.pdf
|
||||||
for the pin connections
|
for the pin connections
|
||||||
|
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
/*
|
/*
|
||||||
Adding Strings together
|
Adding Strings together
|
||||||
|
|
||||||
Examples of how to add strings together
|
Examples of how to add Strings together
|
||||||
You can also add several different data types to string, as shown here:
|
You can also add several different data types to String, as shown here:
|
||||||
|
|
||||||
created 27 July 2010
|
created 27 July 2010
|
||||||
modified 2 Apr 2012
|
modified 2 Apr 2012
|
||||||
@ -13,7 +13,7 @@
|
|||||||
This example code is in the public domain.
|
This example code is in the public domain.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// declare three strings:
|
// declare three Strings:
|
||||||
String stringOne, stringTwo, stringThree;
|
String stringOne, stringTwo, stringThree;
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
@ -27,40 +27,40 @@ void setup() {
|
|||||||
stringTwo = String("this string");
|
stringTwo = String("this string");
|
||||||
stringThree = String();
|
stringThree = String();
|
||||||
// send an intro:
|
// send an intro:
|
||||||
Serial.println("\n\nAdding strings together (concatenation):");
|
Serial.println("\n\nAdding Strings together (concatenation):");
|
||||||
Serial.println();
|
Serial.println();
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
// adding a constant integer to a string:
|
// adding a constant integer to a String:
|
||||||
stringThree = stringOne + 123;
|
stringThree = stringOne + 123;
|
||||||
Serial.println(stringThree); // prints "You added 123"
|
Serial.println(stringThree); // prints "You added 123"
|
||||||
|
|
||||||
// adding a constant long interger to a string:
|
// adding a constant long integer to a String:
|
||||||
stringThree = stringOne + 123456789;
|
stringThree = stringOne + 123456789;
|
||||||
Serial.println(stringThree); // prints "You added 123456789"
|
Serial.println(stringThree); // prints "You added 123456789"
|
||||||
|
|
||||||
// adding a constant character to a string:
|
// adding a constant character to a String:
|
||||||
stringThree = stringOne + 'A';
|
stringThree = stringOne + 'A';
|
||||||
Serial.println(stringThree); // prints "You added A"
|
Serial.println(stringThree); // prints "You added A"
|
||||||
|
|
||||||
// adding a constant string to a string:
|
// adding a constant string to a String:
|
||||||
stringThree = stringOne + "abc";
|
stringThree = stringOne + "abc";
|
||||||
Serial.println(stringThree); // prints "You added abc"
|
Serial.println(stringThree); // prints "You added abc"
|
||||||
|
|
||||||
stringThree = stringOne + stringTwo;
|
stringThree = stringOne + stringTwo;
|
||||||
Serial.println(stringThree); // prints "You added this string"
|
Serial.println(stringThree); // prints "You added this string"
|
||||||
|
|
||||||
// adding a variable integer to a string:
|
// adding a variable integer to a String:
|
||||||
int sensorValue = analogRead(A0);
|
int sensorValue = analogRead(A0);
|
||||||
stringOne = "Sensor value: ";
|
stringOne = "Sensor value: ";
|
||||||
stringThree = stringOne + sensorValue;
|
stringThree = stringOne + sensorValue;
|
||||||
Serial.println(stringThree); // prints "Sensor Value: 401" or whatever value analogRead(A0) has
|
Serial.println(stringThree); // prints "Sensor Value: 401" or whatever value analogRead(A0) has
|
||||||
|
|
||||||
// adding a variable long integer to a string:
|
// adding a variable long integer to a String:
|
||||||
stringOne = "millis() value: ";
|
stringOne = "millis() value: ";
|
||||||
stringThree = stringOne + millis();
|
stringThree = stringOne + millis();
|
||||||
Serial.println(stringThree); // prints "The millis: 345345" or whatever value currentTime has
|
Serial.println(stringThree); // prints "The millis: 345345" or whatever value millis() has
|
||||||
|
|
||||||
// do nothing while true:
|
// do nothing while true:
|
||||||
while (true);
|
while (true);
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
Appending to Strings using the += operator and concat()
|
Appending to Strings using the += operator and concat()
|
||||||
|
|
||||||
Examples of how to append different data types to strings
|
Examples of how to append different data types to Strings
|
||||||
|
|
||||||
created 27 July 2010
|
created 27 July 2010
|
||||||
modified 2 Apr 2012
|
modified 2 Apr 2012
|
||||||
@ -24,34 +24,34 @@ void setup() {
|
|||||||
stringOne = String("Sensor ");
|
stringOne = String("Sensor ");
|
||||||
stringTwo = String("value");
|
stringTwo = String("value");
|
||||||
// send an intro:
|
// send an intro:
|
||||||
Serial.println("\n\nAppending to a string:");
|
Serial.println("\n\nAppending to a String:");
|
||||||
Serial.println();
|
Serial.println();
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
Serial.println(stringOne); // prints "Sensor "
|
Serial.println(stringOne); // prints "Sensor "
|
||||||
|
|
||||||
// adding a string to a string:
|
// adding a string to a String:
|
||||||
stringOne += stringTwo;
|
stringOne += stringTwo;
|
||||||
Serial.println(stringOne); // prints "Sensor value"
|
Serial.println(stringOne); // prints "Sensor value"
|
||||||
|
|
||||||
// adding a constant string to a string:
|
// adding a constant string to a String:
|
||||||
stringOne += " for input ";
|
stringOne += " for input ";
|
||||||
Serial.println(stringOne); // prints "Sensor value for input"
|
Serial.println(stringOne); // prints "Sensor value for input"
|
||||||
|
|
||||||
// adding a constant character to a string:
|
// adding a constant character to a String:
|
||||||
stringOne += 'A';
|
stringOne += 'A';
|
||||||
Serial.println(stringOne); // prints "Sensor value for input A"
|
Serial.println(stringOne); // prints "Sensor value for input A"
|
||||||
|
|
||||||
// adding a constant integer to a string:
|
// adding a constant integer to a String:
|
||||||
stringOne += 0;
|
stringOne += 0;
|
||||||
Serial.println(stringOne); // prints "Sensor value for input A0"
|
Serial.println(stringOne); // prints "Sensor value for input A0"
|
||||||
|
|
||||||
// adding a constant string to a string:
|
// adding a constant string to a String:
|
||||||
stringOne += ": ";
|
stringOne += ": ";
|
||||||
Serial.println(stringOne); // prints "Sensor value for input"
|
Serial.println(stringOne); // prints "Sensor value for input"
|
||||||
|
|
||||||
// adding a variable integer to a string:
|
// adding a variable integer to a String:
|
||||||
stringOne += analogRead(A0);
|
stringOne += analogRead(A0);
|
||||||
Serial.println(stringOne); // prints "Sensor value for input A0: 456" or whatever analogRead(A0) is
|
Serial.println(stringOne); // prints "Sensor value for input A0: 456" or whatever analogRead(A0) is
|
||||||
|
|
||||||
@ -59,11 +59,11 @@ void loop() {
|
|||||||
stringOne = "A long integer: ";
|
stringOne = "A long integer: ";
|
||||||
stringTwo = "The millis(): ";
|
stringTwo = "The millis(): ";
|
||||||
|
|
||||||
// adding a constant long integer to a string:
|
// adding a constant long integer to a String:
|
||||||
stringOne += 123456789;
|
stringOne += 123456789;
|
||||||
Serial.println(stringOne); // prints "A long integer: 123456789"
|
Serial.println(stringOne); // prints "A long integer: 123456789"
|
||||||
|
|
||||||
// using concat() to add a long variable to a string:
|
// using concat() to add a long variable to a String:
|
||||||
stringTwo.concat(millis());
|
stringTwo.concat(millis());
|
||||||
Serial.println(stringTwo); // prints "The millis(): 43534" or whatever the value of the millis() is
|
Serial.println(stringTwo); // prints "The millis(): 43534" or whatever the value of the millis() is
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
String Case changes
|
String Case changes
|
||||||
|
|
||||||
Examples of how to change the case of a string
|
Examples of how to change the case of a String
|
||||||
|
|
||||||
created 27 July 2010
|
created 27 July 2010
|
||||||
modified 2 Apr 2012
|
modified 2 Apr 2012
|
||||||
@ -20,7 +20,7 @@ void setup() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// send an intro:
|
// send an intro:
|
||||||
Serial.println("\n\nString case changes:");
|
Serial.println("\n\nString case changes:");
|
||||||
Serial.println();
|
Serial.println();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,11 +19,11 @@ void setup() {
|
|||||||
; // wait for serial port to connect. Needed for native USB port only
|
; // wait for serial port to connect. Needed for native USB port only
|
||||||
}
|
}
|
||||||
|
|
||||||
Serial.println("\n\nString charAt() and setCharAt():");
|
Serial.println("\n\nString charAt() and setCharAt():");
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
// make a string to report a sensor reading:
|
// make a String to report a sensor reading:
|
||||||
String reportString = "SensorReading: 456";
|
String reportString = "SensorReading: 456";
|
||||||
Serial.println(reportString);
|
Serial.println(reportString);
|
||||||
|
|
||||||
@ -36,7 +36,7 @@ void loop() {
|
|||||||
// add blank space:
|
// add blank space:
|
||||||
Serial.println();
|
Serial.println();
|
||||||
|
|
||||||
// you can alo set the character of a string. Change the : to a = character
|
// you can also set the character of a String. Change the : to a = character
|
||||||
reportString.setCharAt(13, '=');
|
reportString.setCharAt(13, '=');
|
||||||
Serial.println(reportString);
|
Serial.println(reportString);
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
Comparing Strings
|
Comparing Strings
|
||||||
|
|
||||||
Examples of how to compare strings using the comparison operators
|
Examples of how to compare Strings using the comparison operators
|
||||||
|
|
||||||
created 27 July 2010
|
created 27 July 2010
|
||||||
modified 2 Apr 2012
|
modified 2 Apr 2012
|
||||||
@ -31,22 +31,22 @@ void setup() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
// two strings equal:
|
// two Strings equal:
|
||||||
if (stringOne == "this") {
|
if (stringOne == "this") {
|
||||||
Serial.println("StringOne == \"this\"");
|
Serial.println("StringOne == \"this\"");
|
||||||
}
|
}
|
||||||
// two strings not equal:
|
// two Strings not equal:
|
||||||
if (stringOne != stringTwo) {
|
if (stringOne != stringTwo) {
|
||||||
Serial.println(stringOne + " =! " + stringTwo);
|
Serial.println(stringOne + " =! " + stringTwo);
|
||||||
}
|
}
|
||||||
|
|
||||||
// two strings not equal (case sensitivity matters):
|
// two Strings not equal (case sensitivity matters):
|
||||||
stringOne = "This";
|
stringOne = "This";
|
||||||
stringTwo = "this";
|
stringTwo = "this";
|
||||||
if (stringOne != stringTwo) {
|
if (stringOne != stringTwo) {
|
||||||
Serial.println(stringOne + " =! " + stringTwo);
|
Serial.println(stringOne + " =! " + stringTwo);
|
||||||
}
|
}
|
||||||
// you can also use equals() to see if two strings are the same:
|
// you can also use equals() to see if two Strings are the same:
|
||||||
if (stringOne.equals(stringTwo)) {
|
if (stringOne.equals(stringTwo)) {
|
||||||
Serial.println(stringOne + " equals " + stringTwo);
|
Serial.println(stringOne + " equals " + stringTwo);
|
||||||
} else {
|
} else {
|
||||||
@ -60,7 +60,7 @@ void loop() {
|
|||||||
Serial.println(stringOne + " does not equal (ignoring case) " + stringTwo);
|
Serial.println(stringOne + " does not equal (ignoring case) " + stringTwo);
|
||||||
}
|
}
|
||||||
|
|
||||||
// a numeric string compared to the number it represents:
|
// a numeric String compared to the number it represents:
|
||||||
stringOne = "1";
|
stringOne = "1";
|
||||||
int numberOne = 1;
|
int numberOne = 1;
|
||||||
if (stringOne.toInt() == numberOne) {
|
if (stringOne.toInt() == numberOne) {
|
||||||
@ -69,14 +69,14 @@ void loop() {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
// two numeric strings compared:
|
// two numeric Strings compared:
|
||||||
stringOne = "2";
|
stringOne = "2";
|
||||||
stringTwo = "1";
|
stringTwo = "1";
|
||||||
if (stringOne >= stringTwo) {
|
if (stringOne >= stringTwo) {
|
||||||
Serial.println(stringOne + " >= " + stringTwo);
|
Serial.println(stringOne + " >= " + stringTwo);
|
||||||
}
|
}
|
||||||
|
|
||||||
// comparison operators can be used to compare strings for alphabetic sorting too:
|
// comparison operators can be used to compare Strings for alphabetic sorting too:
|
||||||
stringOne = String("Brown");
|
stringOne = String("Brown");
|
||||||
if (stringOne < "Charles") {
|
if (stringOne < "Charles") {
|
||||||
Serial.println(stringOne + " < Charles");
|
Serial.println(stringOne + " < Charles");
|
||||||
@ -95,9 +95,9 @@ void loop() {
|
|||||||
Serial.println(stringOne + " >= Brow");
|
Serial.println(stringOne + " >= Brow");
|
||||||
}
|
}
|
||||||
|
|
||||||
// the compareTo() operator also allows you to compare strings
|
// the compareTo() operator also allows you to compare Strings
|
||||||
// it evaluates on the first character that's different.
|
// it evaluates on the first character that's different.
|
||||||
// if the first character of the string you're comparing to
|
// if the first character of the String you're comparing to
|
||||||
// comes first in alphanumeric order, then compareTo() is greater than 0:
|
// comes first in alphanumeric order, then compareTo() is greater than 0:
|
||||||
stringOne = "Cucumber";
|
stringOne = "Cucumber";
|
||||||
stringTwo = "Cucuracha";
|
stringTwo = "Cucuracha";
|
||||||
@ -109,7 +109,7 @@ void loop() {
|
|||||||
|
|
||||||
delay(10000); // because the next part is a loop:
|
delay(10000); // because the next part is a loop:
|
||||||
|
|
||||||
// compareTo() is handy when you've got strings with numbers in them too:
|
// compareTo() is handy when you've got Strings with numbers in them too:
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
stringOne = "Sensor: ";
|
stringOne = "Sensor: ";
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
String constructors
|
String constructors
|
||||||
|
|
||||||
Examples of how to create strings from other data types
|
Examples of how to create Strings from other data types
|
||||||
|
|
||||||
created 27 July 2010
|
created 27 July 2010
|
||||||
modified 30 Aug 2011
|
modified 30 Aug 2011
|
||||||
@ -66,11 +66,11 @@ void loop() {
|
|||||||
// prints "123456" or whatever the value of millis() is:
|
// prints "123456" or whatever the value of millis() is:
|
||||||
Serial.println(stringOne);
|
Serial.println(stringOne);
|
||||||
|
|
||||||
//using a float and the right decimal places:
|
// using a float and the right decimal places:
|
||||||
stringOne = String(5.698, 3);
|
stringOne = String(5.698, 3);
|
||||||
Serial.println(stringOne);
|
Serial.println(stringOne);
|
||||||
|
|
||||||
//using a float and less decimal places to use rounding:
|
// using a float and less decimal places to use rounding:
|
||||||
stringOne = String(5.698, 2);
|
stringOne = String(5.698, 2);
|
||||||
Serial.println(stringOne);
|
Serial.println(stringOne);
|
||||||
|
|
||||||
|
@ -26,7 +26,7 @@ void setup() {
|
|||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
// indexOf() returns the position (i.e. index) of a particular character
|
// indexOf() returns the position (i.e. index) of a particular character
|
||||||
// in a string. For example, if you were parsing HTML tags, you could use it:
|
// in a String. For example, if you were parsing HTML tags, you could use it:
|
||||||
String stringOne = "<HTML><HEAD><BODY>";
|
String stringOne = "<HTML><HEAD><BODY>";
|
||||||
int firstClosingBracket = stringOne.indexOf('>');
|
int firstClosingBracket = stringOne.indexOf('>');
|
||||||
Serial.println("The index of > in the string " + stringOne + " is " + firstClosingBracket);
|
Serial.println("The index of > in the string " + stringOne + " is " + firstClosingBracket);
|
||||||
|
@ -20,7 +20,7 @@ void setup() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// send an intro:
|
// send an intro:
|
||||||
Serial.println("\n\nString length() and trim():");
|
Serial.println("\n\nString length() and trim():");
|
||||||
Serial.println();
|
Serial.println();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
String replace()
|
String replace()
|
||||||
|
|
||||||
Examples of how to replace characters or substrings of a string
|
Examples of how to replace characters or substrings of a String
|
||||||
|
|
||||||
created 27 July 2010
|
created 27 July 2010
|
||||||
modified 2 Apr 2012
|
modified 2 Apr 2012
|
||||||
@ -20,7 +20,7 @@ void setup() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// send an intro:
|
// send an intro:
|
||||||
Serial.println("\n\nString replace:\n");
|
Serial.println("\n\nString replace:\n");
|
||||||
Serial.println();
|
Serial.println();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -28,7 +28,7 @@ void loop() {
|
|||||||
String stringOne = "<html><head><body>";
|
String stringOne = "<html><head><body>";
|
||||||
Serial.println(stringOne);
|
Serial.println(stringOne);
|
||||||
// replace() changes all instances of one substring with another:
|
// replace() changes all instances of one substring with another:
|
||||||
// first, make a copy of th original string:
|
// first, make a copy of the original string:
|
||||||
String stringTwo = stringOne;
|
String stringTwo = stringOne;
|
||||||
// then perform the replacements:
|
// then perform the replacements:
|
||||||
stringTwo.replace("<", "</");
|
stringTwo.replace("<", "</");
|
||||||
|
@ -36,7 +36,7 @@ int platform = OSX;
|
|||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
// make pin 2 an input and turn on the
|
// make pin 2 an input and turn on the
|
||||||
// pullup resistor so it goes high unless
|
// pull-up resistor so it goes high unless
|
||||||
// connected to ground:
|
// connected to ground:
|
||||||
pinMode(2, INPUT_PULLUP);
|
pinMode(2, INPUT_PULLUP);
|
||||||
Keyboard.begin();
|
Keyboard.begin();
|
||||||
@ -67,7 +67,7 @@ void loop() {
|
|||||||
Keyboard.press(KEY_DELETE);
|
Keyboard.press(KEY_DELETE);
|
||||||
delay(100);
|
delay(100);
|
||||||
Keyboard.releaseAll();
|
Keyboard.releaseAll();
|
||||||
//ALT-l:
|
// ALT-l:
|
||||||
delay(2000);
|
delay(2000);
|
||||||
Keyboard.press(KEY_LEFT_ALT);
|
Keyboard.press(KEY_LEFT_ALT);
|
||||||
Keyboard.press('l');
|
Keyboard.press('l');
|
||||||
|
@ -39,7 +39,7 @@ char ctrlKey = KEY_LEFT_GUI;
|
|||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
// make pin 2 an input and turn on the
|
// make pin 2 an input and turn on the
|
||||||
// pullup resistor so it goes high unless
|
// pull-up resistor so it goes high unless
|
||||||
// connected to ground:
|
// connected to ground:
|
||||||
pinMode(2, INPUT_PULLUP);
|
pinMode(2, INPUT_PULLUP);
|
||||||
// initialize control over the keyboard:
|
// initialize control over the keyboard:
|
||||||
@ -63,7 +63,7 @@ void loop() {
|
|||||||
// versions of the Arduino IDE after 1.5 pre-populate
|
// versions of the Arduino IDE after 1.5 pre-populate
|
||||||
// new sketches with setup() and loop() functions
|
// new sketches with setup() and loop() functions
|
||||||
// let's clear the window before typing anything new
|
// let's clear the window before typing anything new
|
||||||
// select all
|
// select all
|
||||||
Keyboard.press(ctrlKey);
|
Keyboard.press(ctrlKey);
|
||||||
Keyboard.press('a');
|
Keyboard.press('a');
|
||||||
delay(500);
|
delay(500);
|
||||||
|
@ -108,7 +108,7 @@ int readAxis(int thisAxis) {
|
|||||||
reading = map(reading, 0, 1023, 0, range);
|
reading = map(reading, 0, 1023, 0, range);
|
||||||
|
|
||||||
// if the output reading is outside from the
|
// if the output reading is outside from the
|
||||||
// rest position threshold, use it:
|
// rest position threshold, use it:
|
||||||
int distance = reading - center;
|
int distance = reading - center;
|
||||||
|
|
||||||
if (abs(distance) < threshold) {
|
if (abs(distance) < threshold) {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
Arduino Starter Kit example
|
Arduino Starter Kit example
|
||||||
Project 2 - Spaceship Interface
|
Project 2 - Spaceship Interface
|
||||||
|
|
||||||
This sketch is written to accompany Project 2 in the
|
This sketch is written to accompany Project 2 in the
|
||||||
Arduino Starter Kit
|
Arduino Starter Kit
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
Arduino Starter Kit example
|
Arduino Starter Kit example
|
||||||
Project 3 - Love-O-Meter
|
Project 3 - Love-O-Meter
|
||||||
|
|
||||||
This sketch is written to accompany Project 3 in the
|
This sketch is written to accompany Project 3 in the
|
||||||
Arduino Starter Kit
|
Arduino Starter Kit
|
||||||
@ -20,7 +20,7 @@
|
|||||||
|
|
||||||
// named constant for the pin the sensor is connected to
|
// named constant for the pin the sensor is connected to
|
||||||
const int sensorPin = A0;
|
const int sensorPin = A0;
|
||||||
// room temperature in Celcius
|
// room temperature in Celsius
|
||||||
const float baselineTemp = 20.0;
|
const float baselineTemp = 20.0;
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
@ -53,7 +53,7 @@ void loop() {
|
|||||||
// convert the voltage to temperature in degrees C
|
// convert the voltage to temperature in degrees C
|
||||||
// the sensor changes 10 mV per degree
|
// the sensor changes 10 mV per degree
|
||||||
// the datasheet says there's a 500 mV offset
|
// the datasheet says there's a 500 mV offset
|
||||||
// ((volatge - 500mV) times 100)
|
// ((voltage - 500 mV) times 100)
|
||||||
Serial.print(", degrees C: ");
|
Serial.print(", degrees C: ");
|
||||||
float temperature = (voltage - .5) * 100;
|
float temperature = (voltage - .5) * 100;
|
||||||
Serial.println(temperature);
|
Serial.println(temperature);
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
Arduino Starter Kit example
|
Arduino Starter Kit example
|
||||||
Project 4 - Color Mixing Lamp
|
Project 4 - Color Mixing Lamp
|
||||||
|
|
||||||
This sketch is written to accompany Project 3 in the
|
This sketch is written to accompany Project 3 in the
|
||||||
Arduino Starter Kit
|
Arduino Starter Kit
|
||||||
@ -62,7 +62,7 @@ void loop() {
|
|||||||
// read the value from the blue-filtered photoresistor:
|
// read the value from the blue-filtered photoresistor:
|
||||||
blueSensorValue = analogRead(blueSensorPin);
|
blueSensorValue = analogRead(blueSensorPin);
|
||||||
|
|
||||||
// print out the values to the serial monitor
|
// print out the values to the Serial Monitor
|
||||||
Serial.print("raw sensor Values \t red: ");
|
Serial.print("raw sensor Values \t red: ");
|
||||||
Serial.print(redSensorValue);
|
Serial.print(redSensorValue);
|
||||||
Serial.print("\t green: ");
|
Serial.print("\t green: ");
|
||||||
@ -80,7 +80,7 @@ void loop() {
|
|||||||
greenValue = greenSensorValue / 4;
|
greenValue = greenSensorValue / 4;
|
||||||
blueValue = blueSensorValue / 4;
|
blueValue = blueSensorValue / 4;
|
||||||
|
|
||||||
// print out the mapped values
|
// print out the mapped values
|
||||||
Serial.print("Mapped sensor Values \t red: ");
|
Serial.print("Mapped sensor Values \t red: ");
|
||||||
Serial.print(redValue);
|
Serial.print(redValue);
|
||||||
Serial.print("\t green: ");
|
Serial.print("\t green: ");
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
Arduino Starter Kit example
|
Arduino Starter Kit example
|
||||||
Project 5 - Servo Mood Indicator
|
Project 5 - Servo Mood Indicator
|
||||||
|
|
||||||
This sketch is written to accompany Project 5 in the
|
This sketch is written to accompany Project 5 in the
|
||||||
Arduino Starter Kit
|
Arduino Starter Kit
|
||||||
@ -18,7 +18,7 @@
|
|||||||
This example code is part of the public domain
|
This example code is part of the public domain
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// include the servo library
|
// include the Servo library
|
||||||
#include <Servo.h>
|
#include <Servo.h>
|
||||||
|
|
||||||
Servo myServo; // create a servo object
|
Servo myServo; // create a servo object
|
||||||
@ -34,7 +34,7 @@ void setup() {
|
|||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
potVal = analogRead(potPin); // read the value of the potentiometer
|
potVal = analogRead(potPin); // read the value of the potentiometer
|
||||||
// print out the value to the serial monitor
|
// print out the value to the Serial Monitor
|
||||||
Serial.print("potVal: ");
|
Serial.print("potVal: ");
|
||||||
Serial.print(potVal);
|
Serial.print(potVal);
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
Arduino Starter Kit example
|
Arduino Starter Kit example
|
||||||
Project 6 - Light Theremin
|
Project 6 - Light Theremin
|
||||||
|
|
||||||
This sketch is written to accompany Project 6 in the
|
This sketch is written to accompany Project 6 in the
|
||||||
Arduino Starter Kit
|
Arduino Starter Kit
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
Arduino Starter Kit example
|
Arduino Starter Kit example
|
||||||
Project 7 - Keyboard
|
Project 7 - Keyboard
|
||||||
|
|
||||||
This sketch is written to accompany Project 7 in the
|
This sketch is written to accompany Project 7 in the
|
||||||
Arduino Starter Kit
|
Arduino Starter Kit
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
Arduino Starter Kit example
|
Arduino Starter Kit example
|
||||||
Project 8 - Digital Hourglass
|
Project 8 - Digital Hourglass
|
||||||
|
|
||||||
This sketch is written to accompany Project 8 in the
|
This sketch is written to accompany Project 8 in the
|
||||||
Arduino Starter Kit
|
Arduino Starter Kit
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
Arduino Starter Kit example
|
Arduino Starter Kit example
|
||||||
Project 9 - Motorized Pinwheel
|
Project 9 - Motorized Pinwheel
|
||||||
|
|
||||||
This sketch is written to accompany Project 9 in the
|
This sketch is written to accompany Project 9 in the
|
||||||
Arduino Starter Kit
|
Arduino Starter Kit
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
Arduino Starter Kit example
|
Arduino Starter Kit example
|
||||||
Project 10 - Zoetrope
|
Project 10 - Zoetrope
|
||||||
|
|
||||||
This sketch is written to accompany Project 10 in the
|
This sketch is written to accompany Project 10 in the
|
||||||
Arduino Starter Kit
|
Arduino Starter Kit
|
||||||
@ -30,7 +30,7 @@ const int onOffSwitchStateSwitchPin = 5; // connected to the switch for turning
|
|||||||
const int potPin = A0; // connected to the potentiometer's output
|
const int potPin = A0; // connected to the potentiometer's output
|
||||||
|
|
||||||
// create some variables to hold values from your inputs
|
// create some variables to hold values from your inputs
|
||||||
int onOffSwitchState = 0; // current state of the On/Off switch
|
int onOffSwitchState = 0; // current state of the on/off switch
|
||||||
int previousOnOffSwitchState = 0; // previous position of the on/off switch
|
int previousOnOffSwitchState = 0; // previous position of the on/off switch
|
||||||
int directionSwitchState = 0; // current state of the direction switch
|
int directionSwitchState = 0; // current state of the direction switch
|
||||||
int previousDirectionSwitchState = 0; // previous state of the direction switch
|
int previousDirectionSwitchState = 0; // previous state of the direction switch
|
||||||
@ -40,7 +40,7 @@ int motorSpeed = 0; // speed of the motor
|
|||||||
int motorDirection = 1; // current direction of the motor
|
int motorDirection = 1; // current direction of the motor
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
// intialize the inputs and outputs
|
// initialize the inputs and outputs
|
||||||
pinMode(directionSwitchPin, INPUT);
|
pinMode(directionSwitchPin, INPUT);
|
||||||
pinMode(onOffSwitchStateSwitchPin, INPUT);
|
pinMode(onOffSwitchStateSwitchPin, INPUT);
|
||||||
pinMode(controlPin1, OUTPUT);
|
pinMode(controlPin1, OUTPUT);
|
||||||
@ -97,7 +97,7 @@ void loop() {
|
|||||||
//turn the motor off
|
//turn the motor off
|
||||||
analogWrite(enablePin, 0);
|
analogWrite(enablePin, 0);
|
||||||
}
|
}
|
||||||
// save the current On/Offswitch state as the previous
|
// save the current on/off switch state as the previous
|
||||||
previousDirectionSwitchState = directionSwitchState;
|
previousDirectionSwitchState = directionSwitchState;
|
||||||
// save the current switch state as the previous
|
// save the current switch state as the previous
|
||||||
previousOnOffSwitchState = onOffSwitchState;
|
previousOnOffSwitchState = onOffSwitchState;
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
Arduino Starter Kit example
|
Arduino Starter Kit example
|
||||||
Project 11 - Crystal Ball
|
Project 11 - Crystal Ball
|
||||||
|
|
||||||
This sketch is written to accompany Project 11 in the
|
This sketch is written to accompany Project 11 in the
|
||||||
Arduino Starter Kit
|
Arduino Starter Kit
|
||||||
@ -27,13 +27,13 @@
|
|||||||
// initialize the library with the numbers of the interface pins
|
// initialize the library with the numbers of the interface pins
|
||||||
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
|
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
|
||||||
|
|
||||||
// set up a constant for the tilt switchPin
|
// set up a constant for the tilt switch pin
|
||||||
const int switchPin = 6;
|
const int switchPin = 6;
|
||||||
|
|
||||||
// variable to hold the value of the switchPin
|
// variable to hold the value of the switch pin
|
||||||
int switchState = 0;
|
int switchState = 0;
|
||||||
|
|
||||||
// variable to hold previous value of the switchpin
|
// variable to hold previous value of the switch pin
|
||||||
int prevSwitchState = 0;
|
int prevSwitchState = 0;
|
||||||
|
|
||||||
// a variable to choose which reply from the crystal ball
|
// a variable to choose which reply from the crystal ball
|
||||||
@ -76,7 +76,7 @@ void loop() {
|
|||||||
// move the cursor to the second line
|
// move the cursor to the second line
|
||||||
lcd.setCursor(0, 1);
|
lcd.setCursor(0, 1);
|
||||||
|
|
||||||
// choose a saying to print baed on the value in reply
|
// choose a saying to print based on the value in reply
|
||||||
switch (reply) {
|
switch (reply) {
|
||||||
case 0:
|
case 0:
|
||||||
lcd.print("Yes");
|
lcd.print("Yes");
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
Arduino Starter Kit example
|
Arduino Starter Kit example
|
||||||
Project 12 - Knock Lock
|
Project 12 - Knock Lock
|
||||||
|
|
||||||
This sketch is written to accompany Project 12 in the
|
This sketch is written to accompany Project 12 in the
|
||||||
Arduino Starter Kit
|
Arduino Starter Kit
|
||||||
@ -28,7 +28,7 @@
|
|||||||
|
|
||||||
// import the library
|
// import the library
|
||||||
#include <Servo.h>
|
#include <Servo.h>
|
||||||
// create an instance of the servo library
|
// create an instance of the Servo library
|
||||||
Servo myServo;
|
Servo myServo;
|
||||||
|
|
||||||
const int piezo = A0; // pin the piezo is attached to
|
const int piezo = A0; // pin the piezo is attached to
|
||||||
@ -72,7 +72,7 @@ void setup() {
|
|||||||
// move the servo to the unlocked position
|
// move the servo to the unlocked position
|
||||||
myServo.write(0);
|
myServo.write(0);
|
||||||
|
|
||||||
// print status to the serial monitor
|
// print status to the Serial Monitor
|
||||||
Serial.println("the box is unlocked!");
|
Serial.println("the box is unlocked!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
Arduino Starter Kit example
|
Arduino Starter Kit example
|
||||||
Project 13 - Touch Sensor Lamp
|
Project 13 - Touch Sensor Lamp
|
||||||
|
|
||||||
This sketch is written to accompany Project 13 in the
|
This sketch is written to accompany Project 13 in the
|
||||||
Arduino Starter Kit
|
Arduino Starter Kit
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
Arduino Starter Kit example
|
Arduino Starter Kit example
|
||||||
Project 14 - Tweak the Arduino Logo
|
Project 14 - Tweak the Arduino Logo
|
||||||
|
|
||||||
This sketch is written to accompany Project 14 in the
|
This sketch is written to accompany Project 14 in the
|
||||||
Arduino Starter Kit
|
Arduino Starter Kit
|
||||||
@ -9,8 +9,8 @@
|
|||||||
10 kilohm potentiometer
|
10 kilohm potentiometer
|
||||||
|
|
||||||
Software required :
|
Software required :
|
||||||
Processing (3.0 or newer) http://processing.org
|
Processing (3.0 or newer) http://processing.org
|
||||||
Active internet connection
|
Active Internet connection
|
||||||
|
|
||||||
Created 18 September 2012
|
Created 18 September 2012
|
||||||
by Scott Fitzgerald
|
by Scott Fitzgerald
|
||||||
@ -34,7 +34,7 @@ void loop() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Processing code for this example
|
/* Processing code for this example
|
||||||
// Tweak the Arduno Logo
|
// Tweak the Arduino Logo
|
||||||
// by Scott Fitzgerald
|
// by Scott Fitzgerald
|
||||||
// This example code is in the public domain
|
// This example code is in the public domain
|
||||||
|
|
||||||
@ -63,12 +63,12 @@ void setup() {
|
|||||||
surface.setSize(logo.width, logo.height);
|
surface.setSize(logo.width, logo.height);
|
||||||
|
|
||||||
// print a list of available serial ports to the
|
// print a list of available serial ports to the
|
||||||
// Processing staus window
|
// Processing status window
|
||||||
println("Available serial ports:");
|
println("Available serial ports:");
|
||||||
println(Serial.list());
|
println(Serial.list());
|
||||||
|
|
||||||
// Tell the serial object the information it needs to communicate
|
// Tell the serial object the information it needs to communicate
|
||||||
// with the Arduno. Change Serial.list()[0] to the correct
|
// with the Arduino. Change Serial.list()[0] to the correct
|
||||||
// port corresponding to your Arduino board. The last
|
// port corresponding to your Arduino board. The last
|
||||||
// parameter (e.g. 9600) is the speed of the communication. It
|
// parameter (e.g. 9600) is the speed of the communication. It
|
||||||
// has to correspond to the value passed to Serial.begin() in your
|
// has to correspond to the value passed to Serial.begin() in your
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
/*
|
/*
|
||||||
Arduino Starter Kit example
|
Arduino Starter Kit example
|
||||||
Project 15 - Hacking Buttons
|
Project 15 - Hacking Buttons
|
||||||
|
|
||||||
This sketch is written to accompany Project 15 in the
|
This sketch is written to accompany Project 15 in the
|
||||||
Arduino Starter Kit
|
Arduino Starter Kit
|
||||||
|
|
||||||
Parts required:
|
Parts required:
|
||||||
batery powered component
|
battery powered component
|
||||||
220 ohm resistor
|
220 ohm resistor
|
||||||
4N35 optocoupler
|
4N35 optocoupler
|
||||||
|
|
||||||
|
@ -4,11 +4,11 @@
|
|||||||
// http://www.opensource.org/licenses/bsd-license.php
|
// http://www.opensource.org/licenses/bsd-license.php
|
||||||
//
|
//
|
||||||
// This sketch turns the Arduino into a AVRISP
|
// This sketch turns the Arduino into a AVRISP
|
||||||
// using the following arduino pins:
|
// using the following Arduino pins:
|
||||||
//
|
//
|
||||||
// Pin 10 is used to reset the target microcontroller.
|
// Pin 10 is used to reset the target microcontroller.
|
||||||
//
|
//
|
||||||
// By default, the hardware SPI pins MISO, MOSI and SCK pins are used
|
// By default, the hardware SPI pins MISO, MOSI and SCK are used
|
||||||
// to communicate with the target. On all Arduinos, these pins can be found
|
// to communicate with the target. On all Arduinos, these pins can be found
|
||||||
// on the ICSP/SPI header:
|
// on the ICSP/SPI header:
|
||||||
//
|
//
|
||||||
@ -20,7 +20,7 @@
|
|||||||
// as digital pin 11, 12 and 13, respectively. That is why many tutorials
|
// as digital pin 11, 12 and 13, respectively. That is why many tutorials
|
||||||
// instruct you to hook up the target to these pins. If you find this wiring
|
// instruct you to hook up the target to these pins. If you find this wiring
|
||||||
// more practical, have a define USE_OLD_STYLE_WIRING. This will work even
|
// more practical, have a define USE_OLD_STYLE_WIRING. This will work even
|
||||||
// even when not using an Uno. (On an Uno this is not needed).
|
// when not using an Uno. (On an Uno this is not needed).
|
||||||
//
|
//
|
||||||
// Alternatively you can use any other digital pin by configuring software ('BitBanged')
|
// Alternatively you can use any other digital pin by configuring software ('BitBanged')
|
||||||
// SPI and having appropriate defines for PIN_MOSI, PIN_MISO and PIN_SCK.
|
// SPI and having appropriate defines for PIN_MOSI, PIN_MISO and PIN_SCK.
|
||||||
@ -43,18 +43,18 @@
|
|||||||
#define PROG_FLICKER true
|
#define PROG_FLICKER true
|
||||||
|
|
||||||
// Configure SPI clock (in Hz).
|
// Configure SPI clock (in Hz).
|
||||||
// E.g. for an attiny @128 kHz: the datasheet states that both the high
|
// E.g. for an ATtiny @ 128 kHz: the datasheet states that both the high
|
||||||
// and low spi clock pulse must be > 2 cpu cycles, so take 3 cycles i.e.
|
// and low SPI clock pulse must be > 2 CPU cycles, so take 3 cycles i.e.
|
||||||
// divide target f_cpu by 6:
|
// divide target f_cpu by 6:
|
||||||
// #define SPI_CLOCK (128000/6)
|
// #define SPI_CLOCK (128000/6)
|
||||||
//
|
//
|
||||||
// A clock slow enough for an attiny85 @ 1MHz, is a reasonable default:
|
// A clock slow enough for an ATtiny85 @ 1 MHz, is a reasonable default:
|
||||||
|
|
||||||
#define SPI_CLOCK (1000000/6)
|
#define SPI_CLOCK (1000000/6)
|
||||||
|
|
||||||
|
|
||||||
// Select hardware or software SPI, depending on SPI clock.
|
// Select hardware or software SPI, depending on SPI clock.
|
||||||
// Currently only for AVR, for other archs (Due, Zero,...),
|
// Currently only for AVR, for other architectures (Due, Zero,...),
|
||||||
// hardware SPI is probably too fast anyway.
|
// hardware SPI is probably too fast anyway.
|
||||||
|
|
||||||
#if defined(ARDUINO_ARCH_AVR)
|
#if defined(ARDUINO_ARCH_AVR)
|
||||||
@ -88,7 +88,7 @@
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// HOODLOADER2 means running sketches on the atmega16u2
|
// HOODLOADER2 means running sketches on the ATmega16U2
|
||||||
// serial converter chips on Uno or Mega boards.
|
// serial converter chips on Uno or Mega boards.
|
||||||
// We must use pins that are broken out:
|
// We must use pins that are broken out:
|
||||||
#else
|
#else
|
||||||
@ -371,7 +371,7 @@ void get_version(uint8_t c) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void set_parameters() {
|
void set_parameters() {
|
||||||
// call this after reading paramter packet into buff[]
|
// call this after reading parameter packet into buff[]
|
||||||
param.devicecode = buff[0];
|
param.devicecode = buff[0];
|
||||||
param.revision = buff[1];
|
param.revision = buff[1];
|
||||||
param.progtype = buff[2];
|
param.progtype = buff[2];
|
||||||
@ -393,7 +393,7 @@ void set_parameters() {
|
|||||||
+ buff[18] * 0x00000100
|
+ buff[18] * 0x00000100
|
||||||
+ buff[19];
|
+ buff[19];
|
||||||
|
|
||||||
// avr devices have active low reset, at89sx are active high
|
// AVR devices have active low reset, AT89Sx are active high
|
||||||
rst_active_high = (param.devicecode >= 0xe0);
|
rst_active_high = (param.devicecode >= 0xe0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -404,7 +404,7 @@ void start_pmode() {
|
|||||||
// SPI.begin() will configure SS as output,
|
// SPI.begin() will configure SS as output,
|
||||||
// so SPI master mode is selected.
|
// so SPI master mode is selected.
|
||||||
// We have defined RESET as pin 10,
|
// We have defined RESET as pin 10,
|
||||||
// which for many arduino's is not the SS pin.
|
// which for many Arduinos is not the SS pin.
|
||||||
// So we have to configure RESET as output here,
|
// So we have to configure RESET as output here,
|
||||||
// (reset_target() first sets the correct level)
|
// (reset_target() first sets the correct level)
|
||||||
reset_target(true);
|
reset_target(true);
|
||||||
@ -412,14 +412,14 @@ void start_pmode() {
|
|||||||
SPI.begin();
|
SPI.begin();
|
||||||
SPI.beginTransaction(SPISettings(SPI_CLOCK, MSBFIRST, SPI_MODE0));
|
SPI.beginTransaction(SPISettings(SPI_CLOCK, MSBFIRST, SPI_MODE0));
|
||||||
|
|
||||||
// See avr datasheets, chapter "SERIAL_PRG Programming Algorithm":
|
// See AVR datasheets, chapter "SERIAL_PRG Programming Algorithm":
|
||||||
|
|
||||||
// Pulse RESET after PIN_SCK is low:
|
// Pulse RESET after PIN_SCK is low:
|
||||||
digitalWrite(PIN_SCK, LOW);
|
digitalWrite(PIN_SCK, LOW);
|
||||||
delay(20); // discharge PIN_SCK, value arbitrally chosen
|
delay(20); // discharge PIN_SCK, value arbitrarily chosen
|
||||||
reset_target(false);
|
reset_target(false);
|
||||||
// Pulse must be minimum 2 target CPU clock cycles
|
// Pulse must be minimum 2 target CPU clock cycles
|
||||||
// so 100 usec is ok for CPU speeds above 20KHz
|
// so 100 usec is ok for CPU speeds above 20 KHz
|
||||||
delayMicroseconds(100);
|
delayMicroseconds(100);
|
||||||
reset_target(true);
|
reset_target(true);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user