From abc9a8917d83aac7a543b5404aa2f8c9236fea45 Mon Sep 17 00:00:00 2001 From: per1234 Date: Fri, 14 Jul 2017 17:54:32 -0700 Subject: [PATCH] Use consistent formatting style for Processing code included in built-in example comments --- .../04.Communication/Dimmer/Dimmer.ino | 43 ++++++----- .../examples/04.Communication/Graph/Graph.ino | 7 +- .../PhysicalPixel/PhysicalPixel.ino | 77 +++++++++---------- .../SerialCallResponse/SerialCallResponse.ino | 14 ++-- .../SerialCallResponseASCII.ino | 46 ++++++----- .../VirtualColorMixer/VirtualColorMixer.ino | 2 +- .../p14_TweakTheArduinoLogo.ino | 3 + 7 files changed, 95 insertions(+), 97 deletions(-) diff --git a/build/shared/examples/04.Communication/Dimmer/Dimmer.ino b/build/shared/examples/04.Communication/Dimmer/Dimmer.ino index 3f2c6fc66..969d3363a 100644 --- a/build/shared/examples/04.Communication/Dimmer/Dimmer.ino +++ b/build/shared/examples/04.Communication/Dimmer/Dimmer.ino @@ -42,7 +42,9 @@ void loop() { } /* Processing code for this example + // Dimmer - sends bytes over a serial port + // by David A. Mellis // This example code is in the public domain. @@ -50,34 +52,35 @@ void loop() { Serial port; void setup() { - size(256, 150); + size(256, 150); - println("Available serial ports:"); - // if using Processing 2.1 or later, use Serial.printArray() - println(Serial.list()); + println("Available serial ports:"); + // if using Processing 2.1 or later, use Serial.printArray() + println(Serial.list()); - // Uses the first port in this list (number 0). Change this to select the port - // corresponding to your Arduino board. The last parameter (e.g. 9600) is the - // speed of the communication. It has to correspond to the value passed to - // Serial.begin() in your Arduino sketch. - port = new Serial(this, Serial.list()[0], 9600); + // Uses the first port in this list (number 0). Change this to select the port + // corresponding to your Arduino board. The last parameter (e.g. 9600) is the + // speed of the communication. It has to correspond to the value passed to + // Serial.begin() in your Arduino sketch. + port = new Serial(this, Serial.list()[0], 9600); - // If you know the name of the port used by the Arduino board, you can specify - // it directly like this. - //port = new Serial(this, "COM1", 9600); + // If you know the name of the port used by the Arduino board, you can specify + // it directly like this. + //port = new Serial(this, "COM1", 9600); } void draw() { - // draw a gradient from black to white - for (int i = 0; i < 256; i++) { - stroke(i); - line(i, 0, i, 150); + // draw a gradient from black to white + for (int i = 0; i < 256; i++) { + stroke(i); + line(i, 0, i, 150); + } + + // write the current X-position of the mouse to the serial port as + // a single byte + port.write(mouseX); } - // write the current X-position of the mouse to the serial port as - // a single byte - port.write(mouseX); - } */ /* Max/MSP v5 patch for this example diff --git a/build/shared/examples/04.Communication/Graph/Graph.ino b/build/shared/examples/04.Communication/Graph/Graph.ino index 4aaf8d689..1fba39cf3 100644 --- a/build/shared/examples/04.Communication/Graph/Graph.ino +++ b/build/shared/examples/04.Communication/Graph/Graph.ino @@ -42,13 +42,12 @@ void loop() { // Graphing sketch - // This program takes ASCII-encoded strings from the serial port at 9600 baud // and graphs them. It expects values in the range 0 to 1023, followed by a // newline, or newline and carriage return - // Created 20 Apr 2005 - // Updated 24 Nov 2015 + // created 20 Apr 2005 + // updated 24 Nov 2015 // by Tom Igoe // This example code is in the public domain. @@ -77,6 +76,7 @@ void loop() { // set initial background: background(0); } + void draw () { // draw the line: stroke(127, 34, 255); @@ -92,7 +92,6 @@ void loop() { } } - void serialEvent (Serial myPort) { // get the ASCII string: String inString = myPort.readStringUntil('\n'); diff --git a/build/shared/examples/04.Communication/PhysicalPixel/PhysicalPixel.ino b/build/shared/examples/04.Communication/PhysicalPixel/PhysicalPixel.ino index 16ee3731d..645bc5dfd 100644 --- a/build/shared/examples/04.Communication/PhysicalPixel/PhysicalPixel.ino +++ b/build/shared/examples/04.Communication/PhysicalPixel/PhysicalPixel.ino @@ -49,7 +49,7 @@ void loop() { /* Processing code for this example - // mouse over serial + // Mouse over serial // 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 if the mouse is not. @@ -60,8 +60,6 @@ void loop() { // by Tom Igoe // This example code is in the public domain. - - import processing.serial.*; float boxX; @@ -72,52 +70,49 @@ void loop() { Serial port; void setup() { - size(200, 200); - boxX = width/2.0; - boxY = height/2.0; - rectMode(RADIUS); + size(200, 200); + boxX = width / 2.0; + boxY = height / 2.0; + rectMode(RADIUS); - // List all the available serial ports in the output pane. - // You will need to choose the port that the Arduino board is connected to - // from this list. The first port in the list is port #0 and the third port - // in the list is port #2. - // if using Processing 2.1 or later, use Serial.printArray() - println(Serial.list()); - - // Open the port that the Arduino board is connected to (in this case #0) - // Make sure to open the port at the same speed Arduino is using (9600bps) - port = new Serial(this, Serial.list()[0], 9600); + // List all the available serial ports in the output pane. + // You will need to choose the port that the Arduino board is connected to + // from this list. The first port in the list is port #0 and the third port + // in the list is port #2. + // if using Processing 2.1 or later, use Serial.printArray() + println(Serial.list()); + // Open the port that the Arduino board is connected to (in this case #0) + // Make sure to open the port at the same speed Arduino is using (9600bps) + port = new Serial(this, Serial.list()[0], 9600); } - void draw() - { - background(0); + void draw() { + background(0); - // Test if the cursor is over the box - if (mouseX > boxX-boxSize && mouseX < boxX+boxSize && - mouseY > boxY-boxSize && mouseY < boxY+boxSize) { - mouseOverBox = true; - // draw a line around the box and change its color: - stroke(255); - fill(153); - // send an 'H' to indicate mouse is over square: - port.write('H'); - } - else { - // return the box to its inactive state: - stroke(153); - fill(153); - // send an 'L' to turn the LED off: - port.write('L'); - mouseOverBox = false; - } + // Test if the cursor is over the box + if (mouseX > boxX - boxSize && mouseX < boxX + boxSize && + mouseY > boxY - boxSize && mouseY < boxY + boxSize) { + mouseOverBox = true; + // draw a line around the box and change its color: + stroke(255); + fill(153); + // send an 'H' to indicate mouse is over square: + port.write('H'); + } + else { + // return the box to its inactive state: + stroke(153); + fill(153); + // send an 'L' to turn the LED off: + port.write('L'); + mouseOverBox = false; + } - // Draw the box - rect(boxX, boxY, boxSize, boxSize); + // Draw the box + rect(boxX, boxY, boxSize, boxSize); } - */ /* diff --git a/build/shared/examples/04.Communication/SerialCallResponse/SerialCallResponse.ino b/build/shared/examples/04.Communication/SerialCallResponse/SerialCallResponse.ino index 6b0aa8336..19ed9bbe4 100644 --- a/build/shared/examples/04.Communication/SerialCallResponse/SerialCallResponse.ino +++ b/build/shared/examples/04.Communication/SerialCallResponse/SerialCallResponse.ino @@ -64,19 +64,18 @@ void establishContact() { } } -/* - Processing sketch to run with this example: +/* Processing sketch to run with this example: // This example code is in the public domain. import processing.serial.*; - int bgcolor; // Background color - int fgcolor; // Fill color + int bgcolor; // Background color + int fgcolor; // Fill color Serial myPort; // The serial port int[] serialInArray = new int[3]; // Where we'll put what we receive int serialCount = 0; // A count of how many bytes we receive - int xpos, ypos; // Starting position of the ball + int xpos, ypos; // Starting position of the ball boolean firstContact = false; // Whether we've heard from the microcontroller void setup() { @@ -84,8 +83,8 @@ void establishContact() { noStroke(); // No border on the next thing drawn // Set the starting position of the ball (middle of the stage) - xpos = width/2; - ypos = height/2; + xpos = width / 2; + ypos = height / 2; // Print a list of the serial ports for debugging purposes // if using Processing 2.1 or later, use Serial.printArray() @@ -140,6 +139,7 @@ void establishContact() { } } } + */ /* diff --git a/build/shared/examples/04.Communication/SerialCallResponseASCII/SerialCallResponseASCII.ino b/build/shared/examples/04.Communication/SerialCallResponseASCII/SerialCallResponseASCII.ino index ef2eac5e6..bb5b87ad0 100644 --- a/build/shared/examples/04.Communication/SerialCallResponseASCII/SerialCallResponseASCII.ino +++ b/build/shared/examples/04.Communication/SerialCallResponseASCII/SerialCallResponseASCII.ino @@ -66,24 +66,22 @@ void establishContact() { } } - -/* - Processing code to run with this example: +/* Processing code to run with this example: // This example code is in the public domain. import processing.serial.*; // import the Processing serial library Serial myPort; // The serial port - float bgcolor; // Background color - float fgcolor; // Fill color - float xpos, ypos; // Starting position of the ball + float bgcolor; // Background color + float fgcolor; // Fill color + float xpos, ypos; // Starting position of the ball void setup() { - size(640,480); + size(640, 480); // List all the available serial ports - // if using Processing 2.1 or later, use Serial.printArray() + // if using Processing 2.1 or later, use Serial.printArray() println(Serial.list()); // I know that the first port in the serial list on my Mac is always my @@ -114,25 +112,25 @@ void establishContact() { // read the serial buffer: String myString = myPort.readStringUntil('\n'); // if you got any bytes other than the linefeed: - myString = trim(myString); + myString = trim(myString); - // split the string at the commas and convert the sections into integers: - int sensors[] = int(split(myString, ',')); + // split the string at the commas and convert the sections into integers: + int sensors[] = int(split(myString, ',')); - // print out the values you got: - for (int sensorNum = 0; sensorNum < sensors.length; sensorNum++) { - print("Sensor " + sensorNum + ": " + sensors[sensorNum] + "\t"); - } - // add a linefeed after all the sensor values are printed: - println(); - if (sensors.length > 1) { - xpos = map(sensors[0], 0,1023,0,width); - ypos = map(sensors[1], 0,1023,0,height); - fgcolor = sensors[2]; - } - // send a byte to ask for more data: - myPort.write("A"); + // print out the values you got: + for (int sensorNum = 0; sensorNum < sensors.length; sensorNum++) { + print("Sensor " + sensorNum + ": " + sensors[sensorNum] + "\t"); } + // add a linefeed after all the sensor values are printed: + println(); + if (sensors.length > 1) { + xpos = map(sensors[0], 0, 1023, 0, width); + ypos = map(sensors[1], 0, 1023, 0, height); + fgcolor = sensors[2]; + } + // send a byte to ask for more data: + myPort.write("A"); + } */ diff --git a/build/shared/examples/04.Communication/VirtualColorMixer/VirtualColorMixer.ino b/build/shared/examples/04.Communication/VirtualColorMixer/VirtualColorMixer.ino index cba36eda2..085f75be3 100644 --- a/build/shared/examples/04.Communication/VirtualColorMixer/VirtualColorMixer.ino +++ b/build/shared/examples/04.Communication/VirtualColorMixer/VirtualColorMixer.ino @@ -76,7 +76,7 @@ void loop() { float[] colors = float(split(inString, ",")); // if the array has at least three elements, you know you got the whole // thing. Put the numbers in the color variables: - if (colors.length >=3) { + if (colors.length >= 3) { // map them to the range 0-255: redValue = map(colors[0], 0, 1023, 0, 255); greenValue = map(colors[1], 0, 1023, 0, 255); diff --git a/build/shared/examples/10.StarterKit_BasicKit/p14_TweakTheArduinoLogo/p14_TweakTheArduinoLogo.ino b/build/shared/examples/10.StarterKit_BasicKit/p14_TweakTheArduinoLogo/p14_TweakTheArduinoLogo.ino index 1b2e0c0dc..e9279e2d6 100644 --- a/build/shared/examples/10.StarterKit_BasicKit/p14_TweakTheArduinoLogo/p14_TweakTheArduinoLogo.ino +++ b/build/shared/examples/10.StarterKit_BasicKit/p14_TweakTheArduinoLogo/p14_TweakTheArduinoLogo.ino @@ -33,7 +33,9 @@ void loop() { } /* Processing code for this example + // Tweak the Arduino Logo + // by Scott Fitzgerald // This example code is in the public domain. @@ -95,4 +97,5 @@ void loop() { // draw the Arduino logo image(logo, 0, 0); } + */