mirror of
https://github.com/esp8266/Arduino.git
synced 2025-07-30 16:24:09 +03:00
Merge of arduino-1.0.1. Work in progress...
This commit is contained in:
@ -34,6 +34,7 @@ my $wire = create_page('Wire.html', "$ARDUINO/Reference/Wire");
|
||||
my $sd = create_page('SD.html', "$ARDUINO/Reference/SD");
|
||||
my $servo = create_page('Servo.html', "$ARDUINO/Reference/Servo");
|
||||
my $spi = create_page('SPI.html', "$ARDUINO/Reference/SPI");
|
||||
my $mousekeyboard = create_page('MouseKeyboard.html', "$ARDUINO/Reference/MouseKeyboard");
|
||||
my $lcd = create_page('LiquidCrystal.html', "$ARDUINO/Reference/LiquidCrystal");
|
||||
my $ethernet = create_page('Ethernet.html', "$ARDUINO/Reference/Ethernet");
|
||||
my $serial = create_page('Serial.html', "$ARDUINO/Reference/Serial");
|
||||
@ -48,6 +49,8 @@ create_linked_pages($servo, qr!$ARDUINO/Reference/(Servo\w+)!, '%%.html')
|
||||
create_linked_pages($sd, qr!$ARDUINO/Reference/(SD\w+)!, '%%.html');
|
||||
create_linked_pages($sd, qr!$ARDUINO/Reference/(File\w+)!, '%%.html');
|
||||
create_linked_pages($spi, qr!$ARDUINO/Reference/(SPI\w+)!, '%%.html');
|
||||
create_linked_pages($mousekeyboard, qr!$ARDUINO/Reference/(Mouse\w+)!, '%%.html');
|
||||
create_linked_pages($mousekeyboard, qr!$ARDUINO/Reference/(Keyboard\w+)!, '%%.html');
|
||||
create_linked_pages($lcd, qr!$ARDUINO/Reference/(LiquidCrystal\w+)!, '%%.html');
|
||||
create_linked_pages($ethernet, qr!$ARDUINO/Reference/(Ethernet\w+)!, '%%.html');
|
||||
create_linked_pages($ethernet, qr!$ARDUINO/Reference/(Server\w+)!, '%%.html');
|
||||
|
@ -18,4 +18,5 @@ void loop() {
|
||||
int sensorValue = analogRead(A0);
|
||||
// print out the value you read:
|
||||
Serial.println(sensorValue);
|
||||
delay(1); // delay in between reads for stability
|
||||
}
|
@ -22,6 +22,7 @@ void loop() {
|
||||
int buttonState = digitalRead(pushButton);
|
||||
// print out the state of the button:
|
||||
Serial.println(buttonState);
|
||||
delay(1); // delay in between reads for stability
|
||||
}
|
||||
|
||||
|
@ -9,7 +9,7 @@
|
||||
* 8-ohm speaker on digital pin 8
|
||||
|
||||
created 21 Jan 2010
|
||||
modified 30 Aug 2011
|
||||
modified 9 Apr 2012
|
||||
by Tom Igoe
|
||||
|
||||
This example code is in the public domain.
|
||||
@ -41,5 +41,4 @@ void loop() {
|
||||
tone(8, notes[thisSensor], 20);
|
||||
}
|
||||
}
|
||||
Serial.println();
|
||||
}
|
@ -9,7 +9,7 @@
|
||||
* 4.7K resistor on analog 0 to ground
|
||||
|
||||
created 21 Jan 2010
|
||||
modified 30 Aug 2011
|
||||
modified 9 Apr 2012
|
||||
by Tom Igoe
|
||||
|
||||
This example code is in the public domain.
|
||||
@ -36,7 +36,7 @@ void loop() {
|
||||
|
||||
// play the pitch:
|
||||
tone(9, thisPitch, 10);
|
||||
|
||||
delay(1); // delay in between reads for stability
|
||||
}
|
||||
|
||||
|
@ -12,7 +12,7 @@
|
||||
* LED connected from digital pin 9 to ground
|
||||
|
||||
created 29 Dec. 2008
|
||||
modified 30 Aug 2011
|
||||
modified 9 Apr 2012
|
||||
by Tom Igoe
|
||||
|
||||
This example code is in the public domain.
|
||||
@ -46,8 +46,8 @@ void loop() {
|
||||
Serial.print("\t output = ");
|
||||
Serial.println(outputValue);
|
||||
|
||||
// wait 10 milliseconds before the next loop
|
||||
// wait 2 milliseconds before the next loop
|
||||
// for the analog-to-digital converter to settle
|
||||
// after the last reading:
|
||||
delay(10);
|
||||
delay(2);
|
||||
}
|
@ -10,9 +10,9 @@
|
||||
* Analog sensor (potentiometer will do) attached to analog input 0
|
||||
|
||||
Created 22 April 2007
|
||||
modified 30 Aug 2011
|
||||
By David A. Mellis <dam@mellis.org>
|
||||
|
||||
modified 9 Apr 2012
|
||||
by Tom Igoe
|
||||
http://www.arduino.cc/en/Tutorial/Smoothing
|
||||
|
||||
This example code is in the public domain.
|
||||
@ -61,7 +61,8 @@ void loop() {
|
||||
// calculate the average:
|
||||
average = total / numReadings;
|
||||
// send it to the computer as ASCII digits
|
||||
Serial.println(average);
|
||||
Serial.println(average);
|
||||
delay(1); // delay in between reads for stability
|
||||
}
|
||||
|
||||
|
@ -11,7 +11,7 @@
|
||||
|
||||
created 2006
|
||||
by Nicholas Zambetti
|
||||
modified 30 Aug 2011
|
||||
modified 9 Apr 2012
|
||||
by Tom Igoe
|
||||
|
||||
This example code is in the public domain.
|
||||
@ -19,10 +19,13 @@
|
||||
<http://www.zambetti.com>
|
||||
|
||||
*/
|
||||
void setup()
|
||||
{
|
||||
void setup() {
|
||||
//Initialize serial and wait for port to open:
|
||||
Serial.begin(9600);
|
||||
|
||||
while (!Serial) {
|
||||
; // wait for serial port to connect. Needed for Leonardo only
|
||||
}
|
||||
|
||||
// prints title with ending line break
|
||||
Serial.println("ASCII Table ~ Character Map");
|
||||
}
|
||||
@ -33,8 +36,7 @@ int thisByte = 33;
|
||||
// for example. '!' is the same as 33, so you could also use this:
|
||||
//int thisByte = '!';
|
||||
|
||||
void loop()
|
||||
{
|
||||
void loop() {
|
||||
// prints value unaltered, i.e. the raw binary version of the
|
||||
// byte. The serial monitor interprets all bytes as
|
||||
// ASCII, so 33, the first number, will show up as '!'
|
@ -18,7 +18,7 @@
|
||||
|
||||
created 2006
|
||||
by David A. Mellis
|
||||
modified 30 Aug 2011
|
||||
modified 9 Apr 2012
|
||||
by Tom Igoe and Scott Fitzgerald
|
||||
|
||||
This example code is in the public domain.
|
||||
@ -36,7 +36,7 @@ void loop() {
|
||||
Serial.println(analogRead(A0));
|
||||
// wait a bit for the analog-to-digital converter
|
||||
// to stabilize after the last reading:
|
||||
delay(10);
|
||||
delay(2);
|
||||
}
|
||||
|
||||
/* Processing code for this example
|
@ -11,7 +11,8 @@
|
||||
* Serial monitor open on Serial port 0:
|
||||
|
||||
created 30 Dec. 2008
|
||||
by Tom Igoe
|
||||
modified 20 May 2012
|
||||
by Tom Igoe & Jed Roach
|
||||
|
||||
This example code is in the public domain.
|
||||
|
||||
@ -30,4 +31,10 @@ void loop() {
|
||||
int inByte = Serial1.read();
|
||||
Serial.write(inByte);
|
||||
}
|
||||
|
||||
// read from port 0, send to port 1:
|
||||
if (Serial.available()) {
|
||||
int inByte = Serial.read();
|
||||
Serial1.write(inByte);
|
||||
}
|
||||
}
|
@ -0,0 +1,74 @@
|
||||
/*
|
||||
Reading a serial ASCII-encoded string.
|
||||
|
||||
This sketch demonstrates the Serial parseInt() function.
|
||||
It looks for an ASCII string of comma-separated values.
|
||||
It parses them into ints, and uses those to fade an RGB LED.
|
||||
|
||||
Circuit: Common-anode RGB LED wired like so:
|
||||
* Red cathode: digital pin 3
|
||||
* Green cathode: digital pin 5
|
||||
* blue cathode: digital pin 6
|
||||
* anode: +5V
|
||||
|
||||
created 13 Apr 2012
|
||||
by Tom Igoe
|
||||
|
||||
This example code is in the public domain.
|
||||
*/
|
||||
|
||||
// pins for the LEDs:
|
||||
const int redPin = 3;
|
||||
const int greenPin = 5;
|
||||
const int bluePin = 6;
|
||||
|
||||
void setup() {
|
||||
// initialize serial:
|
||||
Serial.begin(9600);
|
||||
// make the pins outputs:
|
||||
pinMode(redPin, OUTPUT);
|
||||
pinMode(greenPin, OUTPUT);
|
||||
pinMode(bluePin, OUTPUT);
|
||||
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// if there's any serial available, read it:
|
||||
while (Serial.available() > 0) {
|
||||
|
||||
// look for the next valid integer in the incoming serial stream:
|
||||
int red = Serial.parseInt();
|
||||
// do it again:
|
||||
int green = Serial.parseInt();
|
||||
// do it again:
|
||||
int blue = Serial.parseInt();
|
||||
|
||||
// look for the newline. That's the end of your
|
||||
// sentence:
|
||||
if (Serial.read() == '\n') {
|
||||
// constrain the values to 0 - 255 and invert
|
||||
// if you're using a common-cathode LED, just use "constrain(color, 0, 255);"
|
||||
red = 255 - constrain(red, 0, 255);
|
||||
green = 255 - constrain(green, 0, 255);
|
||||
blue = 255 - constrain(blue, 0, 255);
|
||||
|
||||
// fade the red, green, and blue legs of the LED:
|
||||
analogWrite(redPin, red);
|
||||
analogWrite(greenPin, green);
|
||||
analogWrite(bluePin, blue);
|
||||
|
||||
// print the three numbers in one string as hexadecimal:
|
||||
Serial.print(red, HEX);
|
||||
Serial.print(green, HEX);
|
||||
Serial.println(blue, HEX);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -33,6 +33,10 @@ void setup()
|
||||
{
|
||||
// start serial port at 9600 bps:
|
||||
Serial.begin(9600);
|
||||
while (!Serial) {
|
||||
; // wait for serial port to connect. Needed for Leonardo only
|
||||
}
|
||||
|
||||
pinMode(2, INPUT); // digital sensor is on digital pin 2
|
||||
establishContact(); // send a byte to establish contact until receiver responds
|
||||
}
|
@ -35,8 +35,13 @@ int inByte = 0; // incoming serial byte
|
||||
|
||||
void setup()
|
||||
{
|
||||
// start serial port at 9600 bps:
|
||||
// start serial port at 9600 bps and wait for port to open:
|
||||
Serial.begin(9600);
|
||||
while (!Serial) {
|
||||
; // wait for serial port to connect. Needed for Leonardo only
|
||||
}
|
||||
|
||||
|
||||
pinMode(2, INPUT); // digital sensor is on digital pin 2
|
||||
establishContact(); // send a byte to establish contact until receiver responds
|
||||
}
|
@ -16,7 +16,7 @@
|
||||
connected to pin 13, so you don't need any extra components for this example.
|
||||
|
||||
created 17 Jan 2009
|
||||
modified 30 Aug 2011
|
||||
modified 9 Apr 2012
|
||||
by Tom Igoe
|
||||
|
||||
This example code is in the public domain.
|
||||
@ -51,6 +51,6 @@ void loop() {
|
||||
|
||||
// print the analog value:
|
||||
Serial.println(analogValue);
|
||||
|
||||
delay(1); // delay in between reads for stability
|
||||
}
|
||||
|
@ -14,7 +14,7 @@
|
||||
* 10K resistor from analog in 0 to ground
|
||||
|
||||
created 1 Jul 2009
|
||||
modified 30 Aug 2011
|
||||
modified 9 Apr 2012
|
||||
by Tom Igoe
|
||||
|
||||
This example code is in the public domain.
|
||||
@ -22,7 +22,8 @@
|
||||
http://www.arduino.cc/en/Tutorial/SwitchCase
|
||||
*/
|
||||
|
||||
// these constants won't change:
|
||||
// these constants won't change. They are the
|
||||
// lowest and highest readings you get from your sensor:
|
||||
const int sensorMin = 0; // sensor minimum, discovered through experiment
|
||||
const int sensorMax = 600; // sensor maximum, discovered through experiment
|
||||
|
||||
@ -53,7 +54,7 @@ void loop() {
|
||||
Serial.println("bright");
|
||||
break;
|
||||
}
|
||||
|
||||
delay(1); // delay in between reads for stability
|
||||
}
|
||||
|
||||
|
@ -50,9 +50,7 @@ int x = 5;
|
||||
int y = 5;
|
||||
|
||||
void setup() {
|
||||
Serial.begin(9600);
|
||||
// initialize the I/O pins as outputs:
|
||||
|
||||
// initialize the I/O pins as outputs
|
||||
// iterate over the pins:
|
||||
for (int thisPin = 0; thisPin < 8; thisPin++) {
|
||||
// initialize the output pins:
|
Binary file not shown.
@ -5,14 +5,18 @@
|
||||
Send any byte and the sketch will tell you about it.
|
||||
|
||||
created 29 Nov 2010
|
||||
modified 2 Apr 2012
|
||||
by Tom Igoe
|
||||
|
||||
This example code is in the public domain.
|
||||
*/
|
||||
|
||||
void setup() {
|
||||
// Open serial communications:
|
||||
// Open serial communications and wait for port to open:
|
||||
Serial.begin(9600);
|
||||
while (!Serial) {
|
||||
; // wait for serial port to connect. Needed for Leonardo only
|
||||
}
|
||||
|
||||
// send an intro:
|
||||
Serial.println("send any byte and I'll tell you everything I can about it");
|
||||
@ -77,9 +81,3 @@ void loop() {
|
||||
Serial.println();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -5,7 +5,7 @@
|
||||
You can also add several different data types to string, as shown here:
|
||||
|
||||
created 27 July 2010
|
||||
modified 30 Aug 2011
|
||||
modified 2 Apr 2012
|
||||
by Tom Igoe
|
||||
|
||||
http://arduino.cc/en/Tutorial/StringAdditionOperator
|
||||
@ -17,11 +17,18 @@
|
||||
String stringOne, stringTwo, stringThree;
|
||||
|
||||
void setup() {
|
||||
// initialize serial and wait for port to open:
|
||||
Serial.begin(9600);
|
||||
while (!Serial) {
|
||||
; // wait for serial port to connect. Needed for Leonardo only
|
||||
}
|
||||
|
||||
stringOne = String("stringThree = ");
|
||||
stringTwo = String("this string");
|
||||
stringThree = String ();
|
||||
// send an intro:
|
||||
Serial.println("\n\nAdding strings together (concatenation):");
|
||||
Serial.println();
|
||||
}
|
||||
|
||||
void loop() {
|
||||
@ -58,4 +65,4 @@ void loop() {
|
||||
|
||||
// do nothing while true:
|
||||
while(true);
|
||||
}
|
||||
}
|
@ -4,7 +4,7 @@
|
||||
Examples of how to append different data types to strings
|
||||
|
||||
created 27 July 2010
|
||||
modified 30 Aug 2011
|
||||
modified 2 Apr 2012
|
||||
by Tom Igoe
|
||||
|
||||
http://arduino.cc/en/Tutorial/StringAppendOperator
|
||||
@ -14,10 +14,17 @@
|
||||
String stringOne, stringTwo;
|
||||
|
||||
void setup() {
|
||||
// Open serial communications and wait for port to open:
|
||||
Serial.begin(9600);
|
||||
while (!Serial) {
|
||||
; // wait for serial port to connect. Needed for Leonardo only
|
||||
}
|
||||
|
||||
stringOne = String("Sensor ");
|
||||
stringTwo = String("value");
|
||||
// send an intro:
|
||||
Serial.println("\n\nAppending to a string:");
|
||||
Serial.println();
|
||||
}
|
||||
|
||||
void loop() {
|
||||
@ -61,4 +68,5 @@ void loop() {
|
||||
|
||||
// do nothing while true:
|
||||
while(true);
|
||||
}
|
||||
}
|
||||
|
@ -4,6 +4,7 @@
|
||||
Examples of how to change the case of a string
|
||||
|
||||
created 27 July 2010
|
||||
modified 2 Apr 2012
|
||||
by Tom Igoe
|
||||
|
||||
http://arduino.cc/en/Tutorial/StringCaseChanges
|
||||
@ -12,24 +13,31 @@
|
||||
*/
|
||||
|
||||
void setup() {
|
||||
// Open serial communications and wait for port to open:
|
||||
Serial.begin(9600);
|
||||
while (!Serial) {
|
||||
; // wait for serial port to connect. Needed for Leonardo only
|
||||
}
|
||||
|
||||
// send an intro:
|
||||
Serial.println("\n\nString case changes:");
|
||||
Serial.println();
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// toUpperCase() changes all letters to upper case:
|
||||
String stringOne = "<html><head><body>";
|
||||
Serial.println(stringOne);
|
||||
stringOne = (stringOne.toUpperCase());
|
||||
stringOne.toUpperCase();
|
||||
Serial.println(stringOne);
|
||||
|
||||
// toLowerCase() changes all letters to lower case:
|
||||
|
||||
// toLowerCase() changes all letters to lower case:
|
||||
String stringTwo = "</BODY></HTML>";
|
||||
Serial.println(stringTwo);
|
||||
stringTwo = stringTwo.toLowerCase();
|
||||
stringTwo.toLowerCase();
|
||||
Serial.println(stringTwo);
|
||||
|
||||
|
||||
|
||||
|
||||
// do nothing while true:
|
||||
while(true);
|
||||
}
|
@ -4,6 +4,7 @@
|
||||
Examples of how to get and set characters of a String
|
||||
|
||||
created 27 July 2010
|
||||
modified 2 Apr 2012
|
||||
by Tom Igoe
|
||||
|
||||
http://arduino.cc/en/Tutorial/StringCharacters
|
||||
@ -12,7 +13,12 @@
|
||||
*/
|
||||
|
||||
void setup() {
|
||||
// Open serial communications and wait for port to open:
|
||||
Serial.begin(9600);
|
||||
while (!Serial) {
|
||||
; // wait for serial port to connect. Needed for Leonardo only
|
||||
}
|
||||
|
||||
Serial.println("\n\nString charAt() and setCharAt():");
|
||||
}
|
||||
|
||||
@ -20,18 +26,19 @@ void loop() {
|
||||
// make a string to report a sensor reading:
|
||||
String reportString = "SensorReading: 456";
|
||||
Serial.println(reportString);
|
||||
|
||||
|
||||
// the reading's most significant digit is at position 15 in the reportString:
|
||||
String mostSignificantDigit = reportString.charAt(15);
|
||||
char mostSignificantDigit = reportString.charAt(15);
|
||||
Serial.println("Most significant digit of the sensor reading is: " + mostSignificantDigit);
|
||||
|
||||
// add blank space:
|
||||
// add blank space:
|
||||
Serial.println();
|
||||
|
||||
|
||||
// you can alo set the character of a string. Change the : to a = character
|
||||
reportString.setCharAt(13, '=');
|
||||
Serial.println(reportString);
|
||||
|
||||
// do nothing while true:
|
||||
while(true);
|
||||
}
|
||||
}
|
||||
|
@ -4,21 +4,29 @@
|
||||
Examples of how to compare strings using the comparison operators
|
||||
|
||||
created 27 July 2010
|
||||
modified 30 Aug 2011
|
||||
modified 2 Apr 2012
|
||||
by Tom Igoe
|
||||
|
||||
http://arduino.cc/en/Tutorial/StringComparisonOperators
|
||||
|
||||
This example code is in the public domain.
|
||||
*/
|
||||
|
||||
|
||||
String stringOne, stringTwo;
|
||||
|
||||
void setup() {
|
||||
// Open serial communications and wait for port to open:
|
||||
Serial.begin(9600);
|
||||
while (!Serial) {
|
||||
; // wait for serial port to connect. Needed for Leonardo only
|
||||
}
|
||||
|
||||
|
||||
stringOne = String("this");
|
||||
stringTwo = String("that");
|
||||
// send an intro:
|
||||
Serial.println("\n\nComparing Strings:");
|
||||
Serial.println();
|
||||
|
||||
}
|
||||
|
||||
@ -57,7 +65,7 @@ void loop() {
|
||||
// a numeric string compared to the number it represents:
|
||||
stringOne = "1";
|
||||
int numberOne = 1;
|
||||
if (stringOne == numberOne) {
|
||||
if (stringOne.toInt() == numberOne) {
|
||||
Serial.println(stringOne + " = " + numberOne);
|
||||
}
|
||||
|
||||
@ -121,4 +129,4 @@ void loop() {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,72 @@
|
||||
/*
|
||||
String constructors
|
||||
|
||||
Examples of how to create strings from other data types
|
||||
|
||||
created 27 July 2010
|
||||
modified 30 Aug 2011
|
||||
by Tom Igoe
|
||||
|
||||
http://arduino.cc/en/Tutorial/StringConstructors
|
||||
|
||||
This example code is in the public domain.
|
||||
*/
|
||||
|
||||
void setup() {
|
||||
// Open serial communications and wait for port to open:
|
||||
Serial.begin(9600);
|
||||
while (!Serial) {
|
||||
; // wait for serial port to connect. Needed for Leonardo only
|
||||
}
|
||||
|
||||
// send an intro:
|
||||
Serial.println("\n\nString Constructors:");
|
||||
Serial.println();
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// using a constant String:
|
||||
String stringOne = "Hello String";
|
||||
Serial.println(stringOne); // prints "Hello String"
|
||||
|
||||
// converting a constant char into a String:
|
||||
stringOne = String('a');
|
||||
Serial.println(stringOne); // prints "a"
|
||||
|
||||
// converting a constant string into a String object:
|
||||
String stringTwo = String("This is a string");
|
||||
Serial.println(stringTwo); // prints "This is a string"
|
||||
|
||||
// concatenating two strings:
|
||||
stringOne = String(stringTwo + " with more");
|
||||
// prints "This is a string with more":
|
||||
Serial.println(stringOne);
|
||||
|
||||
// using a constant integer:
|
||||
stringOne = String(13);
|
||||
Serial.println(stringOne); // prints "13"
|
||||
|
||||
// using an int and a base:
|
||||
stringOne = String(analogRead(A0), DEC);
|
||||
// prints "453" or whatever the value of analogRead(A0) is
|
||||
Serial.println(stringOne);
|
||||
|
||||
// using an int and a base (hexadecimal):
|
||||
stringOne = String(45, HEX);
|
||||
// prints "2d", which is the hexadecimal version of decimal 45:
|
||||
Serial.println(stringOne);
|
||||
|
||||
// using an int and a base (binary)
|
||||
stringOne = String(255, BIN);
|
||||
// prints "11111111" which is the binary value of 255
|
||||
Serial.println(stringOne);
|
||||
|
||||
// using a long and a base:
|
||||
stringOne = String(millis(), DEC);
|
||||
// prints "123456" or whatever the value of millis() is:
|
||||
Serial.println(stringOne);
|
||||
|
||||
// do nothing while true:
|
||||
while(true);
|
||||
|
||||
}
|
@ -4,6 +4,7 @@
|
||||
Examples of how to evaluate, look for, and replace characters in a String
|
||||
|
||||
created 27 July 2010
|
||||
modified 2 Apr 2012
|
||||
by Tom Igoe
|
||||
|
||||
http://arduino.cc/en/Tutorial/StringIndexOf
|
||||
@ -12,13 +13,19 @@
|
||||
*/
|
||||
|
||||
void setup() {
|
||||
// Open serial communications and wait for port to open:
|
||||
Serial.begin(9600);
|
||||
Serial.println("\n\nString indexOf() and lastIndexOf() functions:");
|
||||
while (!Serial) {
|
||||
; // wait for serial port to connect. Needed for Leonardo only
|
||||
}
|
||||
|
||||
// send an intro:
|
||||
Serial.println("\n\nString indexOf() and lastIndexOf() functions:");
|
||||
Serial.println();
|
||||
}
|
||||
|
||||
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:
|
||||
String stringOne = "<HTML><HEAD><BODY>";
|
||||
int firstClosingBracket = stringOne.indexOf('>');
|
||||
@ -47,12 +54,13 @@ void loop() {
|
||||
Serial.println("The index of the last list item in the string " + stringOne + " is " + lastListItem);
|
||||
|
||||
|
||||
// lastIndexOf() can also search for a string:
|
||||
stringOne = "<p>Lorem ipsum dolor sit amet</p><p>Ipsem</p><p>Quod</p>";
|
||||
// lastIndexOf() can also search for a string:
|
||||
stringOne = "<p>Lorem ipsum dolor sit amet</p><p>Ipsem</p><p>Quod</p>";
|
||||
int lastParagraph = stringOne.lastIndexOf("<p");
|
||||
int secondLastGraf = stringOne.lastIndexOf("<p", lastParagraph - 1);
|
||||
Serial.println("The index of the second last paragraph tag " + stringOne + " is " + secondLastGraf);
|
||||
|
||||
// do nothing while true:
|
||||
while(true);
|
||||
}
|
||||
// do nothing while true:
|
||||
while(true);
|
||||
}
|
||||
|
@ -15,8 +15,15 @@ String txtMsg = ""; // a string for incoming text
|
||||
int lastStringLength = txtMsg.length(); // previous length of the String
|
||||
|
||||
void setup() {
|
||||
// open the serial port:
|
||||
// Open serial communications and wait for port to open:
|
||||
Serial.begin(9600);
|
||||
while (!Serial) {
|
||||
; // wait for serial port to connect. Needed for Leonardo only
|
||||
}
|
||||
|
||||
// send an intro:
|
||||
Serial.println("\n\nString length():");
|
||||
Serial.ptintln();
|
||||
}
|
||||
|
||||
void loop() {
|
||||
@ -40,4 +47,4 @@ void loop() {
|
||||
// note the length for next time through the loop:
|
||||
lastStringLength = txtMsg.length();
|
||||
}
|
||||
}
|
||||
}
|
@ -4,6 +4,7 @@
|
||||
Examples of how to use length() and trim() in a String
|
||||
|
||||
created 27 July 2010
|
||||
modified 2 Apr 2012
|
||||
by Tom Igoe
|
||||
|
||||
http://arduino.cc/en/Tutorial/StringLengthTrim
|
||||
@ -12,8 +13,15 @@
|
||||
*/
|
||||
|
||||
void setup() {
|
||||
// Open serial communications and wait for port to open:
|
||||
Serial.begin(9600);
|
||||
while (!Serial) {
|
||||
; // wait for serial port to connect. Needed for Leonardo only
|
||||
}
|
||||
|
||||
// send an intro:
|
||||
Serial.println("\n\nString length() and trim():");
|
||||
Serial.println();
|
||||
}
|
||||
|
||||
void loop() {
|
||||
@ -24,7 +32,7 @@ void loop() {
|
||||
Serial.println(stringOne.length());
|
||||
|
||||
// trim the white space off the string:
|
||||
stringOne = stringOne.trim();
|
||||
stringOne.trim();
|
||||
Serial.print(stringOne);
|
||||
Serial.print("<--- end of trimmed string. Length: ");
|
||||
Serial.println(stringOne.length());
|
BIN
build/shared/examples/08.Strings/StringReplace/.swp
Normal file
BIN
build/shared/examples/08.Strings/StringReplace/.swp
Normal file
Binary file not shown.
@ -0,0 +1,50 @@
|
||||
/*
|
||||
String replace()
|
||||
|
||||
Examples of how to replace characters or substrings of a string
|
||||
|
||||
created 27 July 2010
|
||||
modified 2 Apr 2012
|
||||
by Tom Igoe
|
||||
|
||||
http://arduino.cc/en/Tutorial/StringReplace
|
||||
|
||||
This example code is in the public domain.
|
||||
*/
|
||||
|
||||
void setup() {
|
||||
// Open serial communications and wait for port to open:
|
||||
Serial.begin(9600);
|
||||
while (!Serial) {
|
||||
; // wait for serial port to connect. Needed for Leonardo only
|
||||
}
|
||||
|
||||
// send an intro:
|
||||
Serial.println("\n\nString replace:\n");
|
||||
Serial.println();
|
||||
}
|
||||
|
||||
void loop() {
|
||||
String stringOne = "<html><head><body>";
|
||||
Serial.println(stringOne);
|
||||
// replace() changes all instances of one substring with another:
|
||||
// first, make a copy of th original string:
|
||||
String stringTwo = stringOne;
|
||||
// then perform the replacements:
|
||||
stringTwo.replace("<", "</");
|
||||
// print the original:
|
||||
Serial.println("Original string: " + stringOne);
|
||||
// and print the modified string:
|
||||
Serial.println("Modified string: " + stringTwo);
|
||||
|
||||
// you can also use replace() on single characters:
|
||||
String normalString = "bookkeeper";
|
||||
Serial.println("normal: " + normalString);
|
||||
String leetString = normalString;
|
||||
leetString.replace('o', '0');
|
||||
leetString.replace('e', '3');
|
||||
Serial.println("l33tspeak: " + leetString);
|
||||
|
||||
// do nothing while true:
|
||||
while(true);
|
||||
}
|
@ -4,7 +4,7 @@
|
||||
Examples of how to use startsWith() and endsWith() in a String
|
||||
|
||||
created 27 July 2010
|
||||
modified 30 Aug 2011
|
||||
modified 2 Apr 2012
|
||||
by Tom Igoe
|
||||
|
||||
http://arduino.cc/en/Tutorial/StringStartsWithEndsWith
|
||||
@ -13,25 +13,31 @@
|
||||
*/
|
||||
|
||||
void setup() {
|
||||
// Open serial communications and wait for port to open:
|
||||
Serial.begin(9600);
|
||||
Serial.println("\n\nString startsWith() and endsWith():");
|
||||
while (!Serial) {
|
||||
; // wait for serial port to connect. Needed for Leonardo only
|
||||
}
|
||||
|
||||
// send an intro:
|
||||
Serial.println("\n\nString startsWith() and endsWith():");
|
||||
Serial.println();
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// startsWith() checks to see if a String starts with a particular substring:
|
||||
String stringOne = "HTTP/1.1 200 OK";
|
||||
Serial.println(stringOne);
|
||||
// startsWith() checks to see if a String starts with a particular substring:
|
||||
String stringOne = "HTTP/1.1 200 OK";
|
||||
Serial.println(stringOne);
|
||||
if (stringOne.startsWith("HTTP/1.1")) {
|
||||
Serial.println("Server's using http version 1.1");
|
||||
}
|
||||
|
||||
|
||||
// you can also look for startsWith() at an offset position in the string:
|
||||
stringOne = "HTTP/1.1 200 OK";
|
||||
stringOne = "HTTP/1.1 200 OK";
|
||||
if (stringOne.startsWith("200 OK", 9)) {
|
||||
Serial.println("Got an OK from the server");
|
||||
}
|
||||
|
||||
|
||||
// endsWith() checks to see if a String ends with a particular character:
|
||||
String sensorReading = "sensor = ";
|
||||
sensorReading += analogRead(A0);
|
||||
@ -44,6 +50,6 @@ void loop() {
|
||||
|
||||
}
|
||||
|
||||
// do nothing while true:
|
||||
while(true);
|
||||
}
|
||||
// do nothing while true:
|
||||
while(true);
|
||||
}
|
@ -3,8 +3,9 @@
|
||||
|
||||
Examples of how to use substring in a String
|
||||
|
||||
created 27 July 2010
|
||||
by Tom Igoe
|
||||
created 27 July 2010,
|
||||
modified 2 Apr 2012
|
||||
by Zach Eveland
|
||||
|
||||
http://arduino.cc/en/Tutorial/StringSubstring
|
||||
|
||||
@ -12,15 +13,22 @@
|
||||
*/
|
||||
|
||||
void setup() {
|
||||
// Open serial communications and wait for port to open:
|
||||
Serial.begin(9600);
|
||||
while (!Serial) {
|
||||
; // wait for serial port to connect. Needed for Leonardo only
|
||||
}
|
||||
|
||||
// send an intro:
|
||||
Serial.println("\n\nString substring():");
|
||||
Serial.println();
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// Set up a String:
|
||||
String stringOne = "Content-Type: text/html";
|
||||
Serial.println(stringOne);
|
||||
|
||||
|
||||
// substring(index) looks for the substring from the index position to the end:
|
||||
if (stringOne.substring(19) == "html") {
|
||||
Serial.println("It's an html file");
|
||||
@ -32,4 +40,4 @@ void loop() {
|
||||
|
||||
// do nothing while true:
|
||||
while(true);
|
||||
}
|
||||
}
|
@ -16,8 +16,15 @@
|
||||
String inString = ""; // string to hold input
|
||||
|
||||
void setup() {
|
||||
// Initialize serial communications:
|
||||
// Open serial communications and wait for port to open:
|
||||
Serial.begin(9600);
|
||||
while (!Serial) {
|
||||
; // wait for serial port to connect. Needed for Leonardo only
|
||||
}
|
||||
|
||||
// send an intro:
|
||||
Serial.println("\n\nString toInt():");
|
||||
Serial.println();
|
||||
}
|
||||
|
||||
void loop() {
|
||||
@ -42,6 +49,3 @@ void loop() {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -0,0 +1,235 @@
|
||||
/*
|
||||
Serial RGB controller
|
||||
|
||||
Reads a serial input string looking for three comma-separated
|
||||
integers with a newline at the end. Values should be between
|
||||
0 and 255. The sketch uses those values to set the color
|
||||
of an RGB LED attached to pins 9 - 11.
|
||||
|
||||
The circuit:
|
||||
* Common-anode RGB LED cathodes attached to pins 9 - 11
|
||||
* LED anode connected to pin 13
|
||||
|
||||
To turn on any given channel, set the pin LOW.
|
||||
To turn off, set the pin HIGH. The higher the analogWrite level,
|
||||
the lower the brightness.
|
||||
|
||||
created 29 Nov 2010
|
||||
by Tom Igoe
|
||||
|
||||
This example code is in the public domain.
|
||||
*/
|
||||
|
||||
String inString = ""; // string to hold input
|
||||
int currentColor = 0;
|
||||
int red, green, blue = 0;
|
||||
|
||||
void setup() {
|
||||
// Open serial communications and wait for port to open:
|
||||
Serial.begin(9600);
|
||||
while (!Serial) {
|
||||
; // wait for serial port to connect. Needed for Leonardo only
|
||||
}
|
||||
|
||||
// send an intro:
|
||||
Serial.println("\n\nString toInt() RGB:");
|
||||
Serial.println();
|
||||
// set LED cathode pins as outputs:
|
||||
pinMode(9, OUTPUT);
|
||||
pinMode(10, OUTPUT);
|
||||
pinMode(11, OUTPUT);
|
||||
// turn on pin 13 to power the LEDs:
|
||||
pinMode(13, OUTPUT);
|
||||
digitalWrite(13, HIGH);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
int inChar;
|
||||
|
||||
// Read serial input:
|
||||
if (Serial.available() > 0) {
|
||||
inChar = Serial.read();
|
||||
}
|
||||
|
||||
if (isDigit(inChar)) {
|
||||
// convert the incoming byte to a char
|
||||
// and add it to the string:
|
||||
inString += (char)inChar;
|
||||
}
|
||||
|
||||
// if you get a comma, convert to a number,
|
||||
// set the appropriate color, and increment
|
||||
// the color counter:
|
||||
if (inChar == ',') {
|
||||
// do something different for each value of currentColor:
|
||||
switch (currentColor) {
|
||||
case 0: // 0 = red
|
||||
red = inString.toInt();
|
||||
// clear the string for new input:
|
||||
inString = "";
|
||||
break;
|
||||
case 1: // 1 = green:
|
||||
green = inString.toInt();
|
||||
// clear the string for new input:
|
||||
inString = "";
|
||||
break;
|
||||
}
|
||||
currentColor++;
|
||||
}
|
||||
// if you get a newline, you know you've got
|
||||
// the last color, i.e. blue:
|
||||
if (inChar == '\n') {
|
||||
blue = inString.toInt();
|
||||
|
||||
// set the levels of the LED.
|
||||
// subtract value from 255 because a higher
|
||||
// analogWrite level means a dimmer LED, since
|
||||
// you're raising the level on the anode:
|
||||
analogWrite(11, 255 - red);
|
||||
analogWrite(9, 255 - green);
|
||||
analogWrite(10, 255 - blue);
|
||||
|
||||
// print the colors:
|
||||
Serial.print("Red: ");
|
||||
Serial.print(red);
|
||||
Serial.print(", Green: ");
|
||||
Serial.print(green);
|
||||
Serial.print(", Blue: ");
|
||||
Serial.println(blue);
|
||||
|
||||
// clear the string for new input:
|
||||
inString = "";
|
||||
// reset the color counter:
|
||||
currentColor = 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
Here's a Processing sketch that will draw a color wheel and send a serial
|
||||
string with the color you click on:
|
||||
|
||||
// Subtractive Color Wheel with Serial
|
||||
// Based on a Processing example by Ira Greenberg.
|
||||
// Serial output added by Tom Igoe
|
||||
//
|
||||
// The primaries are red, yellow, and blue. The secondaries are green,
|
||||
// purple, and orange. The tertiaries are yellow-orange, red-orange,
|
||||
// red-purple, blue-purple, blue-green, and yellow-green.
|
||||
//
|
||||
// Create a shade or tint of the subtractive color wheel using
|
||||
// SHADE or TINT parameters.
|
||||
|
||||
// Updated 29 November 2010.
|
||||
|
||||
|
||||
|
||||
import processing.serial.*;
|
||||
|
||||
int segs = 12;
|
||||
int steps = 6;
|
||||
float rotAdjust = TWO_PI / segs / 2;
|
||||
float radius;
|
||||
float segWidth;
|
||||
float interval = TWO_PI / segs;
|
||||
|
||||
Serial myPort;
|
||||
|
||||
void setup() {
|
||||
size(200, 200);
|
||||
background(127);
|
||||
smooth();
|
||||
ellipseMode(RADIUS);
|
||||
noStroke();
|
||||
// make the diameter 90% of the sketch area
|
||||
radius = min(width, height) * 0.45;
|
||||
segWidth = radius / steps;
|
||||
|
||||
// swap which line is commented out to draw the other version
|
||||
// drawTintWheel();
|
||||
drawShadeWheel();
|
||||
// open the first serial port in your computer's list
|
||||
myPort = new Serial(this, Serial.list()[0], 9600);
|
||||
}
|
||||
|
||||
|
||||
void drawShadeWheel() {
|
||||
for (int j = 0; j < steps; j++) {
|
||||
color[] cols = {
|
||||
color(255-(255/steps)*j, 255-(255/steps)*j, 0),
|
||||
color(255-(255/steps)*j, (255/1.5)-((255/1.5)/steps)*j, 0),
|
||||
color(255-(255/steps)*j, (255/2)-((255/2)/steps)*j, 0),
|
||||
color(255-(255/steps)*j, (255/2.5)-((255/2.5)/steps)*j, 0),
|
||||
color(255-(255/steps)*j, 0, 0),
|
||||
color(255-(255/steps)*j, 0, (255/2)-((255/2)/steps)*j),
|
||||
color(255-(255/steps)*j, 0, 255-(255/steps)*j),
|
||||
color((255/2)-((255/2)/steps)*j, 0, 255-(255/steps)*j),
|
||||
color(0, 0, 255-(255/steps)*j),
|
||||
color(0, 255-(255/steps)*j, (255/2.5)-((255/2.5)/steps)*j),
|
||||
color(0, 255-(255/steps)*j, 0),
|
||||
color((255/2)-((255/2)/steps)*j, 255-(255/steps)*j, 0)
|
||||
};
|
||||
for (int i = 0; i < segs; i++) {
|
||||
fill(cols[i]);
|
||||
arc(width/2, height/2, radius, radius,
|
||||
interval*i+rotAdjust, interval*(i+1)+rotAdjust);
|
||||
}
|
||||
radius -= segWidth;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void drawTintWheel() {
|
||||
for (int j = 0; j < steps; j++) {
|
||||
color[] cols = {
|
||||
color((255/steps)*j, (255/steps)*j, 0),
|
||||
color((255/steps)*j, ((255/1.5)/steps)*j, 0),
|
||||
color((255/steps)*j, ((255/2)/steps)*j, 0),
|
||||
color((255/steps)*j, ((255/2.5)/steps)*j, 0),
|
||||
color((255/steps)*j, 0, 0),
|
||||
color((255/steps)*j, 0, ((255/2)/steps)*j),
|
||||
color((255/steps)*j, 0, (255/steps)*j),
|
||||
color(((255/2)/steps)*j, 0, (255/steps)*j),
|
||||
color(0, 0, (255/steps)*j),
|
||||
color(0, (255/steps)*j, ((255/2.5)/steps)*j),
|
||||
color(0, (255/steps)*j, 0),
|
||||
color(((255/2)/steps)*j, (255/steps)*j, 0)
|
||||
};
|
||||
for (int i = 0; i < segs; i++) {
|
||||
fill(cols[i]);
|
||||
arc(width/2, height/2, radius, radius,
|
||||
interval*i+rotAdjust, interval*(i+1)+rotAdjust);
|
||||
}
|
||||
radius -= segWidth;
|
||||
}
|
||||
}
|
||||
|
||||
void draw() {
|
||||
// nothing happens here
|
||||
}
|
||||
|
||||
void mouseReleased() {
|
||||
// get the color of the mouse position's pixel:
|
||||
color targetColor = get(mouseX, mouseY);
|
||||
// get the component values:
|
||||
int r = int(red(targetColor));
|
||||
int g = int(green(targetColor));
|
||||
int b = int(blue(targetColor));
|
||||
// make a comma-separated string:
|
||||
String colorString = r + "," + g + "," + b + "\n";
|
||||
// send it out the serial port:
|
||||
myPort.write(colorString );
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -1,64 +0,0 @@
|
||||
/*
|
||||
String constructors
|
||||
|
||||
Examples of how to create strings from other data types
|
||||
|
||||
created 27 July 2010
|
||||
modified 30 Aug 2011
|
||||
by Tom Igoe
|
||||
|
||||
http://arduino.cc/en/Tutorial/StringConstructors
|
||||
|
||||
This example code is in the public domain.
|
||||
*/
|
||||
|
||||
void setup() {
|
||||
Serial.begin(9600);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// using a constant String:
|
||||
String stringOne = "Hello String";
|
||||
Serial.println(stringOne); // prints "Hello String"
|
||||
|
||||
// converting a constant char into a String:
|
||||
stringOne = String('a');
|
||||
Serial.println(stringOne); // prints "a"
|
||||
|
||||
// converting a constant string into a String object:
|
||||
String stringTwo = String("This is a string");
|
||||
Serial.println(stringTwo); // prints "This is a string"
|
||||
|
||||
// concatenating two strings:
|
||||
stringOne = String(stringTwo + " with more");
|
||||
// prints "This is a string with more":
|
||||
Serial.println(stringOne);
|
||||
|
||||
// using a constant integer:
|
||||
stringOne = String(13);
|
||||
Serial.println(stringOne); // prints "13"
|
||||
|
||||
// using an int and a base:
|
||||
stringOne = String(analogRead(A0), DEC);
|
||||
// prints "453" or whatever the value of analogRead(A0) is
|
||||
Serial.println(stringOne);
|
||||
|
||||
// using an int and a base (hexadecimal):
|
||||
stringOne = String(45, HEX);
|
||||
// prints "2d", which is the hexadecimal version of decimal 45:
|
||||
Serial.println(stringOne);
|
||||
|
||||
// using an int and a base (binary)
|
||||
stringOne = String(255, BIN);
|
||||
// prints "11111111" which is the binary value of 255
|
||||
Serial.println(stringOne);
|
||||
|
||||
// using a long and a base:
|
||||
stringOne = String(millis(), DEC);
|
||||
// prints "123456" or whatever the value of millis() is:
|
||||
Serial.println(stringOne);
|
||||
|
||||
// do nothing while true:
|
||||
while(true);
|
||||
|
||||
}
|
@ -1,35 +0,0 @@
|
||||
/*
|
||||
String replace()
|
||||
|
||||
Examples of how to replace characters or substrings of a string
|
||||
|
||||
created 27 July 2010
|
||||
by Tom Igoe
|
||||
|
||||
http://arduino.cc/en/Tutorial/StringReplace
|
||||
|
||||
This example code is in the public domain.
|
||||
*/
|
||||
|
||||
void setup() {
|
||||
Serial.begin(9600);
|
||||
Serial.println("\n\nString replace:");
|
||||
}
|
||||
|
||||
void loop() {
|
||||
String stringOne = "<html><head><body>";
|
||||
Serial.println(stringOne);
|
||||
// replace() changes all instances of one substring with another:
|
||||
String stringTwo = stringOne.replace("<", "</");
|
||||
Serial.println(stringTwo);
|
||||
|
||||
// you can also use replace() on single characters:
|
||||
String normalString = "bookkeeper";
|
||||
Serial.println("normal: " + normalString);
|
||||
String leetString = normalString.replace('o', '0');
|
||||
leetString = leetString.replace('e', '3');
|
||||
Serial.println("l33tspeak: " + leetString);
|
||||
|
||||
// do nothing while true:
|
||||
while(true);
|
||||
}
|
@ -1,230 +0,0 @@
|
||||
/*
|
||||
Serial RGB controller
|
||||
|
||||
Reads a serial input string looking for three comma-separated
|
||||
integers with a newline at the end. Values should be between
|
||||
0 and 255. The sketch uses those values to set the color
|
||||
of an RGB LED attached to pins 9 - 11.
|
||||
|
||||
The circuit:
|
||||
* Common-anode RGB LED cathodes attached to pins 9 - 11
|
||||
* LED anode connected to pin 13
|
||||
|
||||
To turn on any given channel, set the pin LOW.
|
||||
To turn off, set the pin HIGH. The higher the analogWrite level,
|
||||
the lower the brightness.
|
||||
|
||||
created 29 Nov 2010
|
||||
by Tom Igoe
|
||||
|
||||
This example code is in the public domain.
|
||||
*/
|
||||
|
||||
String inString = ""; // string to hold input
|
||||
int currentColor = 0;
|
||||
int red, green, blue = 0;
|
||||
|
||||
void setup() {
|
||||
// Initialize serial communications:
|
||||
Serial.begin(9600);
|
||||
// set LED cathode pins as outputs:
|
||||
pinMode(9, OUTPUT);
|
||||
pinMode(10, OUTPUT);
|
||||
pinMode(11, OUTPUT);
|
||||
// turn on pin 13 to power the LEDs:
|
||||
pinMode(13, OUTPUT);
|
||||
digitalWrite(13, HIGH);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
int inChar;
|
||||
|
||||
// Read serial input:
|
||||
if (Serial.available() > 0) {
|
||||
inChar = Serial.read();
|
||||
}
|
||||
|
||||
if (isDigit(inChar)) {
|
||||
// convert the incoming byte to a char
|
||||
// and add it to the string:
|
||||
inString += (char)inChar;
|
||||
}
|
||||
|
||||
// if you get a comma, convert to a number,
|
||||
// set the appropriate color, and increment
|
||||
// the color counter:
|
||||
if (inChar == ',') {
|
||||
// do something different for each value of currentColor:
|
||||
switch (currentColor) {
|
||||
case 0: // 0 = red
|
||||
red = inString.toInt();
|
||||
// clear the string for new input:
|
||||
inString = "";
|
||||
break;
|
||||
case 1: // 1 = green:
|
||||
green = inString.toInt();
|
||||
// clear the string for new input:
|
||||
inString = "";
|
||||
break;
|
||||
}
|
||||
currentColor++;
|
||||
}
|
||||
// if you get a newline, you know you've got
|
||||
// the last color, i.e. blue:
|
||||
if (inChar == '\n') {
|
||||
blue = inString.toInt();
|
||||
|
||||
// set the levels of the LED.
|
||||
// subtract value from 255 because a higher
|
||||
// analogWrite level means a dimmer LED, since
|
||||
// you're raising the level on the anode:
|
||||
analogWrite(11, 255 - red);
|
||||
analogWrite(9, 255 - green);
|
||||
analogWrite(10, 255 - blue);
|
||||
|
||||
// print the colors:
|
||||
Serial.print("Red: ");
|
||||
Serial.print(red);
|
||||
Serial.print(", Green: ");
|
||||
Serial.print(green);
|
||||
Serial.print(", Blue: ");
|
||||
Serial.println(blue);
|
||||
|
||||
// clear the string for new input:
|
||||
inString = "";
|
||||
// reset the color counter:
|
||||
currentColor = 0;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
Here's a Processing sketch that will draw a color wheel and send a serial
|
||||
string with the color you click on:
|
||||
|
||||
// Subtractive Color Wheel with Serial
|
||||
// Based on a Processing example by Ira Greenberg.
|
||||
// Serial output added by Tom Igoe
|
||||
//
|
||||
// The primaries are red, yellow, and blue. The secondaries are green,
|
||||
// purple, and orange. The tertiaries are yellow-orange, red-orange,
|
||||
// red-purple, blue-purple, blue-green, and yellow-green.
|
||||
//
|
||||
// Create a shade or tint of the subtractive color wheel using
|
||||
// SHADE or TINT parameters.
|
||||
|
||||
// Updated 29 November 2010.
|
||||
|
||||
|
||||
|
||||
import processing.serial.*;
|
||||
|
||||
int segs = 12;
|
||||
int steps = 6;
|
||||
float rotAdjust = TWO_PI / segs / 2;
|
||||
float radius;
|
||||
float segWidth;
|
||||
float interval = TWO_PI / segs;
|
||||
|
||||
Serial myPort;
|
||||
|
||||
void setup() {
|
||||
size(200, 200);
|
||||
background(127);
|
||||
smooth();
|
||||
ellipseMode(RADIUS);
|
||||
noStroke();
|
||||
// make the diameter 90% of the sketch area
|
||||
radius = min(width, height) * 0.45;
|
||||
segWidth = radius / steps;
|
||||
|
||||
// swap which line is commented out to draw the other version
|
||||
// drawTintWheel();
|
||||
drawShadeWheel();
|
||||
// open the first serial port in your computer's list
|
||||
myPort = new Serial(this, Serial.list()[0], 9600);
|
||||
}
|
||||
|
||||
|
||||
void drawShadeWheel() {
|
||||
for (int j = 0; j < steps; j++) {
|
||||
color[] cols = {
|
||||
color(255-(255/steps)*j, 255-(255/steps)*j, 0),
|
||||
color(255-(255/steps)*j, (255/1.5)-((255/1.5)/steps)*j, 0),
|
||||
color(255-(255/steps)*j, (255/2)-((255/2)/steps)*j, 0),
|
||||
color(255-(255/steps)*j, (255/2.5)-((255/2.5)/steps)*j, 0),
|
||||
color(255-(255/steps)*j, 0, 0),
|
||||
color(255-(255/steps)*j, 0, (255/2)-((255/2)/steps)*j),
|
||||
color(255-(255/steps)*j, 0, 255-(255/steps)*j),
|
||||
color((255/2)-((255/2)/steps)*j, 0, 255-(255/steps)*j),
|
||||
color(0, 0, 255-(255/steps)*j),
|
||||
color(0, 255-(255/steps)*j, (255/2.5)-((255/2.5)/steps)*j),
|
||||
color(0, 255-(255/steps)*j, 0),
|
||||
color((255/2)-((255/2)/steps)*j, 255-(255/steps)*j, 0)
|
||||
};
|
||||
for (int i = 0; i < segs; i++) {
|
||||
fill(cols[i]);
|
||||
arc(width/2, height/2, radius, radius,
|
||||
interval*i+rotAdjust, interval*(i+1)+rotAdjust);
|
||||
}
|
||||
radius -= segWidth;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void drawTintWheel() {
|
||||
for (int j = 0; j < steps; j++) {
|
||||
color[] cols = {
|
||||
color((255/steps)*j, (255/steps)*j, 0),
|
||||
color((255/steps)*j, ((255/1.5)/steps)*j, 0),
|
||||
color((255/steps)*j, ((255/2)/steps)*j, 0),
|
||||
color((255/steps)*j, ((255/2.5)/steps)*j, 0),
|
||||
color((255/steps)*j, 0, 0),
|
||||
color((255/steps)*j, 0, ((255/2)/steps)*j),
|
||||
color((255/steps)*j, 0, (255/steps)*j),
|
||||
color(((255/2)/steps)*j, 0, (255/steps)*j),
|
||||
color(0, 0, (255/steps)*j),
|
||||
color(0, (255/steps)*j, ((255/2.5)/steps)*j),
|
||||
color(0, (255/steps)*j, 0),
|
||||
color(((255/2)/steps)*j, (255/steps)*j, 0)
|
||||
};
|
||||
for (int i = 0; i < segs; i++) {
|
||||
fill(cols[i]);
|
||||
arc(width/2, height/2, radius, radius,
|
||||
interval*i+rotAdjust, interval*(i+1)+rotAdjust);
|
||||
}
|
||||
radius -= segWidth;
|
||||
}
|
||||
}
|
||||
|
||||
void draw() {
|
||||
// nothing happens here
|
||||
}
|
||||
|
||||
void mouseReleased() {
|
||||
// get the color of the mouse position's pixel:
|
||||
color targetColor = get(mouseX, mouseY);
|
||||
// get the component values:
|
||||
int r = int(red(targetColor));
|
||||
int g = int(green(targetColor));
|
||||
int b = int(blue(targetColor));
|
||||
// make a comma-separated string:
|
||||
String colorString = r + "," + g + "," + b + "\n";
|
||||
// send it out the serial port:
|
||||
myPort.write(colorString );
|
||||
}
|
||||
|
||||
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -183,5 +183,17 @@ parseFloat KEYWORD2
|
||||
readBytes KEYWORD2
|
||||
readBytesUntil KEYWORD2
|
||||
|
||||
# USB-related keywords
|
||||
|
||||
Keyboard KEYWORD3
|
||||
Mouse KEYWORD3
|
||||
press KEYWORD2
|
||||
release KEYWORD2
|
||||
releaseAll KEYWORD2
|
||||
accept KEYWORD2
|
||||
click KEYWORD2
|
||||
move KEYWORD2
|
||||
isPressed KEYWORD2
|
||||
|
||||
setup KEYWORD3 Setup
|
||||
loop KEYWORD3 Loop
|
||||
|
Binary file not shown.
@ -1,3 +1,122 @@
|
||||
ARDUINO 1.0.1 - 2012.05.21
|
||||
|
||||
[environment]
|
||||
|
||||
* The IDE has been internationalized and translated into multiple languages.
|
||||
Thanks to Shigeru Kanemoto for the internationalization and Japanese
|
||||
translation and many others for the other translations. For more
|
||||
information, see: http://arduino.cc/playground/Main/LanguagesIDE
|
||||
|
||||
* Added preference for selecting the language in which to display the
|
||||
Arduino software. Defaults to the operating system locale.
|
||||
|
||||
* New upload process for the Arduino Leonardo (ATmega32U4).
|
||||
|
||||
* The editor font size preference now applies to the serial monitor and
|
||||
error / message console as well as the editor. (Paul Stoffregen)
|
||||
http://code.google.com/p/arduino/issues/detail?id=550
|
||||
|
||||
* Compilation has been speeded up by only compiling changed files. (All
|
||||
files are recompiled when a new board is selected.) (Paul Stoffregen)
|
||||
http://code.google.com/p/arduino/issues/detail?id=638
|
||||
|
||||
* Console log files (stdout.txt and stderr.txt) are now removed when the
|
||||
Arduino software exits. (Paul Stoffregen)
|
||||
|
||||
* The minimum size for the Arduino software window has been reduced.
|
||||
http://code.google.com/p/arduino/issues/detail?id=52
|
||||
|
||||
* Improvements to the Find / Replace dialog. (Peter Lewis)
|
||||
http://code.google.com/p/arduino/issues/detail?id=825
|
||||
|
||||
* Support for selecting words (on double-click) and lines (triple-click)
|
||||
in the Arduino software. (Peter Lewis)
|
||||
http://code.google.com/p/arduino/issues/detail?id=824
|
||||
|
||||
* Don't insert newline when using serial monitor keyboard
|
||||
shortcut. (Lars J. Nielsen)
|
||||
http://code.google.com/p/arduino/issues/detail?id=279
|
||||
|
||||
* Added a preference for disabling verification on upload (for increased
|
||||
speed). (Nathan Seidle)
|
||||
http://code.google.com/p/arduino/issues/detail?id=842
|
||||
|
||||
* Added the gcc toolchain to the Linux distribution. (To use the
|
||||
toolchain already installed on your system, simply delete the one
|
||||
that comes with the Arduino software.) (Paul Stoffregen)
|
||||
http://code.google.com/p/arduino/issues/detail?id=300
|
||||
|
||||
* Updating Arduino Mini upload protocol to 'arduino' from 'stk500' (should
|
||||
fix problems with auto-reset not working).
|
||||
|
||||
[core / libraries]
|
||||
|
||||
* Updated (and official) support for the Arduino Leonardo (ATmega32U4).
|
||||
Includes new bootloader and various fixes to the core.
|
||||
|
||||
* Adding overloads to Wire.write() (for Wire.write(0)). (Paul Stoffregen)
|
||||
http://code.google.com/p/arduino/issues/detail?id=527
|
||||
|
||||
* Fixing delayMicroseconds() for 20 MHz clocks (Erdem U. Altinyurt)
|
||||
http://code.google.com/p/arduino/issues/detail?id=306
|
||||
|
||||
* Support third external interrupt on ATmega1284P. (maniacbug)
|
||||
http://code.google.com/p/arduino/issues/detail?id=728
|
||||
|
||||
* Update reference voltage constants for ATmega1284P. (maniacbug)
|
||||
http://code.google.com/p/arduino/issues/detail?id=728
|
||||
|
||||
* Adding --relax linker flag for ATmega2560. (arducopter)
|
||||
http://code.google.com/p/arduino/issues/detail?id=729
|
||||
|
||||
* Fixing Ethernet library bug on avr-gcc 4.5.1 (SurferTim)
|
||||
http://code.google.com/p/arduino/issues/detail?id=605
|
||||
|
||||
* Fixed DHCP hostname generation. (peter)
|
||||
|
||||
* Simplifying microseconds to clock cycles conversions (Rob Tillaart)
|
||||
http://code.google.com/p/arduino/issues/detail?id=675
|
||||
|
||||
* Fixed various warnings. (maniacbug)
|
||||
http://code.google.com/p/arduino/issues/detail?id=688
|
||||
|
||||
* Fixed bug w/ repeated initial characters in findUntil(). (Jeffery.zksun)
|
||||
http://code.google.com/p/arduino/issues/detail?id=768
|
||||
|
||||
* Added INPUT_PULLUP option for pinMode(). The INPUT mode now explicitly
|
||||
disables the pullup resistors. (Paul Stoffregen)
|
||||
http://code.google.com/p/arduino/issues/detail?id=246
|
||||
|
||||
* Fixing bug in the receiving of multiple UDP packets. (dylan and peter)
|
||||
http://code.google.com/p/arduino/issues/detail?id=669
|
||||
|
||||
* Added ability to generate repeated starts in the Wire library (in
|
||||
master mode). Extra boolean parameters to endTransmission() and
|
||||
requestFrom() control whether or not to send a stop (or a repeated
|
||||
start instead). (Todd Krein)
|
||||
http://code.google.com/p/arduino/issues/detail?id=663
|
||||
|
||||
* Added Ethernet.maintain() to renew DHCP leases. (Peter Magnusson)
|
||||
http://code.google.com/p/arduino/issues/detail?id=716
|
||||
|
||||
* Fix for CLOSE_WAIT bug that could cause Ethernet sketches to crash
|
||||
over time. (mr-russ and Johann Richard)
|
||||
|
||||
* Fix to servo pulse timing calculation. (jwatte)
|
||||
http://code.google.com/p/arduino/issues/detail?id=908
|
||||
|
||||
* Added readString() and readStringUntil() functions. (Adrian McEwen)
|
||||
http://code.google.com/p/arduino/issues/detail?id=454
|
||||
|
||||
[examples]
|
||||
|
||||
* Updated to latest ArduinoISP sketch. (rsbohn)
|
||||
http://code.google.com/p/arduino/issues/detail?id=378
|
||||
|
||||
* Fixed ArduinoISP sketch by lowering delay() in heartbeat.
|
||||
|
||||
* Other updates.
|
||||
|
||||
ARDUINO 1.0 - 2011.11.30
|
||||
|
||||
[environment]
|
||||
|
@ -86,13 +86,12 @@ ServiceBinary=%12%\%DRIVERFILENAME%.sys
|
||||
[SourceDisksFiles]
|
||||
[SourceDisksNames]
|
||||
[DeviceList]
|
||||
%DESCRIPTION%=DriverInstall, USB\VID_2341&PID_0032
|
||||
%DESCRIPTION%=DriverInstall, USB\VID_2341&PID_0034&MI_00
|
||||
%DESCRIPTION%=DriverInstall, USB\VID_2341&PID_0036
|
||||
%DESCRIPTION%=DriverInstall, USB\VID_2341&PID_8036&MI_00
|
||||
|
||||
[DeviceList.NTamd64]
|
||||
%DESCRIPTION%=DriverInstall, USB\VID_2341&PID_0032
|
||||
%DESCRIPTION%=DriverInstall, USB\VID_2341&PID_0034&MI_00
|
||||
|
||||
%DESCRIPTION%=DriverInstall, USB\VID_2341&PID_0036
|
||||
%DESCRIPTION%=DriverInstall, USB\VID_2341&PID_8036&MI_00
|
||||
|
||||
;------------------------------------------------------------------------------
|
||||
; String Definitions
|
||||
|
Reference in New Issue
Block a user