Go Down

Topic: Esplora: how could I program the slider switch to give Dpad 4 more functions? (Read 4771 times) previous topic - next topic


I just re-worded the subject to be a question instead of a statement.

I would like to have add a second function to each of the 4 Dpad buttons, perhaps by using the slider as a mode switch:
ie: slider is to the left, Dpad buttons send keystrokes 1,2,3,4 then slider to the right and Dpad buttons send keystrokes 5,6,7,8.

I got the Esplora for Christmas and so am a new user. Can you show me how to go about this?

Thank you. Here is what I have so far, which since it is a modification to the Tux controller, works for the 1,2,3,4, functions:

 8 buttons - add 4 more functions to Dpad by using slider as mode switch
Based on Keyboard emulation By Enrico Gueli

#include <Esplora.h>

boolean buttonStates[8];

const byte buttons[] = {
 JOYSTICK_DOWN, // down arrow
 JOYSTICK_LEFT, // left arrow
 JOYSTICK_UP, // up arrow
 JOYSTICK_RIGHT, // right arrow
 SWITCH_DOWN, // press 1
 SWITCH_LEFT, // press 2
 SWITCH_UP, // press 3
 SWITCH_RIGHT, // press 4

const char keystrokes[] = {

void setup() {

void loop() {

 // Iterate through all the buttons:
 for (byte thisButton = 0; thisButton < 8; thisButton++) {
   boolean lastState = buttonStates[thisButton];
   boolean newState = Esplora.readButton(buttons[thisButton]);
   if (lastState != newState) { // Something changed!
     if (newState == PRESSED) {
     else if (newState == RELEASED) {

   // Store the new button state, so you can sense a difference later:
   buttonStates[thisButton] = newState;
int slider = Esplora.readSlider();
byte mode2 = map(slider, 0, 1023, 0, 13);


Thank you for your time.


maybe define

const char keystrokes[2][] = {

and change line  byte mode2 = map(slider, 0, 1023, 0, 13); to  mode2 = map(slider, 0, 1023, 0, 1); (declare at top of loop byte mode2=0;)


      if (newState == PRESSED) {
      else if (newState == RELEASED) {

Hi Again, Kitty.

I get a raft of errors, which is no doubt due to me not knowing what other things to change besides your advice. Thanks for taking the time. If I may be so bold, could you try your suggestion yourself and see if it works for you? 

Thank you again.



Can the both of you read the how to use the forum sticky and post your code correctly between code tags. This is the # in the reply box.
Then we can all join in and help.
I get a raft of errors,

So post the FULL code of what you are trying to compile and the errors you get.
You were given some things to change in your code, we can see if you have done that correctly.

You can read the error messages, they tell you what is wrong. It is just that by including the full path name they can look a bit intimidating.

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131