aboutsummaryrefslogtreecommitdiff
path: root/libraries/Esplora/Beginners
diff options
context:
space:
mode:
authorCristian Maglie <c.maglie@bug.st>2013-01-27 12:52:06 +0100
committerCristian Maglie <c.maglie@bug.st>2013-01-27 12:52:06 +0100
commit76d436f51501bd47ff463b88a196f517191f58ad (patch)
tree1f22ba2385ad22eca306d67793c0827451f2b50a /libraries/Esplora/Beginners
parentbb9cc4f70c17eed497ab30d7bfe6eebb35055205 (diff)
parentc6287dd6ac33544179a6544b8f3f55a396ec6608 (diff)
Merge branch 'ide-1.5.x' into can
Diffstat (limited to 'libraries/Esplora/Beginners')
-rw-r--r--libraries/Esplora/Beginners/EsploraAccelerometer/EsploraAccelerometer.ino38
-rw-r--r--libraries/Esplora/Beginners/EsploraBlink/EsploraBlink.ino42
-rw-r--r--libraries/Esplora/Beginners/EsploraJoystickMouse/EsploraJoystickMouse.ino50
-rw-r--r--libraries/Esplora/Beginners/EsploraLedShow/EsploraLedShow.ino42
-rw-r--r--libraries/Esplora/Beginners/EsploraLedShow2/EsploraLedShow2.ino55
-rw-r--r--libraries/Esplora/Beginners/EsploraLightCalibrator/EsploraLightCalibrator.ino91
-rw-r--r--libraries/Esplora/Beginners/EsploraMusic/EsploraMusic.ino53
-rw-r--r--libraries/Esplora/Beginners/EsploraSoundSensor/EsploraSoundSensor.ino41
-rw-r--r--libraries/Esplora/Beginners/EsploraTemperatureSensor/EsploraTemperatureSensor.ino37
9 files changed, 449 insertions, 0 deletions
diff --git a/libraries/Esplora/Beginners/EsploraAccelerometer/EsploraAccelerometer.ino b/libraries/Esplora/Beginners/EsploraAccelerometer/EsploraAccelerometer.ino
new file mode 100644
index 0000000..db5cc93
--- /dev/null
+++ b/libraries/Esplora/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 <Esplora.h>
+
+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/Beginners/EsploraBlink/EsploraBlink.ino b/libraries/Esplora/Beginners/EsploraBlink/EsploraBlink.ino
new file mode 100644
index 0000000..e198551
--- /dev/null
+++ b/libraries/Esplora/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 <Esplora.h>
+
+
+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/Beginners/EsploraJoystickMouse/EsploraJoystickMouse.ino b/libraries/Esplora/Beginners/EsploraJoystickMouse/EsploraJoystickMouse.ino
new file mode 100644
index 0000000..8d9260e
--- /dev/null
+++ b/libraries/Esplora/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 <Esplora.h>
+
+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/Beginners/EsploraLedShow/EsploraLedShow.ino b/libraries/Esplora/Beginners/EsploraLedShow/EsploraLedShow.ino
new file mode 100644
index 0000000..3c617dc
--- /dev/null
+++ b/libraries/Esplora/Beginners/EsploraLedShow/EsploraLedShow.ino
@@ -0,0 +1,42 @@
+/*
+ Esplora LED Show
+
+ Makes the RGB LED bright and glow as the joystick or the
+ slider are moved.
+
+ Created on 22 november 2012
+ By Enrico Gueli <enrico.gueli@gmail.com>
+ Modified 22 Dec 2012
+ by Tom Igoe
+*/
+#include <Esplora.h>
+
+void setup() {
+ // initialize the serial communication:
+ Serial.begin(9600);
+}
+
+void loop() {
+ // read the sensors into variables:
+ int xAxis = Esplora.readJoystickX();
+ int yAxis = Esplora.readJoystickY();
+ int slider = Esplora.readSlider();
+
+ // convert the sensor readings to light levels:
+ byte red = map(xAxis, -512, 512, 0, 255);
+ byte green = map(yAxis, -512, 512, 0, 255);
+ byte blue = slider/4;
+
+ // print the light levels:
+ Serial.print(red);
+ Serial.print(' ');
+ Serial.print(green);
+ Serial.print(' ');
+ Serial.println(blue);
+
+ // write the light levels to the LED.
+ Esplora.writeRGB(red, green, blue);
+
+ // add a delay to keep the LED from flickering:
+ delay(10);
+}
diff --git a/libraries/Esplora/Beginners/EsploraLedShow2/EsploraLedShow2.ino b/libraries/Esplora/Beginners/EsploraLedShow2/EsploraLedShow2.ino
new file mode 100644
index 0000000..8f9f8a2
--- /dev/null
+++ b/libraries/Esplora/Beginners/EsploraLedShow2/EsploraLedShow2.ino
@@ -0,0 +1,55 @@
+/*
+ Esplora Led/Microphone
+
+ This simple sketch reads the microphone, light sensor, and slider.
+ Then it uses those readings to set the brightness of red, green and blue
+ channels of the RGB LED. The red channel will change with the loudness
+ "heared" by the microphone, the green channel changes as the
+ amount of light in the room and the blue channel will change
+ with the position of the slider.
+
+ Created on 22 november 2012
+ By Enrico Gueli <enrico.gueli@gmail.com>
+ Modified 24 Nov 2012
+ by Tom Igoe
+*/
+
+#include <Esplora.h>
+
+void setup() {
+ // initialize the serial communication:
+ Serial.begin(9600);
+}
+
+int lowLight = 400; // the light sensor reading when it's covered
+int highLight = 1023; // the maximum light sensor reading
+int minGreen = 0; // minimum brightness of the green LED
+int maxGreen = 100; // maximum brightness of the green LED
+
+void loop() {
+ // read the sensors into variables:
+ int mic = Esplora.readMicrophone();
+ int light = Esplora.readLightSensor();
+ int slider = Esplora.readSlider();
+
+ // convert the sensor readings to light levels:
+ byte red = constrain(mic, 0, 255);
+ byte green = constrain(
+ map(light, lowLight, highLight, minGreen, maxGreen),
+ 0, 255);
+ byte blue = slider/4;
+
+ // print the light levels (to see what's going on):
+ Serial.print(red);
+ Serial.print(' ');
+ Serial.print(green);
+ Serial.print(' ');
+ Serial.println(blue);
+
+ // write the light levels to the LED.
+ // note that the green value is always 0:
+ Esplora.writeRGB(red, green, blue);
+
+ // add a delay to keep the LED from flickering:
+ delay(10);
+}
diff --git a/libraries/Esplora/Beginners/EsploraLightCalibrator/EsploraLightCalibrator.ino b/libraries/Esplora/Beginners/EsploraLightCalibrator/EsploraLightCalibrator.ino
new file mode 100644
index 0000000..c3eaff4
--- /dev/null
+++ b/libraries/Esplora/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 <Esplora.h>
+
+// 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/Beginners/EsploraMusic/EsploraMusic.ino b/libraries/Esplora/Beginners/EsploraMusic/EsploraMusic.ino
new file mode 100644
index 0000000..7a950fb
--- /dev/null
+++ b/libraries/Esplora/Beginners/EsploraMusic/EsploraMusic.ino
@@ -0,0 +1,53 @@
+/*
+ Esplora Music
+
+ This sketch turns the Esplora in a simple musical instrument.
+ Press the Switch 1 and move the slider to see how it works.
+
+ Created on 22 november 2012
+ By Enrico Gueli <enrico.gueli@gmail.com>
+ modified 22 Dec 2012
+ by Tom Igoe
+*/
+
+
+#include <Esplora.h>
+
+// these are the frequencies for the notes from middle C
+// to one octave above middle C:
+const int note[] = {
+262, // C
+277, // C#
+294, // D
+311, // D#
+330, // E
+349, // F
+370, // F#
+392, // G
+415, // G#
+440, // A
+466, // A#
+494, // B
+523 // C next octave
+};
+
+void setup() {
+}
+
+void loop() {
+ // read the button labeled SWITCH_DOWN. If it's low,
+ // then play a note:
+ if (Esplora.readButton(SWITCH_DOWN) == LOW) {
+ int slider = Esplora.readSlider();
+
+ // use map() to map the slider's range to the
+ // range of notes you have:
+ byte thisNote = map(slider, 0, 1023, 0, 13);
+ // play the note corresponding to the slider's position:
+ Esplora.tone(note[thisNote]);
+ }
+ else {
+ // if the button isn't pressed, turn the note off:
+ Esplora.noTone();
+ }
+}
diff --git a/libraries/Esplora/Beginners/EsploraSoundSensor/EsploraSoundSensor.ino b/libraries/Esplora/Beginners/EsploraSoundSensor/EsploraSoundSensor.ino
new file mode 100644
index 0000000..3bf454f
--- /dev/null
+++ b/libraries/Esplora/Beginners/EsploraSoundSensor/EsploraSoundSensor.ino
@@ -0,0 +1,41 @@
+/*
+ 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).
+ 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 <Esplora.h>
+
+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/Beginners/EsploraTemperatureSensor/EsploraTemperatureSensor.ino b/libraries/Esplora/Beginners/EsploraTemperatureSensor/EsploraTemperatureSensor.ino
new file mode 100644
index 0000000..72bbf04
--- /dev/null
+++ b/libraries/Esplora/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 <Esplora.h>
+
+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);
+}
+
+