Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit fd1055c

Browse filesBrowse files
committed
Updated Esplora examples to match the latest of the Esplora repo
1 parent 9ef43ac commit fd1055c
Copy full SHA for fd1055c

File tree

Expand file treeCollapse file tree

14 files changed

+461
-106
lines changed
Filter options
Expand file treeCollapse file tree

14 files changed

+461
-106
lines changed
+38Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
Esplora Accelerometer
3+
4+
This sketch shows you how to read the values from the accelerometer.
5+
To see it in action, open the serial monitor and tilt the board. You'll see
6+
the accelerometer values for each axis change when you tilt the board
7+
on that axis.
8+
9+
Created on 22 Dec 2012
10+
by Tom Igoe
11+
12+
This example is in the public domain.
13+
*/
14+
15+
#include <Esplora.h>
16+
17+
void setup()
18+
{
19+
Serial.begin(9600); // initialize serial communications with your computer
20+
}
21+
22+
void loop()
23+
{
24+
int xAxis = Esplora.readAccelerometer(X_AXIS); // read the X axis
25+
int yAxis = Esplora.readAccelerometer(Y_AXIS); // read the Y axis
26+
int zAxis = Esplora.readAccelerometer(Z_AXIS); // read the Z axis
27+
28+
Serial.print("x: "); // print the label for X
29+
Serial.print(xAxis); // print the value for the X axis
30+
Serial.print("\ty: "); // print a tab character, then the label for Y
31+
Serial.print(yAxis); // print the value for the Y axis
32+
Serial.print("\tz: "); // print a tab character, then the label for Z
33+
Serial.println(zAxis); // print the value for the Z axis
34+
35+
delay(500); // wait half a second (500 milliseconds)
36+
}
37+
38+
+42Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
2+
/*
3+
Esplora Blink
4+
5+
This sketch blinks the Esplora's RGB LED. It goes through
6+
all three primary colors (red, green, blue), then it
7+
combines them for secondary colors(yellow, cyan, magenta), then
8+
it turns on all the colors for white.
9+
For best results cover the LED with a piece of white paper to see the colors.
10+
11+
Created on 22 Dec 2012
12+
by Tom Igoe
13+
14+
This example is in the public domain.
15+
*/
16+
17+
#include <Esplora.h>
18+
19+
20+
void setup() {
21+
// There's nothing to set up for this sketch
22+
}
23+
24+
void loop() {
25+
Esplora.writeRGB(255,0,0); // make the LED red
26+
delay(1000); // wait 1 second
27+
Esplora.writeRGB(0,255,0); // make the LED green
28+
delay(1000); // wait 1 second
29+
Esplora.writeRGB(0,0,255); // make the LED blue
30+
delay(1000); // wait 1 second
31+
Esplora.writeRGB(255,255,0); // make the LED yellow
32+
delay(1000); // wait 1 second
33+
Esplora.writeRGB(0,255,255); // make the LED cyan
34+
delay(1000); // wait 1 second
35+
Esplora.writeRGB(255,0,255); // make the LED magenta
36+
delay(1000); // wait 1 second
37+
Esplora.writeRGB(255,255,255);// make the LED white
38+
delay(1000); // wait 1 second
39+
40+
}
41+
42+
+50Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
Esplora Joystick Mouse
3+
4+
This sketch shows you how to read the joystick and use it to control the movement
5+
of the cursor on your computer. You're making your Esplora into a mouse!
6+
7+
WARNING: this sketch will take over your mouse movement. If you lose control
8+
of your mouse do the following:
9+
1) unplug the Esplora.
10+
2) open the EsploraBlink sketch
11+
3) hold the reset button down while plugging your Esplora back in
12+
4) while holding reset, click "Upload"
13+
5) when you see the message "Done compiling", release the reset button.
14+
15+
This will stop your Esplora from controlling your mouse while you upload a sketch
16+
that doesn't take control of the mouse.
17+
18+
Created on 22 Dec 2012
19+
by Tom Igoe
20+
21+
This example is in the public domain.
22+
*/
23+
24+
#include <Esplora.h>
25+
26+
void setup()
27+
{
28+
Serial.begin(9600); // initialize serial communication with your computer
29+
Mouse.begin(); // take control of the mouse
30+
}
31+
32+
void loop()
33+
{
34+
int xValue = Esplora.readJoystickX(); // read the joystick's X position
35+
int yValue = Esplora.readJoystickY(); // read the joystick's Y position
36+
int button = Esplora.readJoystickSwitch(); // read the joystick pushbutton
37+
Serial.print("Joystick X: "); // print a label for the X value
38+
Serial.print(xValue); // print the X value
39+
Serial.print("\tY: "); // print a tab character and a label for the Y value
40+
Serial.print(yValue); // print the Y value
41+
Serial.print("\tButton: "); // print a tab character and a label for the button
42+
Serial.print(button); // print the button value
43+
44+
int mouseX = map( xValue,-512, 512, 10, -10); // map the X value to a range of movement for the mouse X
45+
int mouseY = map( yValue,-512, 512, -10, 10); // map the Y value to a range of movement for the mouse Y
46+
Mouse.move(mouseX, mouseY, 0); // move the mouse
47+
48+
delay(10); // a short delay before moving again
49+
}
50+

