From b7da415d6f1376c2a3b0118bc59eb6911503e1e6 Mon Sep 17 00:00:00 2001 From: Mike Date: Fri, 28 Dec 2012 20:16:42 +0000 Subject: [PATCH 1/9] Fix Debounce example to work as described This alters the debounce example code to toggle the LED rather than just use the button state to set the LED state. Fixes #293 --- .../examples/02.Digital/Debounce/Debounce.ino | 22 +++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/build/shared/examples/02.Digital/Debounce/Debounce.ino b/build/shared/examples/02.Digital/Debounce/Debounce.ino index 89416b269..3ead18503 100644 --- a/build/shared/examples/02.Digital/Debounce/Debounce.ino +++ b/build/shared/examples/02.Digital/Debounce/Debounce.ino @@ -19,6 +19,8 @@ by David A. Mellis modified 30 Aug 2011 by Limor Fried + modified 28 Dec 2012 + by Mike Walters This example code is in the public domain. @@ -43,6 +45,9 @@ long debounceDelay = 50; // the debounce time; increase if the output flicker void setup() { pinMode(buttonPin, INPUT); pinMode(ledPin, OUTPUT); + + // set initial LED state + digitalWrite(ledPin, ledState); } void loop() { @@ -62,12 +67,21 @@ void loop() { if ((millis() - lastDebounceTime) > debounceDelay) { // whatever the reading is at, it's been there for longer // than the debounce delay, so take it as the actual current state: - buttonState = reading; + + // if the button state has changed: + if (reading != buttonState) { + buttonState = reading; + + // only toggle the LED if the new button state is HIGH + if (buttonState == HIGH) { + ledState = !ledState; + + // set the LED: + digitalWrite(ledPin, ledState); + } + } } - // set the LED using the state of the button: - digitalWrite(ledPin, buttonState); - // save the reading. Next time through the loop, // it'll be the lastButtonState: lastButtonState = reading; From c87ddd567df1891a6bbcaaf6c6ae721d3d860b00 Mon Sep 17 00:00:00 2001 From: Fede85 Date: Tue, 16 Apr 2013 16:50:23 +0200 Subject: [PATCH 2/9] small changes to the Debounce example --- .../shared/examples/02.Digital/Debounce/Debounce.ino | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/build/shared/examples/02.Digital/Debounce/Debounce.ino b/build/shared/examples/02.Digital/Debounce/Debounce.ino index 3ead18503..da3aa29d9 100644 --- a/build/shared/examples/02.Digital/Debounce/Debounce.ino +++ b/build/shared/examples/02.Digital/Debounce/Debounce.ino @@ -22,15 +22,15 @@ modified 28 Dec 2012 by Mike Walters -This example code is in the public domain. + This example code is in the public domain. http://www.arduino.cc/en/Tutorial/Debounce */ // constants won't change. They're used here to // set pin numbers: -const int buttonPin = 2; // the number of the pushbutton pin -const int ledPin = 13; // the number of the LED pin +const int buttonPin = 2; // the number of the pushbutton pin +const int ledPin = 13; // the number of the LED pin // Variables will change: int ledState = HIGH; // the current state of the output pin @@ -75,13 +75,13 @@ void loop() { // only toggle the LED if the new button state is HIGH if (buttonState == HIGH) { ledState = !ledState; - - // set the LED: - digitalWrite(ledPin, ledState); } } } + // set the LED: + digitalWrite(ledPin, ledState); + // save the reading. Next time through the loop, // it'll be the lastButtonState: lastButtonState = reading; From ce3554261d5cfef427fb8860f086038b949d5891 Mon Sep 17 00:00:00 2001 From: Fede85 Date: Tue, 16 Apr 2013 21:37:41 +0200 Subject: [PATCH 3/9] Moved refresh client from html meta tag to http header Fixes #953 --- libraries/Ethernet/examples/WebServer/WebServer.ino | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/libraries/Ethernet/examples/WebServer/WebServer.ino b/libraries/Ethernet/examples/WebServer/WebServer.ino index 0573f059d..e5510c326 100644 --- a/libraries/Ethernet/examples/WebServer/WebServer.ino +++ b/libraries/Ethernet/examples/WebServer/WebServer.ino @@ -22,7 +22,7 @@ // The IP address will be dependent on your local network: byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; -IPAddress ip(192,168,1, 177); +IPAddress ip(192,168,1,177); // Initialize the Ethernet server library // with the IP address and port you want to use @@ -64,11 +64,10 @@ void loop() { client.println("HTTP/1.1 200 OK"); client.println("Content-Type: text/html"); client.println("Connection: close"); + client.println("Refresh: 5"); client.println(); client.println(""); client.println(""); - // add a meta refresh tag, so the browser pulls again every 5 seconds: - client.println(""); // output the value of each analog input pin for (int analogChannel = 0; analogChannel < 6; analogChannel++) { int sensorReading = analogRead(analogChannel); From fab4632b07ba9e2b2a21c8e6e56668205636773e Mon Sep 17 00:00:00 2001 From: Fede85 Date: Wed, 17 Apr 2013 11:33:28 +0200 Subject: [PATCH 4/9] WifiWebServer example: Moved the autorefresh feature inside the http header --- .../WiFi/examples/WiFiWebServer/WiFiWebServer.ino | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/libraries/WiFi/examples/WiFiWebServer/WiFiWebServer.ino b/libraries/WiFi/examples/WiFiWebServer/WiFiWebServer.ino index 7d7a24713..de861e880 100644 --- a/libraries/WiFi/examples/WiFiWebServer/WiFiWebServer.ino +++ b/libraries/WiFi/examples/WiFiWebServer/WiFiWebServer.ino @@ -22,7 +22,7 @@ #include -char ssid[] = "yourNetwork"; // your network SSID (name) +char ssid[] = "yourNetwork"; // your network SSID (name) char pass[] = "secretPassword"; // your network password int keyIndex = 0; // your network key Index number (needed only for WEP) @@ -78,12 +78,11 @@ void loop() { // send a standard http response header client.println("HTTP/1.1 200 OK"); client.println("Content-Type: text/html"); - client.println("Connection: close"); + client.println("Connection: close"); // the connection will be closed after completion of the response + client.println("Refresh: 5"); // refresh the page automatically every 5 sec client.println(); client.println(""); client.println(""); - // add a meta refresh tag, so the browser pulls again every 5 seconds: - client.println(""); // output the value of each analog input pin for (int analogChannel = 0; analogChannel < 6; analogChannel++) { int sensorReading = analogRead(analogChannel); @@ -108,9 +107,10 @@ void loop() { } // give the web browser time to receive the data delay(1); - // close the connection: - client.stop(); - Serial.println("client disonnected"); + + // close the connection: + client.stop(); + Serial.println("client disonnected"); } } From a138309ff6cba7daeea949d30124ce3526a1b541 Mon Sep 17 00:00:00 2001 From: Fede85 Date: Wed, 17 Apr 2013 11:37:31 +0200 Subject: [PATCH 5/9] WebServer example: Added comments --- libraries/Ethernet/examples/WebServer/WebServer.ino | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/Ethernet/examples/WebServer/WebServer.ino b/libraries/Ethernet/examples/WebServer/WebServer.ino index e5510c326..5e5d67afa 100644 --- a/libraries/Ethernet/examples/WebServer/WebServer.ino +++ b/libraries/Ethernet/examples/WebServer/WebServer.ino @@ -63,8 +63,8 @@ void loop() { // send a standard http response header client.println("HTTP/1.1 200 OK"); client.println("Content-Type: text/html"); - client.println("Connection: close"); - client.println("Refresh: 5"); + client.println("Connection: close"); // the connection will be closed after completion of the response + client.println("Refresh: 5"); // refresh the page automatically every 5 sec client.println(); client.println(""); client.println(""); From d66930fd6a8057e0d9c678cb5d449708a9062514 Mon Sep 17 00:00:00 2001 From: PaulStoffregen Date: Mon, 22 Apr 2013 04:22:21 -0700 Subject: [PATCH 6/9] Support select-paste on Linux (Paul Stoffregen) --- .../processing/app/syntax/JEditTextArea.java | 35 ++++++++++++++++++- .../processing/app/tools/DiscourseFormat.java | 2 ++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/app/src/processing/app/syntax/JEditTextArea.java b/app/src/processing/app/syntax/JEditTextArea.java index fae0698cc..924eeb7a9 100644 --- a/app/src/processing/app/syntax/JEditTextArea.java +++ b/app/src/processing/app/syntax/JEditTextArea.java @@ -1187,6 +1187,16 @@ public class JEditTextArea extends JComponent selectionEndLine = newEndLine; biasLeft = newBias; + if (newStart != newEnd) { + Clipboard unixclipboard = getToolkit().getSystemSelection(); + if (unixclipboard != null) { + String selection = getSelectedText(); + if (selection != null) { + unixclipboard.setContents(new StringSelection(selection), null); + } + } + } + fireCaretEvent(); } @@ -1649,7 +1659,11 @@ public class JEditTextArea extends JComponent for(int i = 0; i < repeatCount; i++) buf.append(selection); - clipboard.setContents(new StringSelection(buf.toString()),null); + Transferable t = new StringSelection(buf.toString()); + clipboard.setContents(t, null); + + Clipboard unixclipboard = getToolkit().getSystemSelection(); + if (unixclipboard != null) unixclipboard.setContents(t, null); } } @@ -2206,6 +2220,25 @@ public class JEditTextArea extends JComponent return; } + // on Linux, middle button pastes selected text + if ((evt.getModifiers() & InputEvent.BUTTON2_MASK) != 0) { + Clipboard unixclipboard = getToolkit().getSystemSelection(); + if (unixclipboard != null) { + Transferable t = unixclipboard.getContents(null); + if (t != null && t.isDataFlavorSupported(DataFlavor.stringFlavor)) { + try { + String s = (String)t.getTransferData(DataFlavor.stringFlavor); + s = s.replace('\u00A0', ' '); + if (editable) setSelectedText(s); + } catch (Exception e) { + System.err.println(e); + e.printStackTrace(); + } + } + return; + } + } + int line = yToLine(evt.getY()); int offset = xToOffset(line,evt.getX()); int dot = getLineStartOffset(line) + offset; diff --git a/app/src/processing/app/tools/DiscourseFormat.java b/app/src/processing/app/tools/DiscourseFormat.java index 097d7ee2c..5494a9ca3 100644 --- a/app/src/processing/app/tools/DiscourseFormat.java +++ b/app/src/processing/app/tools/DiscourseFormat.java @@ -108,6 +108,8 @@ public class DiscourseFormat { // i don't care about ownership } }); + Clipboard unixclipboard = Toolkit.getDefaultToolkit().getSystemSelection(); + if (unixclipboard != null) unixclipboard.setContents(formatted, null); editor.statusNotice("Code formatted for " + (html ? "HTML" : "the Arduino forum ") + From f9135178d1ce2fa59b09f960247b6ea4236f53d9 Mon Sep 17 00:00:00 2001 From: PaulStoffregen Date: Mon, 22 Apr 2013 14:17:38 -0700 Subject: [PATCH 7/9] Add "Copy To Clipboard" button for compile errors (Paul Stoffregen) --- app/src/processing/app/EditorStatus.java | 36 ++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/app/src/processing/app/EditorStatus.java b/app/src/processing/app/EditorStatus.java index 57b7fba0f..fbcd3fdb1 100644 --- a/app/src/processing/app/EditorStatus.java +++ b/app/src/processing/app/EditorStatus.java @@ -26,6 +26,8 @@ package processing.app; import java.awt.*; import java.awt.event.*; import javax.swing.*; +import java.awt.datatransfer.*; +import static processing.app.I18n._; /** @@ -68,6 +70,7 @@ public class EditorStatus extends JPanel /*implements ActionListener*/ { JButton okButton; JTextField editField; JProgressBar progressBar; + JButton copyErrorButton; //Thread promptThread; int response; @@ -108,6 +111,7 @@ public class EditorStatus extends JPanel /*implements ActionListener*/ { public void notice(String message) { mode = NOTICE; this.message = message; + copyErrorButton.setVisible(false); //update(); repaint(); } @@ -120,6 +124,7 @@ public class EditorStatus extends JPanel /*implements ActionListener*/ { public void error(String message) { mode = ERR; this.message = message; + copyErrorButton.setVisible(true); repaint(); } @@ -177,6 +182,7 @@ public class EditorStatus extends JPanel /*implements ActionListener*/ { this.message = message; progressBar.setIndeterminate(false); progressBar.setVisible(true); + copyErrorButton.setVisible(false); setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); repaint(); } @@ -189,6 +195,7 @@ public class EditorStatus extends JPanel /*implements ActionListener*/ { progressBar.setIndeterminate(true); progressBar.setValue(50); progressBar.setVisible(true); + copyErrorButton.setVisible(false); setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); repaint(); } @@ -207,6 +214,7 @@ public class EditorStatus extends JPanel /*implements ActionListener*/ { if (Preferences.getBoolean("editor.beep.compile")) { Toolkit.getDefaultToolkit().beep(); } + if (progressBar == null) return; progressBar.setVisible(false); progressBar.setValue(0); setCursor(null); @@ -216,6 +224,7 @@ public class EditorStatus extends JPanel /*implements ActionListener*/ { public void progressUpdate(int value) { + if (progressBar == null) return; progressBar.setValue(value); repaint(); } @@ -438,6 +447,29 @@ public class EditorStatus extends JPanel /*implements ActionListener*/ { add(progressBar); progressBar.setVisible(false); + copyErrorButton = new JButton(_("Copy To Clipboard")); + add(copyErrorButton); + //copyErrorButton.setVisible(true); + copyErrorButton.setVisible(false); + System.out.println("create copyErrorButton"); + copyErrorButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + String message=""; + if ((Preferences.getBoolean("build.verbose")) == false) { + message = " " + _("This report would have more information with") + "\n"; + message += " \"" + _("Show verbose output during compilation") + "\"\n"; + message += " " + _("enabled in File > Preferences.") + "\n"; + } + message += _("Arduino: ") + Base.VERSION_NAME + " (" + System.getProperty("os.name") + "), "; + message += _("Board: ") + "\"" + Base.getBoardPreferences().get("name") + "\"\n"; + message += editor.console.consoleTextPane.getText().trim(); + Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); + StringSelection data = new StringSelection(message); + clipboard.setContents(data, null); + Clipboard unixclipboard = Toolkit.getDefaultToolkit().getSystemSelection(); + if (unixclipboard != null) unixclipboard.setContents(data, null); + } + }); } } @@ -470,6 +502,10 @@ public class EditorStatus extends JPanel /*implements ActionListener*/ { editField.setBounds(yesLeft - Preferences.BUTTON_WIDTH, editTop, editWidth, editHeight); progressBar.setBounds(noLeft, editTop, editWidth, editHeight); + + Dimension copyErrorButtonSize = copyErrorButton.getPreferredSize(); + copyErrorButton.setLocation(sizeW - copyErrorButtonSize.width - 5, top); + copyErrorButton.setSize(copyErrorButtonSize.width, Preferences.BUTTON_HEIGHT); } From c111f6611247df8a5c29556dc37df34ec295b3dd Mon Sep 17 00:00:00 2001 From: Fede85 Date: Wed, 24 Apr 2013 10:45:22 +0200 Subject: [PATCH 8/9] Corrected the return type of the digitalPotWrite in the SPI/DigitalPotControl example Fixes #1063 --- .../SPI/examples/DigitalPotControl/DigitalPotControl.ino | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/SPI/examples/DigitalPotControl/DigitalPotControl.ino b/libraries/SPI/examples/DigitalPotControl/DigitalPotControl.ino index ef97dae88..adf93a2c1 100644 --- a/libraries/SPI/examples/DigitalPotControl/DigitalPotControl.ino +++ b/libraries/SPI/examples/DigitalPotControl/DigitalPotControl.ino @@ -60,7 +60,7 @@ void loop() { } -int digitalPotWrite(int address, int value) { +void digitalPotWrite(int address, int value) { // take the SS pin low to select the chip: digitalWrite(slaveSelectPin,LOW); // send in the address and value via SPI: @@ -68,4 +68,4 @@ int digitalPotWrite(int address, int value) { SPI.transfer(value); // take the SS pin high to de-select the chip: digitalWrite(slaveSelectPin,HIGH); -} \ No newline at end of file +} From 0db906f175da33703df4c23de13c1a1e524782d6 Mon Sep 17 00:00:00 2001 From: Fede85 Date: Tue, 30 Apr 2013 17:55:34 +0200 Subject: [PATCH 9/9] changed the pin where to connect the button from 2 to 4 to be compliant with the comment in the header and the tutorial. Fixes #1396 --- .../09.USB/Keyboard/KeyboardMessage/KeyboardMessage.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/shared/examples/09.USB/Keyboard/KeyboardMessage/KeyboardMessage.ino b/build/shared/examples/09.USB/Keyboard/KeyboardMessage/KeyboardMessage.ino index 35d06c6a3..39222fdaa 100644 --- a/build/shared/examples/09.USB/Keyboard/KeyboardMessage/KeyboardMessage.ino +++ b/build/shared/examples/09.USB/Keyboard/KeyboardMessage/KeyboardMessage.ino @@ -18,7 +18,7 @@ http://www.arduino.cc/en/Tutorial/KeyboardButton */ -const int buttonPin = 2; // input pin for pushbutton +const int buttonPin = 4; // input pin for pushbutton int previousButtonState = HIGH; // for checking the state of a pushButton int counter = 0; // button push counter