1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-08-05 13:16:13 +03:00

Run new astyle formatter against all the examples

This commit is contained in:
Federico Fissore
2013-10-21 09:58:40 +02:00
parent 3c6ee46828
commit b4c68b3dff
259 changed files with 5160 additions and 5217 deletions

View File

@@ -1,13 +1,13 @@
/*
Character analysis operators
Character analysis operators
Examples using the character analysis operators.
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.
*/
@@ -35,40 +35,40 @@ void loop() {
Serial.println(thisChar);
// analyze what was sent:
if(isAlphaNumeric(thisChar)) {
if (isAlphaNumeric(thisChar)) {
Serial.println("it's alphanumeric");
}
if(isAlpha(thisChar)) {
if (isAlpha(thisChar)) {
Serial.println("it's alphabetic");
}
if(isAscii(thisChar)) {
if (isAscii(thisChar)) {
Serial.println("it's ASCII");
}
if(isWhitespace(thisChar)) {
if (isWhitespace(thisChar)) {
Serial.println("it's whitespace");
}
if(isControl(thisChar)) {
if (isControl(thisChar)) {
Serial.println("it's a control character");
}
if(isDigit(thisChar)) {
if (isDigit(thisChar)) {
Serial.println("it's a numeric digit");
}
if(isGraph(thisChar)) {
if (isGraph(thisChar)) {
Serial.println("it's a printable character that's not whitespace");
}
if(isLowerCase(thisChar)) {
if (isLowerCase(thisChar)) {
Serial.println("it's lower case");
}
if(isPrintable(thisChar)) {
if (isPrintable(thisChar)) {
Serial.println("it's printable");
}
if(isPunct(thisChar)) {
if (isPunct(thisChar)) {
Serial.println("it's punctuation");
}
if(isSpace(thisChar)) {
if (isSpace(thisChar)) {
Serial.println("it's a space character");
}
if(isUpperCase(thisChar)) {
if (isUpperCase(thisChar)) {
Serial.println("it's upper case");
}
if (isHexadecimalDigit(thisChar)) {

View File

@@ -1,16 +1,16 @@
/*
Adding Strings together
Examples of how to add strings together
You can also add several different data types to string, as shown here:
created 27 July 2010
modified 2 Apr 2012
by Tom Igoe
http://arduino.cc/en/Tutorial/StringAdditionOperator
This example code is in the public domain.
This example code is in the public domain.
*/
// declare three strings:
@@ -59,10 +59,10 @@ void loop() {
// adding a variable long integer to a string:
long currentTime = millis();
stringOne="millis() value: ";
stringOne = "millis() value: ";
stringThree = stringOne + millis();
Serial.println(stringThree); // prints "The millis: 345345" or whatever value currentTime has
// do nothing while true:
while(true);
while (true);
}

View File

@@ -1,14 +1,14 @@
/*
Appending to Strings using the += operator and concat()
Examples of how to append different data types to strings
created 27 July 2010
modified 2 Apr 2012
by Tom Igoe
http://arduino.cc/en/Tutorial/StringAppendOperator
This example code is in the public domain.
*/
@@ -68,6 +68,6 @@ void loop() {
Serial.println(stringTwo); // prints "The millis(): 43534" or whatever the value of the millis() is
// do nothing while true:
while(true);
while (true);
}

View File

@@ -1,14 +1,14 @@
/*
String Case changes
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
This example code is in the public domain.
*/
@@ -31,7 +31,7 @@ void loop() {
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.toLowerCase();
@@ -39,5 +39,5 @@ void loop() {
// do nothing while true:
while(true);
while (true);
}

View File

@@ -1,14 +1,14 @@
/*
String charAt() and setCharAt()
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
This example code is in the public domain.
*/
@@ -30,17 +30,17 @@ void loop() {
// the reading's most significant digit is at position 15 in the reportString:
char mostSignificantDigit = reportString.charAt(15);
String message = "Most significant digit of the sensor reading is: ";
String message = "Most significant digit of the sensor reading is: ";
Serial.println(message + mostSignificantDigit);
// add blank space:
Serial.println();
// you can alo set the character of a string. Change the : to a = character
reportString.setCharAt(13, '=');
reportString.setCharAt(13, '=');
Serial.println(reportString);
// do nothing while true:
while(true);
while (true);
}

View File

@@ -1,14 +1,14 @@
/*
Comparing Strings
Comparing Strings
Examples of how to compare strings using the comparison operators
created 27 July 2010
modified 2 Apr 2012
by Tom Igoe
http://arduino.cc/en/Tutorial/StringComparisonOperators
This example code is in the public domain.
*/
@@ -33,7 +33,7 @@ void setup() {
void loop() {
// two strings equal:
if (stringOne == "this") {
Serial.println("StringOne == \"this\"");
Serial.println("StringOne == \"this\"");
}
// two strings not equal:
if (stringOne != stringTwo) {
@@ -49,7 +49,7 @@ void loop() {
// you can also use equals() to see if two strings are the same:
if (stringOne.equals(stringTwo)) {
Serial.println(stringOne + " equals " + stringTwo);
}
}
else {
Serial.println(stringOne + " does not equal " + stringTwo);
}
@@ -57,7 +57,7 @@ void loop() {
// or perhaps you want to ignore case:
if (stringOne.equalsIgnoreCase(stringTwo)) {
Serial.println(stringOne + " equals (ignoring case) " + stringTwo);
}
}
else {
Serial.println(stringOne + " does not equal (ignoring case) " + stringTwo);
}
@@ -81,20 +81,20 @@ void loop() {
// comparison operators can be used to compare strings for alphabetic sorting too:
stringOne = String("Brown");
if (stringOne < "Charles") {
Serial.println(stringOne + " < Charles");
Serial.println(stringOne + " < Charles");
}
if (stringOne > "Adams") {
Serial.println(stringOne + " > Adams");
Serial.println(stringOne + " > Adams");
}
if (stringOne <= "Browne") {
Serial.println(stringOne + " <= Browne");
Serial.println(stringOne + " <= Browne");
}
if (stringOne >= "Brow") {
Serial.println(stringOne + " >= Brow");
Serial.println(stringOne + " >= Brow");
}
// the compareTo() operator also allows you to compare strings
@@ -104,10 +104,10 @@ void loop() {
stringOne = "Cucumber";
stringTwo = "Cucuracha";
if (stringOne.compareTo(stringTwo) < 0 ) {
Serial.println(stringOne + " comes before " + stringTwo);
}
Serial.println(stringOne + " comes before " + stringTwo);
}
else {
Serial.println(stringOne + " comes after " + stringTwo);
Serial.println(stringOne + " comes after " + stringTwo);
}
delay(10000); // because the next part is a loop:
@@ -116,16 +116,16 @@ void loop() {
while (true) {
stringOne = "Sensor: ";
stringTwo= "Sensor: ";
stringTwo = "Sensor: ";
stringOne += analogRead(A0);
stringOne += analogRead(A0);
stringTwo += analogRead(A5);
if (stringOne.compareTo(stringTwo) < 0 ) {
Serial.println(stringOne + " comes before " + stringTwo);
}
Serial.println(stringOne + " comes before " + stringTwo);
}
else {
Serial.println(stringOne + " comes after " + stringTwo);
Serial.println(stringOne + " comes after " + stringTwo);
}
}

View File

@@ -1,14 +1,14 @@
/*
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.
*/
@@ -18,7 +18,7 @@ void setup() {
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
// send an intro:
Serial.println("\n\nString Constructors:");
Serial.println();
@@ -26,47 +26,47 @@ void setup() {
void loop() {
// using a constant String:
String stringOne = "Hello String";
String stringOne = "Hello String";
Serial.println(stringOne); // prints "Hello String"
// converting a constant char into a String:
stringOne = String('a');
stringOne = String('a');
Serial.println(stringOne); // prints "a"
// converting a constant string into a String object:
String stringTwo = String("This is a string");
String stringTwo = String("This is a string");
Serial.println(stringTwo); // prints "This is a string"
// concatenating two strings:
stringOne = String(stringTwo + " with more");
stringOne = String(stringTwo + " with more");
// prints "This is a string with more":
Serial.println(stringOne);
Serial.println(stringOne);
// using a constant integer:
stringOne = String(13);
stringOne = String(13);
Serial.println(stringOne); // prints "13"
// using an int and a base:
stringOne = String(analogRead(A0), DEC);
stringOne = String(analogRead(A0), DEC);
// prints "453" or whatever the value of analogRead(A0) is
Serial.println(stringOne);
Serial.println(stringOne);
// using an int and a base (hexadecimal):
stringOne = String(45, HEX);
stringOne = String(45, HEX);
// prints "2d", which is the hexadecimal version of decimal 45:
Serial.println(stringOne);
Serial.println(stringOne);
// using an int and a base (binary)
stringOne = String(255, BIN);
stringOne = String(255, BIN);
// prints "11111111" which is the binary value of 255
Serial.println(stringOne);
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);
// prints "123456" or whatever the value of millis() is:
Serial.println(stringOne);
// do nothing while true:
while(true);
while (true);
}

View File

@@ -1,15 +1,15 @@
/*
String indexOf() and lastIndexOf() functions
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
This example code is in the public domain.
This example code is in the public domain.
*/
void setup() {
@@ -61,6 +61,6 @@ void loop() {
Serial.println("The index of the second last paragraph tag " + stringOne + " is " + secondLastGraf);
// do nothing while true:
while(true);
while (true);
}

View File

@@ -1,14 +1,14 @@
/*
String length()
Examples of how to use length() in a String.
String length()
Examples of how to use length() in a String.
Open the Serial Monitor and start sending characters to see the results.
created 1 Aug 2010
by Tom Igoe
http://arduino.cc/en/Tutorial/StringLengthTrim
This example code is in the public domain.
*/
@@ -32,7 +32,7 @@ void loop() {
while (Serial.available() > 0) {
char inChar = Serial.read();
txtMsg += inChar;
}
}
// print the message and a notice if it's changed:
if (txtMsg.length() != lastStringLength) {
@@ -41,9 +41,9 @@ void loop() {
// if the String's longer than 140 characters, complain:
if (txtMsg.length() < 140) {
Serial.println("That's a perfectly acceptable text message");
}
}
else {
Serial.println("That's too long for a text message.");
Serial.println("That's too long for a text message.");
}
// note the length for next time through the loop:
lastStringLength = txtMsg.length();

View File

@@ -1,14 +1,14 @@
/*
String length() and trim()
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
This example code is in the public domain.
*/
@@ -38,5 +38,5 @@ void loop() {
Serial.println(stringOne.length());
// do nothing while true:
while(true);
while (true);
}

View File

@@ -1,15 +1,15 @@
/*
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.
This example code is in the public domain.
*/
void setup() {
@@ -46,5 +46,5 @@ void loop() {
Serial.println("l33tspeak: " + leetString);
// do nothing while true:
while(true);
while (true);
}

View File

@@ -1,14 +1,14 @@
/*
String startWith() and endsWith()
Examples of how to use startsWith() and endsWith() in a String
created 27 July 2010
modified 2 Apr 2012
by Tom Igoe
http://arduino.cc/en/Tutorial/StringStartsWithEndsWith
This example code is in the public domain.
*/
@@ -29,27 +29,27 @@ void loop() {
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");
}
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";
if (stringOne.startsWith("200 OK", 9)) {
Serial.println("Got an OK from the server");
}
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);
Serial.print (sensorReading);
if (sensorReading.endsWith(0)) {
Serial.println(". This reading is divisible by ten");
}
Serial.println(". This reading is divisible by ten");
}
else {
Serial.println(". This reading is not divisible by ten");
Serial.println(". This reading is not divisible by ten");
}
// do nothing while true:
while(true);
while (true);
}

View File

@@ -1,14 +1,14 @@
/*
String substring()
Examples of how to use substring in a String
created 27 July 2010,
created 27 July 2010,
modified 2 Apr 2012
by Zach Eveland
http://arduino.cc/en/Tutorial/StringSubstring
This example code is in the public domain.
*/
@@ -31,13 +31,13 @@ void loop() {
// 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");
}
Serial.println("It's an html file");
}
// you can also look for a substring in the middle of a string:
if (stringOne.substring(14,18) == "text") {
Serial.println("It's a text-based file");
}
if (stringOne.substring(14, 18) == "text") {
Serial.println("It's a text-based file");
}
// do nothing while true:
while(true);
while (true);
}

View File

@@ -1,16 +1,16 @@
/*
String to Integer conversion
Reads a serial input string until it sees a newline, then converts
the string to a number if the characters are digits.
The circuit:
No external components needed.
created 29 Nov 2010
by Tom Igoe
This example code is in the public domain.
This example code is in the public domain.
*/
String inString = ""; // string to hold input
@@ -32,9 +32,9 @@ void loop() {
while (Serial.available() > 0) {
int inChar = Serial.read();
if (isDigit(inChar)) {
// convert the incoming byte to a char
// convert the incoming byte to a char
// and add it to the string:
inString += (char)inChar;
inString += (char)inChar;
}
// if you get a newline, print the string,
// then the string's value:
@@ -44,7 +44,7 @@ void loop() {
Serial.print("String: ");
Serial.println(inString);
// clear the string for new input:
inString = "";
inString = "";
}
}
}

View File

@@ -1,23 +1,23 @@
/*
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
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 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.
This example code is in the public domain.
*/
String inString = ""; // string to hold input
@@ -52,9 +52,9 @@ void loop() {
}
if (isDigit(inChar)) {
// convert the incoming byte to a char
// convert the incoming byte to a char
// and add it to the string:
inString += (char)inChar;
inString += (char)inChar;
}
// if you get a comma, convert to a number,
@@ -63,16 +63,16 @@ void loop() {
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;
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++;
}
@@ -98,7 +98,7 @@ void loop() {
Serial.println(blue);
// clear the string for new input:
inString = "";
inString = "";
// reset the color counter:
currentColor = 0;
}
@@ -109,33 +109,33 @@ void loop() {
/*
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.
// 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,
//
// 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);
@@ -145,70 +145,70 @@ Here's a Processing sketch that will draw a color wheel and send a serial
// 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[] 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(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,
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[] 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(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,
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);
@@ -221,7 +221,7 @@ Here's a Processing sketch that will draw a color wheel and send a serial
// send it out the serial port:
myPort.write(colorString );
}
*/