Simple Array Confusion. 9 Button Keyboard.h

Hi,

Before all you wiser people LOL at my attempt, as you may well do so. I’m a novice, but I’ve made an attempt, made the effort, tried, failed and got myself confused.

I have an Arduino Due with 9 momentary switches to Gnd and digital input pins 2,3,4,5,6,7,8,9 & 10. I wish to emulate keyboard presses to control a DAW / VST.

As you will see I have got myself very confused with my lack of coding skills and knowledge of arrays.

Hear is the sketch I’ve attempted, please don’t LOL to much;

/*
  Keyboard Message test

  For the Arduino Leonardo and Micro.

  Sends a text string when a button is pressed.

  The circuit:
   pushbutton attached from pin 4 to +5V
   10-kilohm resistor attached from pin 4 to ground

  created 24 Oct 2011
  modified 27 Mar 2012
  by Tom Igoe
  modified 11 Nov 2013
  by Scott Fitzgerald

  This example code is in the public domain.

  http://www.arduino.cc/en/Tutorial/KeyboardMessage
*/

#include "Keyboard.h"
int buttonPins[9] = {2, 3, 4, 5, 6, 7, 8, 9, 10};
int previousButtonState = LOW;   // for checking the state of a pushButton

void setup()
{
  for (int i = 0; i < 9; i++)
    pinMode(buttonPins[i], INPUT_PULLUP);
  Keyboard.begin();  // initialize control over the keyboard:
}

void loop()
{
  for (int i = 0; i < 9; i++)
    int buttonState = digitalRead(buttonPins[i]);  // read the pushbutton
  if ((buttonState != previousButtonState)  // if the button state has changed
      && (buttonState == LOW))  // and it's currently pressed
  {
    switch()
  {
    case 1:
      Keyboard.write(' ');  // press spacebar
        break;
      case 2:
        Keyboard.write('a');
        break;
      case 3:
        Keyboard.write('b');
        break;
      case 4:
        Keyboard.write('c');
        break;
      case 5:
        Keyboard.write('d');
        break;
      case 6:
        Keyboard.write('e');
        break;
      case 7:
        Keyboard.write('f');
        break;
      case 8:
        Keyboard.write('g');
        break;
      case 9:
        Keyboard.write('h');
        break;
    }
    previousButtonState = buttonState;  // save the current button state for comparison next time
  }
}

And hear are the error msgs I currently get;

Arduino: 1.8.1 (Mac OS X), Board: "Arduino Due (Programming Port)"