‎libraries/Esplora/examples/EsploraLedShow/EsploraLedShow.ino renamed to ‎libraries/Esplora/examples/Beginners/EsploraLedShow/EsploraLedShow.ino

Copy file name to clipboardExpand all lines: libraries/Esplora/examples/Beginners/EsploraLedShow/EsploraLedShow.ino
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
77
Created on 22 november 2012
88
By Enrico Gueli <enrico.gueli@gmail.com>
9-
Modified 24 Nov 2012
9+
Modified 22 Dec 2012
1010
by Tom Igoe
1111
*/
1212
#include <Esplora.h>
@@ -24,7 +24,7 @@ void loop() {
2424

2525
// convert the sensor readings to light levels:
2626
byte red = map(xAxis, -512, 512, 0, 255);
27-
byte green = map(xAxis, -512, 512, 0, 255);
27+
byte green = map(yAxis, -512, 512, 0, 255);
2828
byte blue = slider/4;
2929

3030
// print the light levels:
+91Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
/*
2+
Esplora Led calibration
3+
4+
This sketch shows you how to read and calibrate the light sensor.
5+
Because light levels vary from one location to another, you need to calibrate the
6+
sensor for each location. To do this, you read the sensor for a few seconds,
7+
and save the highest and lowest readings as maximum and minimum.
8+
Then, when you're using the sensor's reading (for example, to set the brightness
9+
of the LED), you map the sensor's reading to a range between the minimum
10+
and the maximum.
11+
12+
Created on 22 Dec 2012
13+
by Tom Igoe
14+
15+
This example is in the public domain.
16+
*/
17+
18+
#include <Esplora.h>
19+
20+
// variables:
21+
int lightMin = 1023; // minimum sensor value
22+
int lightMax = 0; // maximum sensor value
23+
boolean calibrated = false; // whether the sensor's been calibrated yet
24+
25+
void setup() {
26+
// initialize the serial communication:
27+
Serial.begin(9600);
28+
29+
// print an intial message
30+
Serial.println("To calibrate the light sensor, press and hold Switch 1");
31+
}
32+
33+
void loop() {
34+
// if switch 1 is pressed, go to the calibration function again:
35+
if (Esplora.readButton(1) == LOW) {
36+
calibrate();
37+
}
38+
// read the sensor into a variable:
39+
int light = Esplora.readLightSensor();
40+
41+
// map the light level to a brightness level for the LED
42+
// using the calibration min and max:
43+
int brightness = map(light, lightMin, lightMax, 0, 255);
44+
// limit the brightness to a range from 0 to 255:
45+
brightness = constrain(brightness, 0, 255);
46+
// write the brightness to the blue LED.
47+
Esplora.writeBlue(brightness);
48+
49+
// if the calibration's been done, show the sensor and brightness
50+
// levels in the serial monitor:
51+
if (calibrated == true) {
52+
// print the light sensor levels and the LED levels (to see what's going on):
53+
Serial.print("light sensor level: ");
54+
Serial.print(light);
55+
Serial.print(" blue brightness: ");
56+
Serial.println(brightness);
57+
}
58+
// add a delay to keep the LED from flickering:
59+
delay(10);
60+
}
61+
62+
void calibrate() {
63+
// tell the user what do to using the serial monitor:
64+
Serial.println("While holding switch 1, shine a light on the light sensor, then cover it.");
65+
66+
// calibrate while switch 1 is pressed:
67+
while(Esplora.readButton(1) == LOW) {
68+
// read the sensor value:
69+
int light = Esplora.readLightSensor();
70+
71+
// record the maximum sensor value:
72+
if (light > lightMax) {
73+
lightMax = light;
74+
}
75+
76+
// record the minimum sensor value:
77+
if (light < lightMin) {
78+
lightMin = light;
79+
}
80+
// note that you're calibrated, for future reference:
81+
calibrated = true;
82+
}
83+
}
84+
85+
86+
87+
88+
89+
90+
91+

‎libraries/Esplora/examples/EsploraMusic/EsploraMusic.ino renamed to ‎libraries/Esplora/examples/Beginners/EsploraMusic/EsploraMusic.ino

Copy file name to clipboardExpand all lines: libraries/Esplora/examples/Beginners/EsploraMusic/EsploraMusic.ino
+3-2Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,15 @@
66
77
Created on 22 november 2012
88
By Enrico Gueli <enrico.gueli@gmail.com>
9-
modified 24 Nov 2012
9+
modified 22 Dec 2012
1010
by Tom Igoe
1111
*/
1212

1313

1414
#include <Esplora.h>
1515

16-
16+
// these are the frequencies for the notes from middle C
17+
// to one octave above middle C:
1718
const int note[] = {
1819
262, // C
1920
277, // C#
+41Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
Esplora Led calibration
3+
4+
This sketch shows you how to read the microphone sensor. The microphone
5+
will range from 0 (total silence) to 1023 (really loud).
6+
When you're using the sensor's reading (for example, to set the brightness
7+
of the LED), you map the sensor's reading to a range between the minimum
8+
and the maximum.
9+
10+
Created on 22 Dec 2012
11+
by Tom Igoe
12+
13+
This example is in the public domain.
14+
*/
15+
16+
#include <Esplora.h>
17+
18+
void setup() {
19+
// initialize the serial communication:
20+
Serial.begin(9600);
21+
}
22+
23+
void loop() {
24+
// read the sensor into a variable:
25+
int loudness = Esplora.readMicrophone();
26+
27+
// map the sound level to a brightness level for the LED:
28+
int brightness = map(loudness, 0, 1023, 0, 255);
29+
// write the brightness to the green LED:
30+
Esplora.writeGreen(brightness);
31+
32+
33+
// print the microphone levels and the LED levels (to see what's going on):
34+
Serial.print("sound level: ");
35+
Serial.print(loudness);
36+
Serial.print(" Green brightness: ");
37+
Serial.println(brightness);
38+
// add a delay to keep the LED from flickering:
39+
delay(10);
40+
}
41+
+37Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
Esplora Temperature Sensor
3+
4+
This sketch shows you how to read the Esplora's temperature sensor
5+
You can read the temperature sensor in Farhenheit or Celsius.
6+
7+
Created on 22 Dec 2012
8+
by Tom Igoe
9+
10+
This example is in the public domain.
11+
*/
12+
#include <Esplora.h>
13+
14+
void setup()
15+
{
16+
Serial.begin(9600); // initialize serial communications with your computer
17+
}
18+
19+
void loop()
20+
{
21+
// read the temperature sensor in Celsius, then Fahrenheit:
22+
int celsius = Esplora.readTemperature(DEGREES_C);
23+
int fahrenheit = Esplora.readTemperature(DEGREES_F);
24+
25+
// print the results:
26+
Serial.print("Temperature is: ");
27+
Serial.print(celsius);
28+
Serial.print(" degrees Celsius, or ");
29+
Serial.print(fahrenheit);
30+
Serial.println(" degrees Fahrenheit.");
31+
Serial.println(" Fahrenheit = (9/5 * Celsius) + 32");
32+
33+
// wait a second before reading again:
34+
delay(1000);
35+
}
36+
37+

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.