Skip to content

Commit 5e98cd8

Browse files
author
Federico Fissore
committed
Examples: mass code format. See example_formatter.conf
1 parent 1af21b2 commit 5e98cd8

File tree

136 files changed

+1377
-1467
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

136 files changed

+1377
-1467
lines changed

build/shared/examples/02.Digital/BlinkWithoutDelay/BlinkWithoutDelay.ino

+12-12
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,17 @@
88
* LED attached from pin 13 to ground.
99
* Note: on most Arduinos, there is already an LED on the board
1010
that's attached to pin 13, so no hardware is needed for this example.
11-
11+
1212
created 2005
1313
by David A. Mellis
1414
modified 8 Feb 2010
1515
by Paul Stoffregen
1616
modified 11 Nov 2013
1717
by Scott Fitzgerald
18-
19-
18+
19+
2020
This example code is in the public domain.
21-
21+
2222
http://www.arduino.cc/en/Tutorial/BlinkWithoutDelay
2323
*/
2424

@@ -40,25 +40,25 @@ void setup() {
4040
pinMode(ledPin, OUTPUT);
4141
}
4242

43-
void loop()
44-
{
43+
void loop() {
4544
// here is where you'd put code that needs to be running all the time.
4645

4746
// check to see if it's time to blink the LED; that is, if the
4847
// difference between the current time and last time you blinked
4948
// the LED is bigger than the interval at which you want to
5049
// blink the LED.
5150
unsigned long currentMillis = millis();
52-
53-
if(currentMillis - previousMillis >= interval) {
54-
// save the last time you blinked the LED
55-
previousMillis = currentMillis;
51+
52+
if (currentMillis - previousMillis >= interval) {
53+
// save the last time you blinked the LED
54+
previousMillis = currentMillis;
5655

5756
// if the LED is off turn it on and vice-versa:
58-
if (ledState == LOW)
57+
if (ledState == LOW) {
5958
ledState = HIGH;
60-
else
59+
} else {
6160
ledState = LOW;
61+
}
6262

6363
// set the LED with the ledState of the variable:
6464
digitalWrite(ledPin, ledState);

build/shared/examples/02.Digital/Button/Button.ino

+1-2
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,7 @@ void loop() {
4848
if (buttonState == HIGH) {
4949
// turn LED on:
5050
digitalWrite(ledPin, HIGH);
51-
}
52-
else {
51+
} else {
5352
// turn LED off:
5453
digitalWrite(ledPin, LOW);
5554
}

build/shared/examples/02.Digital/DigitalInputPullup/DigitalInputPullup.ino

+1-2
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,7 @@ void loop() {
4242
// button's pressed, and off when it's not:
4343
if (sensorVal == HIGH) {
4444
digitalWrite(13, LOW);
45-
}
46-
else {
45+
} else {
4746
digitalWrite(13, HIGH);
4847
}
4948
}

build/shared/examples/02.Digital/StateChangeDetection/StateChangeDetection.ino

+1-2
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,7 @@ void loop() {
5858
Serial.println("on");
5959
Serial.print("number of button pushes: ");
6060
Serial.println(buttonPushCounter);
61-
}
62-
else {
61+
} else {
6362
// if the current state is LOW then the button
6463
// wend from on to off:
6564
Serial.println("off");

build/shared/examples/03.Analog/AnalogInOutSerial/AnalogInOutSerial.ino

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ void loop() {
4141
analogWrite(analogOutPin, outputValue);
4242

4343
// print the results to the serial monitor:
44-
Serial.print("sensor = " );
44+
Serial.print("sensor = ");
4545
Serial.print(sensorValue);
4646
Serial.print("\t output = ");
4747
Serial.println(outputValue);

build/shared/examples/03.Analog/Smoothing/Smoothing.ino

+5-4
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,13 @@ int average = 0; // the average
3434

3535
int inputPin = A0;
3636

37-
void setup()
38-
{
37+
void setup() {
3938
// initialize serial communication with computer:
4039
Serial.begin(9600);
4140
// initialize all the readings to 0:
42-
for (int thisReading = 0; thisReading < numReadings; thisReading++)
41+
for (int thisReading = 0; thisReading < numReadings; thisReading++) {
4342
readings[thisReading] = 0;
43+
}
4444
}
4545

4646
void loop() {
@@ -54,9 +54,10 @@ void loop() {
5454
readIndex = readIndex + 1;
5555

5656
// if we're at the end of the array...
57-
if (readIndex >= numReadings)
57+
if (readIndex >= numReadings) {
5858
// ...wrap around to the beginning:
5959
readIndex = 0;
60+
}
6061

6162
// calculate the average:
6263
average = total / numReadings;

build/shared/examples/04.Communication/Dimmer/Dimmer.ino

+1-2
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@
2323

2424
const int ledPin = 9; // the pin that the LED is attached to
2525

26-
void setup()
27-
{
26+
void setup() {
2827
// initialize the serial communication:
2928
Serial.begin(9600);
3029
// initialize the ledPin as an output:

build/shared/examples/04.Communication/Graph/Graph.ino

+3-3
Original file line numberDiff line numberDiff line change
@@ -65,15 +65,15 @@ void loop() {
6565
// List all the available serial ports
6666
// if using Processing 2.1 or later, use Serial.printArray()
6767
println(Serial.list());
68-
68+
6969
// I know that the first port in the serial list on my mac
7070
// is always my Arduino, so I open Serial.list()[0].
7171
// Open whatever port is the one you're using.
7272
myPort = new Serial(this, Serial.list()[0], 9600);
73-
73+
7474
// don't generate a serialEvent() unless you get a newline character:
7575
myPort.bufferUntil('\n');
76-
76+
7777
// set inital background:
7878
background(0);
7979
}

build/shared/examples/04.Communication/PhysicalPixel/PhysicalPixel.ino

+12-12
Original file line numberDiff line numberDiff line change
@@ -78,19 +78,19 @@ void loop() {
7878
size(200, 200);
7979
boxX = width/2.0;
8080
boxY = height/2.0;
81-
rectMode(RADIUS);
82-
83-
// List all the available serial ports in the output pane.
84-
// You will need to choose the port that the Arduino board is
85-
// connected to from this list. The first port in the list is
86-
// port #0 and the third port in the list is port #2.
81+
rectMode(RADIUS);
82+
83+
// List all the available serial ports in the output pane.
84+
// You will need to choose the port that the Arduino board is
85+
// connected to from this list. The first port in the list is
86+
// port #0 and the third port in the list is port #2.
8787
// if using Processing 2.1 or later, use Serial.printArray()
88-
println(Serial.list());
89-
90-
// Open the port that the Arduino board is connected to (in this case #0)
91-
// Make sure to open the port at the same speed Arduino is using (9600bps)
92-
port = new Serial(this, Serial.list()[0], 9600);
93-
88+
println(Serial.list());
89+
90+
// Open the port that the Arduino board is connected to (in this case #0)
91+
// Make sure to open the port at the same speed Arduino is using (9600bps)
92+
port = new Serial(this, Serial.list()[0], 9600);
93+
9494
}
9595
9696
void draw()

build/shared/examples/04.Communication/SerialCallResponse/SerialCallResponse.ino

+2-4
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ int secondSensor = 0; // second analog sensor
2929
int thirdSensor = 0; // digital sensor
3030
int inByte = 0; // incoming serial byte
3131

32-
void setup()
33-
{
32+
void setup() {
3433
// start serial port at 9600 bps:
3534
Serial.begin(9600);
3635
while (!Serial) {
@@ -41,8 +40,7 @@ void setup()
4140
establishContact(); // send a byte to establish contact until receiver responds
4241
}
4342

44-
void loop()
45-
{
43+
void loop() {
4644
// if we get a valid byte, read analog ins:
4745
if (Serial.available() > 0) {
4846
// get incoming byte:

build/shared/examples/04.Communication/SerialCallResponseASCII/SerialCallResponseASCII.ino

+2-4
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@ int secondSensor = 0; // second analog sensor
3333
int thirdSensor = 0; // digital sensor
3434
int inByte = 0; // incoming serial byte
3535

36-
void setup()
37-
{
36+
void setup() {
3837
// start serial port at 9600 bps and wait for port to open:
3938
Serial.begin(9600);
4039
while (!Serial) {
@@ -46,8 +45,7 @@ void setup()
4645
establishContact(); // send a byte to establish contact until receiver responds
4746
}
4847

49-
void loop()
50-
{
48+
void loop() {
5149
// if we get a valid byte, read analog ins:
5250
if (Serial.available() > 0) {
5351
// get incoming byte:

build/shared/examples/04.Communication/VirtualColorMixer/VirtualColorMixer.ino

+3-5
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,11 @@ const int redPin = A0; // sensor to control red color
2020
const int greenPin = A1; // sensor to control green color
2121
const int bluePin = A2; // sensor to control blue color
2222

23-
void setup()
24-
{
23+
void setup() {
2524
Serial.begin(9600);
2625
}
2726

28-
void loop()
29-
{
27+
void loop() {
3028
Serial.print(analogRead(redPin));
3129
Serial.print(",");
3230
Serial.print(analogRead(greenPin));
@@ -52,7 +50,7 @@ void loop()
5250
// List all the available serial ports
5351
// if using Processing 2.1 or later, use Serial.printArray()
5452
println(Serial.list());
55-
53+
5654
// I know that the first port in the serial list on my mac
5755
// is always my Arduino, so I open Serial.list()[0].
5856
// Open whatever port is the one you're using.

build/shared/examples/05.Control/IfStatementConditional/IfStatementConditional.ino

+1-2
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,7 @@ void loop() {
4444
// if the analog value is high enough, turn on the LED:
4545
if (analogValue > threshold) {
4646
digitalWrite(ledPin, HIGH);
47-
}
48-
else {
47+
} else {
4948
digitalWrite(ledPin, LOW);
5049
}
5150

build/shared/examples/05.Control/WhileStatementConditional/WhileStatementConditional.ino

+2-2
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ int sensorValue = 0; // the sensor value
4343
void setup() {
4444
// set the LED pins as outputs and the switch pin as input:
4545
pinMode(indicatorLedPin, OUTPUT);
46-
pinMode (ledPin, OUTPUT);
47-
pinMode (buttonPin, INPUT);
46+
pinMode(ledPin, OUTPUT);
47+
pinMode(buttonPin, INPUT);
4848
}
4949

5050
void loop() {

build/shared/examples/06.Sensors/ADXL3xx/ADXL3xx.ino

+2-4
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@ const int xpin = A3; // x-axis of the accelerometer
3333
const int ypin = A2; // y-axis
3434
const int zpin = A1; // z-axis (only on 3-axis models)
3535

36-
void setup()
37-
{
36+
void setup() {
3837
// initialize the serial communications:
3938
Serial.begin(9600);
4039

@@ -48,8 +47,7 @@ void setup()
4847
digitalWrite(powerpin, HIGH);
4948
}
5049

51-
void loop()
52-
{
50+
void loop() {
5351
// print the sensor values:
5452
Serial.print(analogRead(xpin));
5553
// print a tab between values:

build/shared/examples/06.Sensors/Ping/Ping.ino

+3-6
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@ void setup() {
3131
Serial.begin(9600);
3232
}
3333

34-
void loop()
35-
{
34+
void loop() {
3635
// establish variables for duration of the ping,
3736
// and the distance result in inches and centimeters:
3837
long duration, inches, cm;
@@ -65,8 +64,7 @@ void loop()
6564
delay(100);
6665
}
6766

68-
long microsecondsToInches(long microseconds)
69-
{
67+
long microsecondsToInches(long microseconds) {
7068
// According to Parallax's datasheet for the PING))), there are
7169
// 73.746 microseconds per inch (i.e. sound travels at 1130 feet per
7270
// second). This gives the distance travelled by the ping, outbound
@@ -75,8 +73,7 @@ long microsecondsToInches(long microseconds)
7573
return microseconds / 74 / 2;
7674
}
7775

78-
long microsecondsToCentimeters(long microseconds)
79-
{
76+
long microsecondsToCentimeters(long microseconds) {
8077
// The speed of sound is 340 m/s or 29 microseconds per centimeter.
8178
// The ping travels out and back, so to find the distance of the
8279
// object we take half of the distance travelled.

build/shared/examples/08.Strings/StringAdditionOperator/StringAdditionOperator.ino

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ void setup() {
2525

2626
stringOne = String("stringThree = ");
2727
stringTwo = String("this string");
28-
stringThree = String ();
28+
stringThree = String();
2929
// send an intro:
3030
Serial.println("\n\nAdding strings together (concatenation):");
3131
Serial.println();

build/shared/examples/08.Strings/StringComparisonOperators/StringComparisonOperators.ino

+6-10
Original file line numberDiff line numberDiff line change
@@ -49,16 +49,14 @@ void loop() {
4949
// you can also use equals() to see if two strings are the same:
5050
if (stringOne.equals(stringTwo)) {
5151
Serial.println(stringOne + " equals " + stringTwo);
52-
}
53-
else {
52+
} else {
5453
Serial.println(stringOne + " does not equal " + stringTwo);
5554
}
5655

5756
// or perhaps you want to ignore case:
5857
if (stringOne.equalsIgnoreCase(stringTwo)) {
5958
Serial.println(stringOne + " equals (ignoring case) " + stringTwo);
60-
}
61-
else {
59+
} else {
6260
Serial.println(stringOne + " does not equal (ignoring case) " + stringTwo);
6361
}
6462

@@ -103,10 +101,9 @@ void loop() {
103101
// comes first in alphanumeric order, then compareTo() is greater than 0:
104102
stringOne = "Cucumber";
105103
stringTwo = "Cucuracha";
106-
if (stringOne.compareTo(stringTwo) < 0 ) {
104+
if (stringOne.compareTo(stringTwo) < 0) {
107105
Serial.println(stringOne + " comes before " + stringTwo);
108-
}
109-
else {
106+
} else {
110107
Serial.println(stringOne + " comes after " + stringTwo);
111108
}
112109

@@ -121,10 +118,9 @@ void loop() {
121118
stringOne += analogRead(A0);
122119
stringTwo += analogRead(A5);
123120

124-
if (stringOne.compareTo(stringTwo) < 0 ) {
121+
if (stringOne.compareTo(stringTwo) < 0) {
125122
Serial.println(stringOne + " comes before " + stringTwo);
126-
}
127-
else {
123+
} else {
128124
Serial.println(stringOne + " comes after " + stringTwo);
129125

130126
}

build/shared/examples/08.Strings/StringIndexOf/StringIndexOf.ino

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ void loop() {
3333

3434
stringOne = "<HTML><HEAD><BODY>";
3535
int secondOpeningBracket = firstClosingBracket + 1;
36-
int secondClosingBracket = stringOne.indexOf('>', secondOpeningBracket );
36+
int secondClosingBracket = stringOne.indexOf('>', secondOpeningBracket);
3737
Serial.println("The index of the second > in the string " + stringOne + " is " + secondClosingBracket);
3838

3939
// you can also use indexOf() to search for Strings:
@@ -43,7 +43,7 @@ void loop() {
4343

4444
stringOne = "<UL><LI>item<LI>item<LI>item</UL>";
4545
int firstListItem = stringOne.indexOf("<LI>");
46-
int secondListItem = stringOne.indexOf("item", firstListItem + 1 );
46+
int secondListItem = stringOne.indexOf("item", firstListItem + 1);
4747
Serial.println("The index of the second list item in the string " + stringOne + " is " + secondClosingBracket);
4848

4949
// lastIndexOf() gives you the last occurrence of a character or string:

0 commit comments

Comments
 (0)