From a5067567ed639da048a0a85e7e5a419f47850928 Mon Sep 17 00:00:00 2001 From: Federico Fissore Date: Wed, 12 Dec 2012 17:40:26 +0100 Subject: [PATCH 01/11] see #1160 --- app/src/processing/app/Base.java | 13 +++++++++++-- app/src/processing/app/Sketch.java | 2 +- app/src/processing/app/debug/Compiler.java | 10 +++++++--- 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/app/src/processing/app/Base.java b/app/src/processing/app/Base.java index 689c13719..50462befe 100644 --- a/app/src/processing/app/Base.java +++ b/app/src/processing/app/Base.java @@ -1182,8 +1182,13 @@ public class Base { Arrays.sort(list, String.CASE_INSENSITIVE_ORDER); ActionListener listener = new ActionListener() { - public void actionPerformed(ActionEvent e) { - activeEditor.getSketch().importLibrary(e.getActionCommand()); + public void actionPerformed(ActionEvent event) { + String jarPath = event.getActionCommand(); + try { + activeEditor.getSketch().importLibrary(jarPath); + } catch (IOException e) { + showWarning(_("Error"), I18n.format("Unable to list header files in {0}", jarPath), e); + } } }; @@ -1220,11 +1225,15 @@ public class Base { // String packages[] = // Compiler.packageListFromClassPath(libraryClassPath); libraries.add(subfolder); + try { String packages[] = Compiler.headerListFromIncludePath(subfolder.getAbsolutePath()); for (String pkg : packages) { importToLibraryTable.put(pkg, subfolder); } + } catch (IOException e) { + showWarning(_("Error"), I18n.format("Unable to list header files in {0}", subfolder), e); + } JMenuItem item = new JMenuItem(libraryName); item.addActionListener(listener); diff --git a/app/src/processing/app/Sketch.java b/app/src/processing/app/Sketch.java index 5f8a09b5d..dd3bcb2b8 100644 --- a/app/src/processing/app/Sketch.java +++ b/app/src/processing/app/Sketch.java @@ -1128,7 +1128,7 @@ public class Sketch { * Add import statements to the current tab for all of packages inside * the specified jar file. */ - public void importLibrary(String jarPath) { + public void importLibrary(String jarPath) throws IOException { // make sure the user didn't hide the sketch folder ensureExistence(); diff --git a/app/src/processing/app/debug/Compiler.java b/app/src/processing/app/debug/Compiler.java index cf5980610..a715d59a4 100644 --- a/app/src/processing/app/debug/Compiler.java +++ b/app/src/processing/app/debug/Compiler.java @@ -644,14 +644,18 @@ public class Compiler implements MessageConsumer { * not the header files in its sub-folders, as those should be included from * within the header files at the top-level). */ - static public String[] headerListFromIncludePath(String path) { + static public String[] headerListFromIncludePath(String path) throws IOException { FilenameFilter onlyHFiles = new FilenameFilter() { public boolean accept(File dir, String name) { return name.endsWith(".h"); } }; - - return (new File(path)).list(onlyHFiles); + + String[] list = (new File(path)).list(onlyHFiles); + if (list == null) { + throw new IOException(); + } + return list; } static public ArrayList findFilesInPath(String path, String extension, From fd1055cc5a27065404ef1436fa62878d747ae413 Mon Sep 17 00:00:00 2001 From: Tom Igoe Date: Sun, 23 Dec 2012 11:55:59 -0500 Subject: [PATCH 02/11] Updated Esplora examples to match the latest of the Esplora repo --- .../EsploraAccelerometer.ino | 38 ++++++ .../Beginners/EsploraBlink/EsploraBlink.ino | 42 ++++++ .../EsploraJoystickMouse.ino | 50 ++++++++ .../EsploraLedShow/EsploraLedShow.ino | 4 +- .../EsploraLedShow2/EsploraLedShow2.ino | 0 .../EsploraLightCalibrator.ino | 91 +++++++++++++ .../EsploraMusic/EsploraMusic.ino | 5 +- .../EsploraSoundSensor/EsploraSoundSensor.ino | 41 ++++++ .../EsploraTemperatureSensor.ino | 37 ++++++ .../examples/EsploraRemote/EsploraRemote.ino | 94 -------------- .../{ => Experts}/EsploraKart/EsploraKart.ino | 0 .../Experts/EsploraPong/EsploraPong.ino | 22 ++++ .../Experts/EsploraRemote/EsploraRemote.ino | 121 ++++++++++++++++++ .../EsploraTable/EsploraTable.ino | 22 ++-- 14 files changed, 461 insertions(+), 106 deletions(-) create mode 100644 libraries/Esplora/examples/Beginners/EsploraAccelerometer/EsploraAccelerometer.ino create mode 100644 libraries/Esplora/examples/Beginners/EsploraBlink/EsploraBlink.ino create mode 100644 libraries/Esplora/examples/Beginners/EsploraJoystickMouse/EsploraJoystickMouse.ino rename libraries/Esplora/examples/{ => Beginners}/EsploraLedShow/EsploraLedShow.ino (92%) rename libraries/Esplora/examples/{ => Beginners}/EsploraLedShow2/EsploraLedShow2.ino (100%) create mode 100644 libraries/Esplora/examples/Beginners/EsploraLightCalibrator/EsploraLightCalibrator.ino rename libraries/Esplora/examples/{ => Beginners}/EsploraMusic/EsploraMusic.ino (89%) create mode 100644 libraries/Esplora/examples/Beginners/EsploraSoundSensor/EsploraSoundSensor.ino create mode 100644 libraries/Esplora/examples/Beginners/EsploraTemperatureSensor/EsploraTemperatureSensor.ino delete mode 100644 libraries/Esplora/examples/EsploraRemote/EsploraRemote.ino rename libraries/Esplora/examples/{ => Experts}/EsploraKart/EsploraKart.ino (100%) create mode 100644 libraries/Esplora/examples/Experts/EsploraPong/EsploraPong.ino create mode 100644 libraries/Esplora/examples/Experts/EsploraRemote/EsploraRemote.ino rename libraries/Esplora/examples/{ => Experts}/EsploraTable/EsploraTable.ino (87%) diff --git a/libraries/Esplora/examples/Beginners/EsploraAccelerometer/EsploraAccelerometer.ino b/libraries/Esplora/examples/Beginners/EsploraAccelerometer/EsploraAccelerometer.ino new file mode 100644 index 000000000..db5cc93ed --- /dev/null +++ b/libraries/Esplora/examples/Beginners/EsploraAccelerometer/EsploraAccelerometer.ino @@ -0,0 +1,38 @@ +/* + Esplora Accelerometer + + This sketch shows you how to read the values from the accelerometer. + To see it in action, open the serial monitor and tilt the board. You'll see + the accelerometer values for each axis change when you tilt the board + on that axis. + + Created on 22 Dec 2012 + by Tom Igoe + + This example is in the public domain. + */ + +#include + +void setup() +{ + Serial.begin(9600); // initialize serial communications with your computer +} + +void loop() +{ + int xAxis = Esplora.readAccelerometer(X_AXIS); // read the X axis + int yAxis = Esplora.readAccelerometer(Y_AXIS); // read the Y axis + int zAxis = Esplora.readAccelerometer(Z_AXIS); // read the Z axis + + Serial.print("x: "); // print the label for X + Serial.print(xAxis); // print the value for the X axis + Serial.print("\ty: "); // print a tab character, then the label for Y + Serial.print(yAxis); // print the value for the Y axis + Serial.print("\tz: "); // print a tab character, then the label for Z + Serial.println(zAxis); // print the value for the Z axis + + delay(500); // wait half a second (500 milliseconds) +} + + diff --git a/libraries/Esplora/examples/Beginners/EsploraBlink/EsploraBlink.ino b/libraries/Esplora/examples/Beginners/EsploraBlink/EsploraBlink.ino new file mode 100644 index 000000000..e198551a0 --- /dev/null +++ b/libraries/Esplora/examples/Beginners/EsploraBlink/EsploraBlink.ino @@ -0,0 +1,42 @@ + +/* + Esplora Blink + + This sketch blinks the Esplora's RGB LED. It goes through + all three primary colors (red, green, blue), then it + combines them for secondary colors(yellow, cyan, magenta), then + it turns on all the colors for white. + For best results cover the LED with a piece of white paper to see the colors. + + Created on 22 Dec 2012 + by Tom Igoe + + This example is in the public domain. + */ + +#include + + +void setup() { + // There's nothing to set up for this sketch +} + +void loop() { + Esplora.writeRGB(255,0,0); // make the LED red + delay(1000); // wait 1 second + Esplora.writeRGB(0,255,0); // make the LED green + delay(1000); // wait 1 second + Esplora.writeRGB(0,0,255); // make the LED blue + delay(1000); // wait 1 second + Esplora.writeRGB(255,255,0); // make the LED yellow + delay(1000); // wait 1 second + Esplora.writeRGB(0,255,255); // make the LED cyan + delay(1000); // wait 1 second + Esplora.writeRGB(255,0,255); // make the LED magenta + delay(1000); // wait 1 second + Esplora.writeRGB(255,255,255);// make the LED white + delay(1000); // wait 1 second + +} + + diff --git a/libraries/Esplora/examples/Beginners/EsploraJoystickMouse/EsploraJoystickMouse.ino b/libraries/Esplora/examples/Beginners/EsploraJoystickMouse/EsploraJoystickMouse.ino new file mode 100644 index 000000000..8d9260e3c --- /dev/null +++ b/libraries/Esplora/examples/Beginners/EsploraJoystickMouse/EsploraJoystickMouse.ino @@ -0,0 +1,50 @@ +/* + Esplora Joystick Mouse + + This sketch shows you how to read the joystick and use it to control the movement + of the cursor on your computer. You're making your Esplora into a mouse! + + WARNING: this sketch will take over your mouse movement. If you lose control + of your mouse do the following: + 1) unplug the Esplora. + 2) open the EsploraBlink sketch + 3) hold the reset button down while plugging your Esplora back in + 4) while holding reset, click "Upload" + 5) when you see the message "Done compiling", release the reset button. + + This will stop your Esplora from controlling your mouse while you upload a sketch + that doesn't take control of the mouse. + + Created on 22 Dec 2012 + by Tom Igoe + + This example is in the public domain. + */ + +#include + +void setup() +{ + Serial.begin(9600); // initialize serial communication with your computer + Mouse.begin(); // take control of the mouse +} + +void loop() +{ + int xValue = Esplora.readJoystickX(); // read the joystick's X position + int yValue = Esplora.readJoystickY(); // read the joystick's Y position + int button = Esplora.readJoystickSwitch(); // read the joystick pushbutton + Serial.print("Joystick X: "); // print a label for the X value + Serial.print(xValue); // print the X value + Serial.print("\tY: "); // print a tab character and a label for the Y value + Serial.print(yValue); // print the Y value + Serial.print("\tButton: "); // print a tab character and a label for the button + Serial.print(button); // print the button value + + int mouseX = map( xValue,-512, 512, 10, -10); // map the X value to a range of movement for the mouse X + int mouseY = map( yValue,-512, 512, -10, 10); // map the Y value to a range of movement for the mouse Y + Mouse.move(mouseX, mouseY, 0); // move the mouse + + delay(10); // a short delay before moving again +} + diff --git a/libraries/Esplora/examples/EsploraLedShow/EsploraLedShow.ino b/libraries/Esplora/examples/Beginners/EsploraLedShow/EsploraLedShow.ino similarity index 92% rename from libraries/Esplora/examples/EsploraLedShow/EsploraLedShow.ino rename to libraries/Esplora/examples/Beginners/EsploraLedShow/EsploraLedShow.ino index 84f049aac..3c617dcce 100644 --- a/libraries/Esplora/examples/EsploraLedShow/EsploraLedShow.ino +++ b/libraries/Esplora/examples/Beginners/EsploraLedShow/EsploraLedShow.ino @@ -6,7 +6,7 @@ Created on 22 november 2012 By Enrico Gueli - Modified 24 Nov 2012 + Modified 22 Dec 2012 by Tom Igoe */ #include @@ -24,7 +24,7 @@ void loop() { // convert the sensor readings to light levels: byte red = map(xAxis, -512, 512, 0, 255); - byte green = map(xAxis, -512, 512, 0, 255); + byte green = map(yAxis, -512, 512, 0, 255); byte blue = slider/4; // print the light levels: diff --git a/libraries/Esplora/examples/EsploraLedShow2/EsploraLedShow2.ino b/libraries/Esplora/examples/Beginners/EsploraLedShow2/EsploraLedShow2.ino similarity index 100% rename from libraries/Esplora/examples/EsploraLedShow2/EsploraLedShow2.ino rename to libraries/Esplora/examples/Beginners/EsploraLedShow2/EsploraLedShow2.ino diff --git a/libraries/Esplora/examples/Beginners/EsploraLightCalibrator/EsploraLightCalibrator.ino b/libraries/Esplora/examples/Beginners/EsploraLightCalibrator/EsploraLightCalibrator.ino new file mode 100644 index 000000000..c3eaff429 --- /dev/null +++ b/libraries/Esplora/examples/Beginners/EsploraLightCalibrator/EsploraLightCalibrator.ino @@ -0,0 +1,91 @@ +/* + Esplora Led calibration + + This sketch shows you how to read and calibrate the light sensor. + Because light levels vary from one location to another, you need to calibrate the + sensor for each location. To do this, you read the sensor for a few seconds, + and save the highest and lowest readings as maximum and minimum. + Then, when you're using the sensor's reading (for example, to set the brightness + of the LED), you map the sensor's reading to a range between the minimum + and the maximum. + + Created on 22 Dec 2012 + by Tom Igoe + + This example is in the public domain. + */ + +#include + +// variables: +int lightMin = 1023; // minimum sensor value +int lightMax = 0; // maximum sensor value +boolean calibrated = false; // whether the sensor's been calibrated yet + +void setup() { + // initialize the serial communication: + Serial.begin(9600); + + // print an intial message + Serial.println("To calibrate the light sensor, press and hold Switch 1"); +} + +void loop() { + // if switch 1 is pressed, go to the calibration function again: + if (Esplora.readButton(1) == LOW) { + calibrate(); + } + // read the sensor into a variable: + int light = Esplora.readLightSensor(); + + // map the light level to a brightness level for the LED + // using the calibration min and max: + int brightness = map(light, lightMin, lightMax, 0, 255); + // limit the brightness to a range from 0 to 255: + brightness = constrain(brightness, 0, 255); + // write the brightness to the blue LED. + Esplora.writeBlue(brightness); + + // if the calibration's been done, show the sensor and brightness + // levels in the serial monitor: + if (calibrated == true) { + // print the light sensor levels and the LED levels (to see what's going on): + Serial.print("light sensor level: "); + Serial.print(light); + Serial.print(" blue brightness: "); + Serial.println(brightness); + } + // add a delay to keep the LED from flickering: + delay(10); +} + +void calibrate() { + // tell the user what do to using the serial monitor: + Serial.println("While holding switch 1, shine a light on the light sensor, then cover it."); + + // calibrate while switch 1 is pressed: + while(Esplora.readButton(1) == LOW) { + // read the sensor value: + int light = Esplora.readLightSensor(); + + // record the maximum sensor value: + if (light > lightMax) { + lightMax = light; + } + + // record the minimum sensor value: + if (light < lightMin) { + lightMin = light; + } + // note that you're calibrated, for future reference: + calibrated = true; + } +} + + + + + + + + diff --git a/libraries/Esplora/examples/EsploraMusic/EsploraMusic.ino b/libraries/Esplora/examples/Beginners/EsploraMusic/EsploraMusic.ino similarity index 89% rename from libraries/Esplora/examples/EsploraMusic/EsploraMusic.ino rename to libraries/Esplora/examples/Beginners/EsploraMusic/EsploraMusic.ino index 10c17f71c..7a950fb15 100644 --- a/libraries/Esplora/examples/EsploraMusic/EsploraMusic.ino +++ b/libraries/Esplora/examples/Beginners/EsploraMusic/EsploraMusic.ino @@ -6,14 +6,15 @@ Created on 22 november 2012 By Enrico Gueli - modified 24 Nov 2012 + modified 22 Dec 2012 by Tom Igoe */ #include - +// these are the frequencies for the notes from middle C +// to one octave above middle C: const int note[] = { 262, // C 277, // C# diff --git a/libraries/Esplora/examples/Beginners/EsploraSoundSensor/EsploraSoundSensor.ino b/libraries/Esplora/examples/Beginners/EsploraSoundSensor/EsploraSoundSensor.ino new file mode 100644 index 000000000..bc3e81f00 --- /dev/null +++ b/libraries/Esplora/examples/Beginners/EsploraSoundSensor/EsploraSoundSensor.ino @@ -0,0 +1,41 @@ +/* + Esplora Led calibration + + This sketch shows you how to read the microphone sensor. The microphone +will range from 0 (total silence) to 1023 (really loud). + When you're using the sensor's reading (for example, to set the brightness + of the LED), you map the sensor's reading to a range between the minimum + and the maximum. + + Created on 22 Dec 2012 + by Tom Igoe + + This example is in the public domain. + */ + +#include + +void setup() { + // initialize the serial communication: + Serial.begin(9600); +} + +void loop() { + // read the sensor into a variable: + int loudness = Esplora.readMicrophone(); + + // map the sound level to a brightness level for the LED: + int brightness = map(loudness, 0, 1023, 0, 255); + // write the brightness to the green LED: + Esplora.writeGreen(brightness); + + + // print the microphone levels and the LED levels (to see what's going on): + Serial.print("sound level: "); + Serial.print(loudness); + Serial.print(" Green brightness: "); + Serial.println(brightness); + // add a delay to keep the LED from flickering: + delay(10); +} + diff --git a/libraries/Esplora/examples/Beginners/EsploraTemperatureSensor/EsploraTemperatureSensor.ino b/libraries/Esplora/examples/Beginners/EsploraTemperatureSensor/EsploraTemperatureSensor.ino new file mode 100644 index 000000000..72bbf04e0 --- /dev/null +++ b/libraries/Esplora/examples/Beginners/EsploraTemperatureSensor/EsploraTemperatureSensor.ino @@ -0,0 +1,37 @@ +/* + Esplora Temperature Sensor + + This sketch shows you how to read the Esplora's temperature sensor + You can read the temperature sensor in Farhenheit or Celsius. + + Created on 22 Dec 2012 + by Tom Igoe + + This example is in the public domain. + */ +#include + +void setup() +{ + Serial.begin(9600); // initialize serial communications with your computer +} + +void loop() +{ + // read the temperature sensor in Celsius, then Fahrenheit: + int celsius = Esplora.readTemperature(DEGREES_C); + int fahrenheit = Esplora.readTemperature(DEGREES_F); + + // print the results: + Serial.print("Temperature is: "); + Serial.print(celsius); + Serial.print(" degrees Celsius, or "); + Serial.print(fahrenheit); + Serial.println(" degrees Fahrenheit."); + Serial.println(" Fahrenheit = (9/5 * Celsius) + 32"); + + // wait a second before reading again: + delay(1000); +} + + diff --git a/libraries/Esplora/examples/EsploraRemote/EsploraRemote.ino b/libraries/Esplora/examples/EsploraRemote/EsploraRemote.ino deleted file mode 100644 index 135b26a25..000000000 --- a/libraries/Esplora/examples/EsploraRemote/EsploraRemote.ino +++ /dev/null @@ -1,94 +0,0 @@ -/* - Esplora Slave - - This sketch allows to test all the Esplora's peripherals. - It is also used with the ProcessingStart sketch (for Processing). - - When uploaded, you can open the Serial monitor and write one of - the following commands (without quotes) to get an answer: - - "D": prints the current value of all sensors, separated by a comma. - See the dumpInputs() function below to get the meaning of - each value. - - "Rxxx" - "Gxxx" - "Bxxx": set the color of the RGB led. For example, write "R255" - to turn on the red to full brightness, "G128" to turn - the green to half brightness, or "G0" to turn off - the green channel. - - "Txxxx": play a tone with the buzzer. The number is the - frequency, e.g. "T440" plays the central A note. - Write "T0" to turn off the buzzer. - - - Created on 22 november 2012 - By Enrico Gueli -*/ - -#include - -void setup() { - while(!Serial); // needed for Leonardo-based board like Esplora - Serial.begin(9600); -} - -void loop() { - if (Serial.available()) - parseCommand(); -} - -/* - * This function reads a character from the serial line and - * decide what to do next. The "what to do" part is given by - * function it calls (e.g. dumpInputs(), setRed() and so on). - */ -void parseCommand() { - char cmd = Serial.read(); - switch(cmd) { - case 'D': dumpInputs(); break; - case 'R': setRed(); break; - case 'G': setGreen(); break; - case 'B': setBlue(); break; - case 'T': setTone(); break; - } -} - -void dumpInputs() { - /* - * please note: a single row contains two instructions. - * one is to print the sensor value, the other to print the - * comma symbol. - */ - Serial.print(Esplora.readButton(SWITCH_1)); Serial.print(','); - Serial.print(Esplora.readButton(SWITCH_2)); Serial.print(','); - Serial.print(Esplora.readButton(SWITCH_3)); Serial.print(','); - Serial.print(Esplora.readButton(SWITCH_4)); Serial.print(','); - Serial.print(Esplora.readSlider()); Serial.print(','); - Serial.print(Esplora.readLightSensor()); Serial.print(','); - Serial.print(Esplora.readTemperature(DEGREES_C)); Serial.print(','); - Serial.print(Esplora.readMicrophone()); Serial.print(','); - Serial.print(Esplora.readJoystickSwitch()); Serial.print(','); - Serial.print(Esplora.readJoystickX()); Serial.print(','); - Serial.print(Esplora.readJoystickY()); Serial.print(','); - Serial.print(Esplora.readAccelerometer(X_AXIS)); Serial.print(','); - Serial.print(Esplora.readAccelerometer(Y_AXIS)); Serial.print(','); - Serial.print(Esplora.readAccelerometer(Z_AXIS)); Serial.println(); -} - -void setRed() { - Esplora.writeRed(Serial.parseInt()); -} - -void setGreen() { - Esplora.writeGreen(Serial.parseInt()); -} - -void setBlue() { - Esplora.writeBlue(Serial.parseInt()); -} - -void setTone() { - Esplora.tone(Serial.parseInt()); -} diff --git a/libraries/Esplora/examples/EsploraKart/EsploraKart.ino b/libraries/Esplora/examples/Experts/EsploraKart/EsploraKart.ino similarity index 100% rename from libraries/Esplora/examples/EsploraKart/EsploraKart.ino rename to libraries/Esplora/examples/Experts/EsploraKart/EsploraKart.ino diff --git a/libraries/Esplora/examples/Experts/EsploraPong/EsploraPong.ino b/libraries/Esplora/examples/Experts/EsploraPong/EsploraPong.ino new file mode 100644 index 000000000..30f73a792 --- /dev/null +++ b/libraries/Esplora/examples/Experts/EsploraPong/EsploraPong.ino @@ -0,0 +1,22 @@ +#include + +void setup() { + Serial.begin(9600); +} + +void loop() { + int slider = Esplora.readSlider(); + int resetButton = Esplora.readButton(1); + int serveButton = Esplora.readButton(3); + int switchPlayerButton = Esplora.readButton(4); + + Serial.print(slider); + Serial.print(","); + Serial.print(resetButton); + Serial.print(","); + Serial.print(serveButton); + Serial.print(","); + Serial.println(switchPlayerButton); + delay(10); +} + diff --git a/libraries/Esplora/examples/Experts/EsploraRemote/EsploraRemote.ino b/libraries/Esplora/examples/Experts/EsploraRemote/EsploraRemote.ino new file mode 100644 index 000000000..85e5bd718 --- /dev/null +++ b/libraries/Esplora/examples/Experts/EsploraRemote/EsploraRemote.ino @@ -0,0 +1,121 @@ +/* + Esplora Remote + + This sketch allows to test all the Esplora's peripherals. + It is also used with the ProcessingStart sketch (for Processing). + + When uploaded, you can open the Serial monitor and write one of + the following commands (without quotes) to get an answer: + + "D": prints the current value of all sensors, separated by a comma. + See the dumpInputs() function below to get the meaning of + each value. + + "Rxxx" + "Gxxx" + "Bxxx": set the color of the RGB led. For example, write "R255" + to turn on the red to full brightness, "G128" to turn + the green to half brightness, or "G0" to turn off + the green channel. + + "Txxxx": play a tone with the buzzer. The number is the + frequency, e.g. "T440" plays the central A note. + Write "T0" to turn off the buzzer. + + + Created on 22 november 2012 + By Enrico Gueli + Modified 22 Dec 2012 + by Tom Igoe + */ + +#include + +void setup() { + while(!Serial); // needed for Leonardo-based board like Esplora + Serial.begin(9600); +} + +void loop() { + if (Serial.available()) + parseCommand(); +} + +/* + * This function reads a character from the serial line and + * decide what to do next. The "what to do" part is given by + * function it calls (e.g. dumpInputs(), setRed() and so on). + */ +void parseCommand() { + char cmd = Serial.read(); + switch(cmd) { + case 'D': + dumpInputs(); + break; + case 'R': + setRed(); + break; + case 'G': + setGreen(); + break; + case 'B': + setBlue(); + break; + case 'T': + setTone(); + break; + } +} + +void dumpInputs() { + /* + * please note: a single row contains two instructions. + * one is to print the sensor value, the other to print the + * comma symbol. + */ + Serial.print(Esplora.readButton(SWITCH_1)); + Serial.print(','); + Serial.print(Esplora.readButton(SWITCH_2)); + Serial.print(','); + Serial.print(Esplora.readButton(SWITCH_3)); + Serial.print(','); + Serial.print(Esplora.readButton(SWITCH_4)); + Serial.print(','); + Serial.print(Esplora.readSlider()); + Serial.print(','); + Serial.print(Esplora.readLightSensor()); + Serial.print(','); + Serial.print(Esplora.readTemperature(DEGREES_C)); + Serial.print(','); + Serial.print(Esplora.readMicrophone()); + Serial.print(','); + Serial.print(Esplora.readJoystickSwitch()); + Serial.print(','); + Serial.print(Esplora.readJoystickX()); + Serial.print(','); + Serial.print(Esplora.readJoystickY()); + Serial.print(','); + Serial.print(Esplora.readAccelerometer(X_AXIS)); + Serial.print(','); + Serial.print(Esplora.readAccelerometer(Y_AXIS)); + Serial.print(','); + Serial.print(Esplora.readAccelerometer(Z_AXIS)); + Serial.println(); +} + +void setRed() { + Esplora.writeRed(Serial.parseInt()); +} + +void setGreen() { + Esplora.writeGreen(Serial.parseInt()); +} + +void setBlue() { + Esplora.writeBlue(Serial.parseInt()); +} + +void setTone() { + Esplora.tone(Serial.parseInt()); +} + diff --git a/libraries/Esplora/examples/EsploraTable/EsploraTable.ino b/libraries/Esplora/examples/Experts/EsploraTable/EsploraTable.ino similarity index 87% rename from libraries/Esplora/examples/EsploraTable/EsploraTable.ino rename to libraries/Esplora/examples/Experts/EsploraTable/EsploraTable.ino index 712dffa7a..73d56528f 100644 --- a/libraries/Esplora/examples/EsploraTable/EsploraTable.ino +++ b/libraries/Esplora/examples/Experts/EsploraTable/EsploraTable.ino @@ -1,16 +1,17 @@ /* Esplora Table - Acts like a keyboard that prints sensor + Acts like a keyboard that prints some of its sensors' data in a table-like text, row by row. + It is a sort of "data-logger". - At startup, it does nothing. It waits for you to open a - spreadsheet (e.g. Google Drive spreadsheet) so it can write - data. By pressing Switch 1, it starts printing the table + At startup, it does nothing. It just waits for you to open a + spreadsheet (e.g. Google Drive spreadsheet) so it can put its + data. Then, by pressing Switch 1, it starts printing the table headers and the first row of data. It waits a bit, then it will print another row, and so on. - The amount of time between each row is determined by the slider. + The amount of time between each row is given by the slider. If put to full left, the sketch will wait 10 seconds; at full right position, it will wait 5 minutes. An intermediate position will make the sketch wait for some time in-between. @@ -174,12 +175,17 @@ void logAndPrint() { } /** - * Similar to delay(), but allows the program to do something else - * in the meanwhile. In particular, it calls checkSwitchPress(). + * Similar to delay(), but allows to do something else + * in the meanwhile. In particular, it calls waitLoop(). * Note 1: it may wait longer than the specified amount, not less; * Note 2: beware of data synchronization issues, e.g. if the - * activeDelay() function alters some variables used by the + * whileWaiting() function alters some variables used by the * caller of this function. + * + * I discovered by chance that there's an ongoing discussion about + * adding yield() in the Arduino API: + * http://comments.gmane.org/gmane.comp.hardware.arduino.devel/1381 + * The purpose is the same, but for now I'm using this implementation. */ void activeDelay(unsigned long amount) { unsigned long at = millis() + amount; From 7e5ca6244baefbdadaf16b735ff5624d979e3d21 Mon Sep 17 00:00:00 2001 From: Scott Fitzgerald Date: Sun, 23 Dec 2012 11:55:16 -0700 Subject: [PATCH 03/11] Small change to EsploraLightCalibrator example Chnaged LOW to HIGH --- .../EsploraLightCalibrator/EsploraLightCalibrator.ino | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/Esplora/examples/Beginners/EsploraLightCalibrator/EsploraLightCalibrator.ino b/libraries/Esplora/examples/Beginners/EsploraLightCalibrator/EsploraLightCalibrator.ino index c3eaff429..37469c05d 100644 --- a/libraries/Esplora/examples/Beginners/EsploraLightCalibrator/EsploraLightCalibrator.ino +++ b/libraries/Esplora/examples/Beginners/EsploraLightCalibrator/EsploraLightCalibrator.ino @@ -32,7 +32,7 @@ void setup() { void loop() { // if switch 1 is pressed, go to the calibration function again: - if (Esplora.readButton(1) == LOW) { + if (Esplora.readButton(1) == HIGH) { calibrate(); } // read the sensor into a variable: @@ -64,7 +64,7 @@ void calibrate() { Serial.println("While holding switch 1, shine a light on the light sensor, then cover it."); // calibrate while switch 1 is pressed: - while(Esplora.readButton(1) == LOW) { + while(Esplora.readButton(1) == HIGH) { // read the sensor value: int light = Esplora.readLightSensor(); From 7289ac61495f064e14ae2439e5edae59701f5ae1 Mon Sep 17 00:00:00 2001 From: Scott Fitzgerald Date: Sun, 23 Dec 2012 11:57:46 -0700 Subject: [PATCH 04/11] Minor changes to EsploraTable example --- .../Experts/EsploraTable/EsploraTable.ino | 22 +++++++------------ 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/libraries/Esplora/examples/Experts/EsploraTable/EsploraTable.ino b/libraries/Esplora/examples/Experts/EsploraTable/EsploraTable.ino index 73d56528f..712dffa7a 100644 --- a/libraries/Esplora/examples/Experts/EsploraTable/EsploraTable.ino +++ b/libraries/Esplora/examples/Experts/EsploraTable/EsploraTable.ino @@ -1,17 +1,16 @@ /* Esplora Table - Acts like a keyboard that prints some of its sensors' + Acts like a keyboard that prints sensor data in a table-like text, row by row. - It is a sort of "data-logger". - At startup, it does nothing. It just waits for you to open a - spreadsheet (e.g. Google Drive spreadsheet) so it can put its - data. Then, by pressing Switch 1, it starts printing the table + At startup, it does nothing. It waits for you to open a + spreadsheet (e.g. Google Drive spreadsheet) so it can write + data. By pressing Switch 1, it starts printing the table headers and the first row of data. It waits a bit, then it will print another row, and so on. - The amount of time between each row is given by the slider. + The amount of time between each row is determined by the slider. If put to full left, the sketch will wait 10 seconds; at full right position, it will wait 5 minutes. An intermediate position will make the sketch wait for some time in-between. @@ -175,17 +174,12 @@ void logAndPrint() { } /** - * Similar to delay(), but allows to do something else - * in the meanwhile. In particular, it calls waitLoop(). + * Similar to delay(), but allows the program to do something else + * in the meanwhile. In particular, it calls checkSwitchPress(). * Note 1: it may wait longer than the specified amount, not less; * Note 2: beware of data synchronization issues, e.g. if the - * whileWaiting() function alters some variables used by the + * activeDelay() function alters some variables used by the * caller of this function. - * - * I discovered by chance that there's an ongoing discussion about - * adding yield() in the Arduino API: - * http://comments.gmane.org/gmane.comp.hardware.arduino.devel/1381 - * The purpose is the same, but for now I'm using this implementation. */ void activeDelay(unsigned long amount) { unsigned long at = millis() + amount; From 957d7d480f6ae238923524427c2e2a04a45a7468 Mon Sep 17 00:00:00 2001 From: Tom Igoe Date: Sun, 23 Dec 2012 20:29:43 -0500 Subject: [PATCH 05/11] Revert "Small change to EsploraLightCalibrator example" This reverts commit 7e5ca6244baefbdadaf16b735ff5624d979e3d21. --- .../EsploraLightCalibrator/EsploraLightCalibrator.ino | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/Esplora/examples/Beginners/EsploraLightCalibrator/EsploraLightCalibrator.ino b/libraries/Esplora/examples/Beginners/EsploraLightCalibrator/EsploraLightCalibrator.ino index 37469c05d..c3eaff429 100644 --- a/libraries/Esplora/examples/Beginners/EsploraLightCalibrator/EsploraLightCalibrator.ino +++ b/libraries/Esplora/examples/Beginners/EsploraLightCalibrator/EsploraLightCalibrator.ino @@ -32,7 +32,7 @@ void setup() { void loop() { // if switch 1 is pressed, go to the calibration function again: - if (Esplora.readButton(1) == HIGH) { + if (Esplora.readButton(1) == LOW) { calibrate(); } // read the sensor into a variable: @@ -64,7 +64,7 @@ void calibrate() { Serial.println("While holding switch 1, shine a light on the light sensor, then cover it."); // calibrate while switch 1 is pressed: - while(Esplora.readButton(1) == HIGH) { + while(Esplora.readButton(1) == LOW) { // read the sensor value: int light = Esplora.readLightSensor(); From 5a644dffe0ac70cb65f6219aed33b82e3128bbc5 Mon Sep 17 00:00:00 2001 From: Tom Igoe Date: Sun, 23 Dec 2012 21:33:39 -0500 Subject: [PATCH 06/11] Minor change to EsploraRemote example --- .../examples/Experts/EsploraRemote/EsploraRemote.ino | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/libraries/Esplora/examples/Experts/EsploraRemote/EsploraRemote.ino b/libraries/Esplora/examples/Experts/EsploraRemote/EsploraRemote.ino index 85e5bd718..27010897b 100644 --- a/libraries/Esplora/examples/Experts/EsploraRemote/EsploraRemote.ino +++ b/libraries/Esplora/examples/Experts/EsploraRemote/EsploraRemote.ino @@ -25,7 +25,7 @@ Created on 22 november 2012 By Enrico Gueli - Modified 22 Dec 2012 + Modified 23 Dec 2012 by Tom Igoe */ @@ -68,11 +68,6 @@ void parseCommand() { } void dumpInputs() { - /* - * please note: a single row contains two instructions. - * one is to print the sensor value, the other to print the - * comma symbol. - */ Serial.print(Esplora.readButton(SWITCH_1)); Serial.print(','); Serial.print(Esplora.readButton(SWITCH_2)); From fbd488e07edbbc8e83bfc9744bde09e1ea72dace Mon Sep 17 00:00:00 2001 From: Tom Igoe Date: Sun, 23 Dec 2012 21:49:09 -0500 Subject: [PATCH 07/11] Added header comments to EsploraPong --- .../Experts/EsploraPong/EsploraPong.ino | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/libraries/Esplora/examples/Experts/EsploraPong/EsploraPong.ino b/libraries/Esplora/examples/Experts/EsploraPong/EsploraPong.ino index 30f73a792..b52e49b71 100644 --- a/libraries/Esplora/examples/Experts/EsploraPong/EsploraPong.ino +++ b/libraries/Esplora/examples/Experts/EsploraPong/EsploraPong.ino @@ -1,3 +1,24 @@ +/* + Esplora Pong + + This sketch connects serially to a Processing sketch to control a Pong game. + It sends the position of the slider and the states of three pushbuttons to the + Processing sketch serially, separated by commas. The Processing sketch uses that + data to control the graphics in the sketch. + + The slider sets a paddle's height + Switch 1 is resets the game + Switch 2 resets the ball to the center + Switch 3 reverses the players + + You can play this game with one or two Esploras. + + Created on 22 Dec 2012 + by Tom Igoe + + This example is in the public domain. + */ + #include void setup() { From fb87c81cb0cb19da8e15e8bdff70a1910b8d4fd9 Mon Sep 17 00:00:00 2001 From: Tom Igoe Date: Sun, 23 Dec 2012 22:10:07 -0500 Subject: [PATCH 08/11] Added comments for EsploraPong --- .../Experts/EsploraPong/EsploraPong.ino | 25 ++++++++++--------- 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/libraries/Esplora/examples/Experts/EsploraPong/EsploraPong.ino b/libraries/Esplora/examples/Experts/EsploraPong/EsploraPong.ino index b52e49b71..725a109f3 100644 --- a/libraries/Esplora/examples/Experts/EsploraPong/EsploraPong.ino +++ b/libraries/Esplora/examples/Experts/EsploraPong/EsploraPong.ino @@ -22,22 +22,23 @@ #include void setup() { - Serial.begin(9600); + Serial.begin(9600); // initialize serial communication } void loop() { + // read the slider and three of the buttons int slider = Esplora.readSlider(); - int resetButton = Esplora.readButton(1); - int serveButton = Esplora.readButton(3); - int switchPlayerButton = Esplora.readButton(4); + int resetButton = Esplora.readButton(SWITCH_1); + int serveButton = Esplora.readButton(SWITCH_3); + int switchPlayerButton = Esplora.readButton(SWITCH_4); - Serial.print(slider); - Serial.print(","); - Serial.print(resetButton); - Serial.print(","); - Serial.print(serveButton); - Serial.print(","); - Serial.println(switchPlayerButton); - delay(10); + Serial.print(slider); // print the slider value + Serial.print(","); // add a comma + Serial.print(resetButton); // print the reset button value + Serial.print(","); // add another comma + Serial.print(serveButton); // print the serve button value + Serial.print(","); // add another comma + Serial.println(switchPlayerButton); // print the last button with a newline + delay(10); // delay before sending the next set } From d7d78ff6a5bfede76bca655900e66a1b0393f925 Mon Sep 17 00:00:00 2001 From: Tom Igoe Date: Sun, 23 Dec 2012 22:22:37 -0500 Subject: [PATCH 09/11] Updated title in comments of Esplora Sound Sensor example --- .../Beginners/EsploraSoundSensor/EsploraSoundSensor.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/Esplora/examples/Beginners/EsploraSoundSensor/EsploraSoundSensor.ino b/libraries/Esplora/examples/Beginners/EsploraSoundSensor/EsploraSoundSensor.ino index bc3e81f00..3bf454fed 100644 --- a/libraries/Esplora/examples/Beginners/EsploraSoundSensor/EsploraSoundSensor.ino +++ b/libraries/Esplora/examples/Beginners/EsploraSoundSensor/EsploraSoundSensor.ino @@ -1,5 +1,5 @@ /* - Esplora Led calibration + Esplora Sound Sensor This sketch shows you how to read the microphone sensor. The microphone will range from 0 (total silence) to 1023 (really loud). From d8e5997328b76c570c1803baef4c5399783fded0 Mon Sep 17 00:00:00 2001 From: Tom Igoe Date: Sun, 23 Dec 2012 23:05:29 -0500 Subject: [PATCH 10/11] Added Esplora readJoystickButton function to be consistent with Esplora readButton --- libraries/Esplora/Esplora.cpp | 9 +++++++++ libraries/Esplora/Esplora.h | 4 +++- libraries/Esplora/keywords.txt | 1 + 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/libraries/Esplora/Esplora.cpp b/libraries/Esplora/Esplora.cpp index 83df0d7dd..29c9e191a 100644 --- a/libraries/Esplora/Esplora.cpp +++ b/libraries/Esplora/Esplora.cpp @@ -111,6 +111,15 @@ boolean _Esplora::readButton(byte ch) { return (val > 512) ? HIGH : LOW; } +boolean _Esplora::readJoystickButton() { + if (readChannel(CH_JOYSTICK_SW) == 1023) { + return HIGH; + } else if (readChannel(CH_JOYSTICK_SW) == 0) { + return LOW; + } +} + + void _Esplora::writeRGB(byte r, byte g, byte b) { writeRed(r); writeGreen(g); diff --git a/libraries/Esplora/Esplora.h b/libraries/Esplora/Esplora.h index 74fa88b2b..4f5534552 100644 --- a/libraries/Esplora/Esplora.h +++ b/libraries/Esplora/Esplora.h @@ -21,7 +21,7 @@ #ifndef ESPLORA_H_ #define ESPLORA_H_ -#include "Arduino.h" +#include /* * The following constants are used internally by the Esplora @@ -141,6 +141,8 @@ public: * LOW if the button is pressed, and HIGH otherwise. */ boolean readButton(byte channel); + + boolean readJoystickButton(); void writeRGB(byte red, byte green, byte blue); void writeRed(byte red); diff --git a/libraries/Esplora/keywords.txt b/libraries/Esplora/keywords.txt index 02ba6607c..b225991f6 100644 --- a/libraries/Esplora/keywords.txt +++ b/libraries/Esplora/keywords.txt @@ -16,6 +16,7 @@ readLightSensor KEYWORD2 readTemperature KEYWORD2 readMicrophone KEYWORD2 readJoystickSwitch KEYWORD2 +readJoystickButton KEYWORD2 readJoystickX KEYWORD2 readJoystickY KEYWORD2 readAccelerometer KEYWORD2 From 169032465a0ca9944562d9b08b32434c637c0d78 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Sun, 6 Jan 2013 18:09:42 +0100 Subject: [PATCH 11/11] Updated revisions log --- build/shared/revisions.txt | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/build/shared/revisions.txt b/build/shared/revisions.txt index 115863f67..8fe6948cf 100644 --- a/build/shared/revisions.txt +++ b/build/shared/revisions.txt @@ -1,4 +1,20 @@ +[core] + +* Fixed malloc bug (Paul Stoffregen) + +[libraries] + +* Fixed memory leak when calling Ethernet.begin() multiple times. +* Fixed SD example listfiles.ino +* Fixed a lot of Esplora examples + +[environment] + +* Sort entries in preferences.txt (Shigeru Kanemoto) +* Fixed some wrong translations +* Fixed NPE due to permissions IO error + ARDUINO 1.0.3 - 2012.12.10 [hardware]