This library is archived and is no longer being maintained. It can be still be downloaded and used, but is read-only and cannot be contributed to. For more information, you can view this repository on GitHub.
The Arduino Esplora has a set of functions for easily interfacing with the sensors and actuators mounted on the board. The functions are accessible through the Esplora class.
The library offers easy access to the data from the onboard sensors, and provides the ability to change the state of the outputs.
The sensors available on the board are:
The actuators available on the board are:
For more information about the Esplora, visit the Esplora documentation.
NOTE: If you're using the Arduino IDE version 1.0.3 or earlier , you will need to download the latest version of this library, or get it from the Arduino GitHub repository.
To use this library
1#include <Esplora.h>
The Esplora Beginners examples show the functionality of the inputs and outputs of the board. They are a good place to start experimenting with the Esplora's capabilities. The Expert examples are more detailed sketches that illustrate project ideas that utilize the board features in novel ways.
Esplora constructor
Esplora is the base class for all methods used by the board. It is not called directly, but invoked whenever you use a function that relies on it.
readSlider()
Reads the value from the linear potentiometer as a 10-bit number. This means that it will map input voltages between 0 and 5 volts into integer values between 0 and 1023. This yields a resolution between readings of: 5 volts / 1024 units or, .0049 volts (4.9 mV) per unit.
1Esplora.readSlider()
none
int : The linear potentiometer's position, mapped to a value between 0 and 1023.
1#include <Esplora.h>2
3void setup()4{5 Serial.begin(9600);6}7
8void loop()9{10 int value = Esplora.readSlider();11 Serial.println(value);12
13 delay(1000);14}
readLightSensor()
Reads the intensity of light hitting the light sensor as a 10-bit number. This means that it will map input voltages between 0 and 5 volts into integer values between 0 and 1023. This yields a resolution between readings of: 5 volts / 1024 units or, .0049 volts (4.9 mV) per unit.
1Esplora.readLightSensor()
none
int : The amount of light hitting the sensor, mapped to a value between 0 and 1023.
1#include <Esplora.h>2
3void setup()4{5 Serial.begin(9600);6}7
8void loop()9{10 int value = Esplora.readLightSensor();11 Serial.println(value);12
13 delay(1000);14}
readTemperature()
Reads the ambient temperature of the temperature sensor and returns a reading in either the Celsius or Fahrenheit scale, depending on the parameter passed.
1readTemperature(scale)
scale: the scale of the output, valid arguments are: DEGREES_C and DEGREES_F
int : The temperature reading in Celsius or Fahrenheit. The Celsius range is from -40°C to 150°C, the Fahrenheit range is from -40°F to 302°F.
1#include <Esplora.h>2
3void setup()4{5 Serial.begin(9600);6}7
8void loop()9{10 int celsius = Esplora.readTemperature(DEGREES_C);11 int fahrenheit = Esplora.readTemperature(DEGREES_F);12 Serial.print(celsius);13 Serial.print("\t");14 Serial.print(fahrenheit);15
16 delay(1000);17}
readMicrophone()
Read the amplitude from the microphone. It returns a valure between 0 and 1023.
1readMicrophone()
none
int : The amplitude mapped to a range of 0 to 1023.
1#include <Esplora.h>2
3void setup()4{5 Serial.begin(9600);6}7
8void loop()9{10 int value = Esplora.readMicrophone();11 Serial.println(value);12
13 delay(1000);14}
readJoystickSwitch()
Reads the joystick's button and returns if its state is 0 or 1023. If you prefer something more consistent with the readButton() function, you may want to use readJoystickButton() instead. That function does the same as this, but returns LOW when the joystick button is pressed, and HIGH when not pressed.
1Esplora.readJoystickSwitch()
none
0 when pressed, 1023 when not pressed.
1#include <Esplora.h>2
3
4void setup(){5 // nothing in setup6}7
8void loop()9{10 int button = Esplora.readJoystickSwitch();11
12 if(button == 0)13 {14 Esplora.writeRed(255);15 }16 else {17 Esplora.writeRed(0);18 }19}
readJoystickButton()
Reads the joystick's button and returns if its state is LOW or HIGH. This function does basically the same thing as readJoystickSwitch(), but it returns values consistent with the readButton() function.
1Esplora.readJoystickButton()
none
LOW when pressed, HIGH when not pressed.
1#include <Esplora.h>2
3
4void setup(){5 // nothing in setup6}7
8void loop()9{10 int button = Esplora.readJoystickButton();11
12 if(button == LOW)13 {14 Esplora.writeRed(255);15 }16 else {17 Esplora.writeRed(0);18 }19}
readAccelerometer()
Reads values from the Esplora's accelerometer. Each of the three axes are accessed independently.
1Esplora.readAccelerometer(axis)
axis : char, determines what axis to read.
int : the value of the readings on the chosen axis. The accelerometer returns zero when it is perpendicular to the direction of gravity. Positive or negative values result when it is accelerates in one of the two directions of the axis.
1#include <Esplora.h>2
3void setup()4{5 Serial.begin(9600);6}7
8void loop()9{10 int x_axis = Esplora.readAccelerometer(X_AXIS);11 int y_axis = Esplora.readAccelerometer(Y_AXIS);12 int z_axis = Esplora.readAccelerometer(Z_AXIS);13
14 Serial.print("x: ");15 Serial.print(x_axis);16 Serial.print("\ty: ");17 Serial.print(y_axis);18 Serial.print("\tz: ");19 Serial.println(z_axis);20
21 delay(500);22}
readButton()
Reads a button's state and returns if it is HIGH or LOW.
1Esplora.readButton(button)
button: the associated button that you wanto read. Valid argument are:
LOW when pressed, HIGH when not pressed.
1#include <Esplora.h>2
3void setup(){}4
5void loop()6{7int button = Esplora.readButton(SWITCH_DOWN);8
9if(button == LOW)10 {11 Esplora.writeRed(255);12 }13else {14 Esplora.writeRed(0);15 }16}
readJoystickX()
Read the position of the X-axis of the joystick. When the joystick is in the center, it returns zero. Positive values indicate the joystick has moved to the right and negative values when moved to the left.
1Esplora.readJoystickX()
none
int : 0 when the joystick is in the middle of the x-axis; 1 to 512 when the joystick is moved to the right; -1 to -512 when the joystick is moved to the left.
1#include <Esplora.h>2
3void setup()4{5Serial.begin(9600);6}7
8void loop()9{10int value = Esplora.readJoystickX();11Serial.println(value);12
13delay(1000);14}
readJoystickY()
Read the position of the Y-axis of the joystick. When the joystick is in the center, it returns zero. Positive values indicate the joystick has moved up and negative values when moved down.
1Esplora.readJoystickY()
none
int : 0 when the joystick is in the middle of the y-axis; 1 to 512 when the joystick is moved up; -1 to -512 when the joystick is moved down.
1#include <Esplora.h>2
3void setup()4{5Serial.begin(9600);6}7
8void loop()9{10int value = Esplora.readJoystickY();11Serial.println(value);12
13delay(1000);14}
writeRGB()
Write values representing brightness to the RGB LED. By mixing different values, it's possible to create different color combinations.
1Esplora.writeRGB(red, green, blue)
nothing
1#include <Esplora.h>2
3void setup() {}4
5void loop()6{7 Esplora.writeRGB(0, 128, 255);8 delay(1000);9 Esplora.writeRGB(255, 0, 128);10 delay(1000);11 Esplora.writeRGB(128, 255, 0);12 delay(1000);13}
writeRed()
Write values to the red LED that correspond to the brightness.
1Esplora.writeRed(value)
value: int, value to set the red LED brightness. Range 0 to 255
nothing
1#include <Esplora.h>2
3void setup() {}4
5void loop()6{7 for(int i=0; i<256; i++)8 {9 Esplora.writeRed(i);10 delay(100);11 }12}
writeGreen()
Write values to the green LED that correspond to the brightness.
1Esplora.writeGreen(value)
value: int, value to set the green LED brightness. Range 0 to 255
nothing
1#include <Esplora.h>2
3void setup() {}4
5void loop()6{7 for(int i=0; i<256; i++)8 {9 Esplora.writeGreen(i);10 delay(100);11 }12}
writeBlue()
Write values to the blue LED that correspond to the brightness.
1Esplora.writeBlue(value)
value: int, value to set the blue LED brightness. Range 0 to 255
nothing
1#include <Esplora.h>2
3void setup() {}4
5void loop()6{7 for(int i=0; i<256; i++)8 {9 Esplora.writeBlue(i);10 delay(100);11 }12}
readRed()
Read the brightness value of the red LED.
1Esplora.readRed()
none
int : the brightness of the red LED between 0 and 255.
1#include <Esplora.h>2
3void setup()4{5 Serial.begin(9600);6}7
8void loop()9{10 int dimmerValue = Esplora.readSlider();11 Esplora.writeRed(dimmerValue);12 Serial.println(Esplora.readRed());13
14 delay(500);15}
readGreen()
Read the brightness value of the green LED.
1Esplora.readGreen()
none
int : the brightness of the green LED between 0 and 255.
1#include <Esplora.h>2
3void setup()4{5 Serial.begin(9600);6}7
8void loop()9{10 int dimmerValue = Esplora.readSlider();11 Esplora.writeGreen(dimmerValue);12 Serial.println(Esplora.readGreen());13
14 delay(500);15}
readBlue()
Read the brightness value of the blue LED.
1Esplora.readBlue()
none
int : the brightness of the blue LED between 0 and 255.
1#include <Esplora.h>2
3void setup()4{5 Serial.begin(9600);6}7
8void loop()9{10 int dimmerValue = Esplora.readSlider();11 Esplora.writeBlue(dimmerValue);12 Serial.println(Esplora.readBlue());13
14 delay(500);15}
tone()
Generates a square wave of the specified frequency from the Esplora's onboard buzzer. A duration can be specified in milliseconds, otherwise the wave continues until a call to Esplora.noTone().
Only one tone can be generated at a time. If a tone is already playing, the call will set its frequency.
Use of the tone() function will interfere with fading the red LED.
1Esplora.tone(frequency, duration)
frequency: the frequency of the tone in hertz - unsigned int
duration: the duration of the tone in milliseconds (optional) - unsigned long
nothing
noTone()
Stops the generation of a square wave triggered by Esplora.tone(). Has no effect if no tone is being generated.
1Esplora.noTone()
none
nothing