/Users/darrensimms/Documents/Arduino/a_b_c/a_b_c.ino: In function 'void loop()':
a_b_c:38: error: 'buttonState' was not declared in this scope
   if ((buttonState != previousButtonState)  // if the button state has changed
        ^
a_b_c:41: error: expected primary-expression before ')' token
     switch()
            ^
exit status 1
'buttonState' was not declared in this scope

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

I had thought of using ‘else if’, instead of ‘case 1 etc’, but on reading, theres nothing to be gained by doing so.

So I ask for some pointers to my confusion and errors please, when you’ve all finished laughing.

Dizzwold.

Arduino: 1.8.1 (Mac OS X), Board: "Arduino Due (Programming Port)"

/Users/darrensimms/Documents/Arduino/a_b_c/a_b_c.ino: In function 'void loop()':
a_b_c:38: error: 'buttonState' was not declared in this scope
   if ((buttonState != previousButtonState)  // if the button state has changed
        ^

You forgot the '{' for the body of the for-loop so the only thing in the loop is the declaration of buttonState. That declaration is local to the body of the for-loop so it is no longer visible on the next line (outside the body of the for-loop).

a_b_c:41: error: expected primary-expression before ')' token
     switch()
            ^
exit status 1

The 'switch' part of the statement needs a value to compare to each of the 'case' constants. You probably meant switch(i).

Warning: You are using one 'previousButtonState' for all 9 buttons. That will not do what you want. You have to keep a previous state for each button (think 'array').

Hi John ‘johnwasser’,

Thank you for your reply and input.

You forgot the ‘{’

A schoolboy error of which I make many, and often over complicate things.

You probably meant switch(i)

A lack of knowledge, thank you for that.

Warning: You are using one ‘previousButtonState’ for all 9 buttons

Again this is a lack of knowledge. So I’ve done some thinking about your “Warning”. I’ve compiled the new sketch, but not tested it yet, but does the following sketch with your tweaks seem correct, or should I do more research? A simple “warning yes that will work” or “no”. I don’t wish of it to be writen for me, as I will never learn from that. If its wrong, I’ll go away and look for what I need to do.

/*
  Keyboard Message test

  For the Arduino Leonardo and Micro.

  Sends a text string when a button is pressed.

  The circuit:
   pushbutton attached from pin 4 to +5V
   10-kilohm resistor attached from pin 4 to ground

  created 24 Oct 2011
  modified 27 Mar 2012
  by Tom Igoe
  modified 11 Nov 2013
  by Scott Fitzgerald

  This example code is in the public domain.

  http://www.arduino.cc/en/Tutorial/KeyboardMessage
*/

#include "Keyboard.h"
int buttonPins[9] = {2, 3, 4, 5, 6, 7, 8, 9, 10};
int previousButtonState [9] = {LOW};  // for checking the state of a pushButton

void setup()
{
  for (int i = 0; i < 9; i++)
    pinMode(buttonPins[i], INPUT_PULLUP);
  Keyboard.begin();  // initialize control over the keyboard:
}

void loop()
{
  for (int i = 0; i < 9; i++)
  { int buttonState = digitalRead(buttonPins[i]);  // read the pushbutton

    if ((buttonState != previousButtonState[9])  // if the button state has changed
        && (buttonState == LOW))  // and it's currently pressed
    {
      switch (i)
      {
        case 1:
          Keyboard.write(' ');  // press spacebar
          break;
        case 2:
          Keyboard.write('a');
          break;
        case 3:
          Keyboard.write('b');
          break;
        case 4:
          Keyboard.write('c');
          break;
        case 5:
          Keyboard.write('d');
          break;
        case 6:
          Keyboard.write('e');
          break;
        case 7:
          Keyboard.write('f');
          break;
        case 8:
          Keyboard.write('g');
          break;
        case 9:
          Keyboard.write('h');
          break;
      }
      previousButtonState[9] = buttonState;  // save the current button state for comparison next time
    }
  }
}

Can I also ask, did my attempt make LOL? I think my daily ambition should be to attempt writing some Arduino code, fail, post it, but to at-least put a smile on someones face. LOL.

Thank you.

Dizzwold.

Tested, but failed again. Getting further lost. Should I be using ‘[10]’?

I can’t see the wood for the trees at the moment.

This is what I have currently;

/*
  Keyboard Message test

  For the Arduino Leonardo and Micro.

  Sends a text string when a button is pressed.

  The circuit:
   pushbutton attached from pin 4 to +5V
   10-kilohm resistor attached from pin 4 to ground

  created 24 Oct 2011
  modified 27 Mar 2012
  by Tom Igoe
  modified 11 Nov 2013
  by Scott Fitzgerald

  This example code is in the public domain.

  http://www.arduino.cc/en/Tutorial/KeyboardMessage
*/

#include "Keyboard.h"
int buttonPins[9] = {2, 3, 4, 5, 6, 7, 8, 9, 10};
int previousButtonState [9] = {LOW, LOW, LOW, LOW, LOW, LOW, LOW, LOW, LOW};  // for checking the state of a pushButton

void setup()
{
  for (int i = 0; i < 9; i++)
    pinMode(buttonPins[i], INPUT_PULLUP);
  Keyboard.begin();  // initialize control over the keyboard:
}

void loop()
{
  for (int i = 0; i < 9; i++)
  { int buttonState = digitalRead(buttonPins[i]);  // read the pushbutton

    if ((buttonState != previousButtonState[9])  // if the button state has changed
        && (buttonState == LOW))  // and it's currently pressed
    {
      switch (i)
      {
        case 1:
          Keyboard.write(' ');  // press spacebar
          break;
        case 2:
          Keyboard.write('m');
          break;
        case 3:
          Keyboard.write('s');
          break;
        case 4:
          Keyboard.write('c');
          break;
        case 5:
          Keyboard.write('d');
          break;
        case 6:
          Keyboard.write('e');
          break;
        case 7:
          Keyboard.write('f');
          break;
        case 8:
          Keyboard.write('g');
          break;
        case 9:
          Keyboard.write('h');
          break;
      }
      previousButtonState[9] = buttonState;  // save the current button state for comparison next time
    }
  }
}

A lack of simple knowledge!!!

Sorry if this is considered ‘bumbing my thread’. I forgot to state, I’ve tried many things in the last few hours, but I can’t find any examples of ‘previousButtonState’ regarding arrays as advised. Any links to such would be a big help.

Dizzwold.

There are several instance of previousButtonState[9] in your code but they all refer to the same level of the array. They should probably be previousButtonState[i] so that each input has its own previous state.

If you put the chars to be written in an array indexed by the value of i then the switch case would not be necessary. Just write the char from the array indexed by the value of i.

EDIT : fixed missing code tags as noted by johnwasser

He means previousButtonState[i]
_ That 'i' in square brackets means italics if it is not inside code tags. That's one of the many reasons we insist on code tags. :)_

Thanks for the reminder John. I have fixed my post.

Thank you UKHeliBob & johnwasser,

Thanks for your input. I just spent the last 20 mins searching my previous posts and sketches looking for italics. LOL. Thanks UKHeliBob for addmitting to that and correcting so. I would have been looking for ages and then asking johnwasser "what are you on about". LOL.

To be honest with UKHeliBob, with my lack of knowledge, call me a simpleton, you have completely lost me. I'm now lost in the woods with chars. If you can find an example for me to read into I'd be grateful.

I must say at this point with my simpleton coding knowlege, I hoped to make 1 person smile and LOL, but johnwasser and UKHeliBob have returned that smile to my face. UKHeliBob "you should know better"!

Sorry, couldn't resist. LOL. As I thought, I was at fault. Shall we move on to my grammar and spelling next?

A fun distraction from some frustration.

I'll try to take-in, what has been advised on-board, but I may end-up coming back with 'cap in hand', but I'll try first!

Thank you for the advice and fun, your both Gents.

Dizzwold.

For a novice, or as some may state a simpleton, I think I 've done well to get this far, yet the comments stating;

previousButtonState[9]

Should be;

previousButtonState[i]

Are we talking about all;

previousButtonState[9]

or just after;

void loop()

A novice "yes", a simpleton "maybe".

Sorry johnwasser & UKHeliBob, I've used code tags. In preview it shows a very big box for 1 line of text. Tried it as a quote, but that makes it in italics, so kept with code tags. Sorry.

Dizzwold.

All the places where you USE previousButtonState, not the one place where you DECLARE previousButtonState. You want to USE the element in the array that corresponds with the current button 'i'.

Using an ‘i’ in every place I have previousButtonState except in globals doesn’t seem to work?

Am I missing something else?

Hears what I have currently;

/*
  Keyboard Message test

  For the Arduino Leonardo and Micro.

  Sends a text string when a button is pressed.

  The circuit:
   pushbutton attached from pin 4 to +5V
   10-kilohm resistor attached from pin 4 to ground

  created 24 Oct 2011
  modified 27 Mar 2012
  by Tom Igoe
  modified 11 Nov 2013
  by Scott Fitzgerald

  This example code is in the public domain.

  http://www.arduino.cc/en/Tutorial/KeyboardMessage
*/

#include "Keyboard.h"
int buttonPins[9] = {2, 3, 4, 5, 6, 7, 8, 9, 10};
int previousButtonState[] = {LOW, LOW, LOW, LOW, LOW, LOW, LOW, LOW, LOW};  // for checking the state of a pushButton

void setup()
{
  for (int i = 0; i < 9; i++)
    pinMode(buttonPins[i], INPUT_PULLUP);
  Keyboard.begin();  // initialize control over the keyboard:
}

void loop()
{
  for (int i = 0; i < 9; i++)
  {
    int buttonState = digitalRead(buttonPins[i]);  // read the pushbutton
    if ((buttonState != previousButtonState[i])  // if the button state has changed
        && (buttonState == LOW))  // and it's currently pressed
    {
      switch (i)
      {
        case 1:
          Keyboard.write(' ');  // press spacebar
          break;
        case 2:
          Keyboard.write('m');
          break;
        case 3:
          Keyboard.write('s');
          break;
        case 4:
          Keyboard.write('c');
          break;
        case 5:
          Keyboard.write('d');
          break;
        case 6:
          Keyboard.write('e');
          break;
        case 7:
          Keyboard.write('f');
          break;
        case 8:
          Keyboard.write('g');
          break;
        case 9:
          Keyboard.write('h');
          break;
      }
      previousButtonState[i] = buttonState;  // save the current button state for comparison next time
    }
  }
}

Dizzwold.

What do you mean by "doesn't seem to work?" ?

      previousButtonState[i] = buttonState;  // save the current button state for comparison next timeShould not be inside the if code block. It should be executed whether or not the button has become pressed.

Another problem is that your switch/case uses cases from 1 to 9 but the for loop that provides the value to switch on goes from 0 to 8. My advice would still be to use an array of 9 chars and to use the value of i as an index to the character to be sent.

You wrote:

     break;
      }
      previousButtonState[i] = buttonState;  // save the current button state for comparison next time
    }
  }
}

What you should have written is:

     break;
      }
    }
      previousButtonState[i] = buttonState;  // save the current button state for comparison next time
  }
}

It's easier to follow with comments:

     break;
      }  // End of switch
    }  // End of 'if button pressed'
      previousButtonState[i] = buttonState;  // save the current button state for comparison next time
  }  // End of 'for i' loop
}  // End of loop()

Hi Guy’s, & Gals for that matter,

I want to thank you for your input and advice. I’m very grateful.

I’ve had lots of problems with my Due today, where it won’t accept sketches sent to it. I not only restarted the IDE, but also rebooted my computer, reset the PRAM and SMC, uploaded the 1.8.2 IDE from 1.8.1 and much more. I think my Due is kind-of bricked. It accepts sketches every now and again, but keeps changing ports

My Due was a gift, and with the way some of the connectors are soldered “not flush, at angles”, I can only guess it is a clone.

I’ve looked on the Arduino Europe site to purchase 1, but they are currently out of stock.

So my little project will have to wait, as I can’t trust the item I have. If it is randomly accepting sketches, I can only assume it is randomly sending info from the native usb!

HeliBobUK, When I remove the i from the braces in the if statment, I get the following errors;

Arduino: 1.8.2 (Mac OS X), Board: "Arduino Due (Programming Port)"

/Users/darrensimms/Documents/Arduino/a_b_c/a_b_c.ino: In function 'void loop()':
a_b_c:39: error: expected primary-expression before ']' token
     if ((buttonState != previousButtonState[])  // if the button state has changed
                                             ^
exit status 1
expected primary-expression before ']' token

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

Then when I remove the braces from the if statement I get more errors;

Arduino: 1.8.2 (Mac OS X), Board: "Arduino Due (Programming Port)"

/Users/darrensimms/Documents/Arduino/a_b_c/a_b_c.ino: In function 'void loop()':
a_b_c:39: error: ISO C++ forbids comparison between pointer and integer [-fpermissive]
     if ((buttonState != previousButtonState)  // if the button state has changed
                         ^
exit status 1
ISO C++ forbids comparison between pointer and integer [-fpermissive]

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

As a novice I’m also unsure what your telling me in your “Another problem”, advice. Should I be using case 0-8 instead of case 1-9? Regarding indexing i to the character to be sent, I have no clue how to do this. This is my 1st attempt of writing my own array. Sorry, I don’t understand. Yes I’m a simpleton.

Johnwasser, Yes yet another school boy error. With your “follow with comments”, I can see my error very clearly. I’ve learnt something from that today.

So unfortunatley, until I can purchase a new, original Due, i will have to put all on hold.

Thank you both for your time and help. Your both Gents.

Grateful Dizzwold.

HeliBobUK, When I remove the i from the braces in the if statment,

Why did you remove them ? Leave the array subscripts as they are with i in the square brackets. It is how the program knows which of the eight previousButtonState variables to us.

As a novice I’m also unsure what your telling me in your “Another problem”, advice. Should I be using case 0-8 instead of case 1-9?

Yes.

To use an array instead of switch/case create an array of key values to be sent with the values in them like this

char keyValues[] = {" mscdefghi"};

Then, instead of switch/case you can do

    if ((buttonState != previousButtonState[i])  // if the button state has changed
        && (buttonState == LOW))  // and it's currently pressed
    {
      Keyboard.write(keyValues[i]);
    }

The value if i will select the value to be sent from the keyValues array. Much neater than switch/case but that should work as well if you want to use it.

Hi UKHeliBob,

Sorry I got your username wrong in my last lost!

Thank you for your reply and clear advice. Very helpful.

I'll admit the use of 'char keyValues' was above my knowledge and vision. So as above thank you.

Regarding removing the i's;

Why did you remove them ?

I thought 'wrongly as you've stated', that was what you where trying to imply with;

previousButtonState = buttonState; // save the current button state for comparison next time
Should not be inside the if code block. It should be executed whether or not the button has become pressed.[/quote]
My issues yesterday with Due not taking sketches and later not being recognised by my computer would seem to be worse and possibly more expensive than I first thought. I later tried my 2 other Arduino Megas, and they weren't recognised by my computer. I've reset the computer again, over night, and now all are working 'for the time being'. I'll have a play and see. If it is my computer, I'll be knackered as it is an IMac, so not cheap!
Again, as with yesterday, I've learned somthing today, for which I'm grateful. Thank you!
Dizzwold.

Hi,

With thanks to UKHeliBob and johnwasser I’ve learnt from their lessons in arrays and now got the sketch fully functional with GarageBand, controlling the ‘Transport system’ aswel as track above or track down select, mute and solo, using the switch/case0/1/2 etc.

Thank you both.

I’m now looking at what UKHeliBob has writen in his last post regarding using an array for the keyValues, but I need to use some ‘special or modifiyer keys’ such as the return key, arrow up and arrow down, that need to be writen as the following for an example;

case 7:
            Keyboard.write((char)KEY_UP_ARROW);  // press up arrow for track above
            break;
          case 8:
            Keyboard.write((char)KEY_DOWN_ARROW);  // press down arrow for track below
            break;

Can I include ‘((char)KEY_UP_ARROW)’ in array like suggested ‘{“mscdefghi”};’?

As UKHeliBob stated, to do so would make the sketch easier and neater to read.

The current sketch;

/*
  Keyboard Message test

  For the Arduino Leonardo and Micro.

  Sends a text string when a button is pressed.

  The circuit:
   pushbutton attached from pin 4 to +5V
   10-kilohm resistor attached from pin 4 to ground

  created 24 Oct 2011
  modified 27 Mar 2012
  by Tom Igoe
  modified 11 Nov 2013
  by Scott Fitzgerald

  This example code is in the public domain.

  http://www.arduino.cc/en/Tutorial/KeyboardMessage
*/

#include "Keyboard.h"
int buttonPins[9] = {2, 3, 4, 5, 6, 7, 8, 9, 10};
int previousButtonState[] = {LOW, LOW, LOW, LOW, LOW, LOW, LOW, LOW, LOW};  // for checking the state of a pushButton

void setup()
{
  for (int i = 0; i < 9; i++)
    pinMode(buttonPins[i], INPUT_PULLUP);
  Keyboard.begin();  // initialize control over the keyboard:
}

void loop()
{
  for (int i = 0; i < 9; i++)
  {
    int buttonState = digitalRead(buttonPins[i]);  // read the pushbutton
    if ((buttonState != previousButtonState[i])  // if the button state has changed
        && (buttonState == LOW))  // and it's currently pressed
    {
      switch (i)
      {
        case 0:
          Keyboard.write(' ');  // press spacebar for play/pause
          break;
        case 1:
          Keyboard.write ((char)KEY_RETURN);  // press return key for go to begining
          break;
        case 2:
          Keyboard.write(',');  // press , comma for back 1 section
          break;
        case 3:
          Keyboard.write('.');  // press . fullstop for forward 1 section
          break;
        case 4:
          Keyboard.write('r');  // press r for record
          break;
        case 5:
          Keyboard.write('m');  // press m for track mute
          break;
        case 6:
          Keyboard.write('s');  //press s for track solo
          break;
        case 7:
          Keyboard.write((char)KEY_UP_ARROW);  // press up arrow for track above
          break;
        case 8:
          Keyboard.write((char)KEY_DOWN_ARROW);  // press down arrow for track below
          break;
      }
    }
      previousButtonState[i] = buttonState;  // save the current button state for comparison next time   
  }
}

Dizzwold.

Can I include ‘((char)KEY_UP_ARROW)’ in array like suggested ‘{“mscdefghi”};’?

Yes, you can include any character in the array. No, you can’t use the value in an initialization list like that.

You could do something like:

   char stuffToDo[] = "mscdef?hi";
   stuffToDo[6] = (char)KEY_UP_ARROW;

   // Send the array...

   byte arrLen = strlen(stuffToDo);
   for(byte b=0; b<arrLen; b++)
   {
     Keyboard.write(stuffToDo[b]);
   }

Hi PaulS,

I thought I had a vague idea of what you were stating, but due, yet again to my poor knowledge, I’m guessing.

For each special key ‘keyValues[0][1][7][8]’, should I call each one ‘keyValues1, keyVelues2’, and so-on?

keyValues[0] = Keyboard.write(' ');
  keyValues[1] = (char)KEY_RETURN;
  keyValues[7] = (char)KEY_UP_ARROW;
  keyValues[8] = (char)KEY_DOWN_ARROW;

Then have seperate versions of;

{
         byte arrLen = strlen(keyValues);
         for(byte b=0; b=arrLen; b++);
        }

Then have different 'byte letters a,b,c for the ‘keyValues1/2/3’?

Sorry but I’m confusing myself and I also don’t know what the ‘char’ is for the spacebar?

This is what I have currently;

/*
  Keyboard Message test

  For the Arduino Leonardo and Micro.

  Sends a text string when a button is pressed.

  The circuit:
   pushbutton attached from pin 4 to +5V
   10-kilohm resistor attached from pin 4 to ground

  created 24 Oct 2011
  modified 27 Mar 2012
  by Tom Igoe
  modified 11 Nov 2013
  by Scott Fitzgerald

  This example code is in the public domain.

  http://www.arduino.cc/en/Tutorial/KeyboardMessage
*/
#include <MIDI_controller.h> // include the library
#include "Keyboard.h"
int buttonPins[9] = {2, 3, 4, 5, 6, 7, 8, 9, 10};
int previousButtonState[] = {LOW, LOW, LOW, LOW, LOW, LOW, LOW, LOW, LOW};  // for checking the state of a pushButton

const static byte Channel_Volume = 0x07; // controller number 7 is defined as Channel Volume in the MIDI implementation.
const static byte Pan_Volume = 0x0A;
const static size_t analogAverage = 8; // Use the average of 8 samples to get smooth transitions and prevent noise

Analog fader1(A0, Channel_Volume, 1); // Create a new instance of the class 'Analog, called 'fader', on pin A0, that sends MIDI messages with controller 7 (channel volume) on channel 1.
Analog fader2(A1, Pan_Volume, 1);

char keyValues[] = "??,.rms??";


void setup()

{
  for (int i = 0; i < 9; i++)
    pinMode(buttonPins[i], INPUT_PULLUP);
  Keyboard.begin();  // initialize control over the keyboard:
  {
    USBMidiController.blink(13);  // flash the LED on pin 13 on every message
    USBMidiController.setDelay(15);  // wait 15 ms after each message not to flood the connection
    delay(1000); // Wait a second...
    fader1.average(analogAverage); // Use the average of 8 samples to get smooth transitions and prevent noise
    fader2.average(analogAverage);
  }
  keyValues[0] = Keyboard.write(' ');
  keyValues[1] = (char)KEY_RETURN;
  keyValues[7] = (char)KEY_UP_ARROW;
  keyValues[8] = (char)KEY_DOWN_ARROW;
}

void loop()
{
  fader1.refresh(); // refresh the fader (check whether the input has changed since last time, if so, send it over MIDI)
  fader2.refresh();

  {
    for (int i = 0; i < 9; i++)
    {
      int buttonState = digitalRead(buttonPins[i]);  // read the pushbutton
      if ((buttonState != previousButtonState[i])  // if the button state has changed
          && (buttonState == LOW))  // and it's currently pressed
      {
        Keyboard.write(keyValues[i]);
        {
          byte arrLen = strlen(keyValues);
          for (byte b = 0; b = arrLen; b++);
        }
      }
      previousButtonState[i] = buttonState;  // save the current button state for comparison next time
    }
  }
}

To be fair, this addition may be above my skills. I had it working with the switch/case sketch.

Thank you for your thoughts and input.

Dizzwold.

keyValues[0] = Keyboard.write(' ');

How is this supposed to work ?
Why not just put a space in the array as suggested in reply #14 ?