Go Down

Topic: Sending HID scan codes via SoftwareSerial with a helper function (Read 482 times) previous topic - next topic

sabriel27

Jul 29, 2013, 06:25 pm Last Edit: Jul 29, 2013, 06:27 pm by sabriel27 Reason: 1
I'm working on a project where I'm basically making a keyboard for iOS devices. I'm using a bluetooth module  (blueSmirf HID from sparkfun) and an Arduino Uno. I'm using the SoftwareSerial library.

I'm trying to clean up a bit of my code so I created this following helper function:


Code: [Select]

void sendKey(const byte scanCode[], int dly) {
       //scanCode is a array of 11 hex codes
       //dly is the amount of delay between the press and the release
       mySerial.write(scanCode, sizeof(scanCode));
       delay(dly);
       mySerial.write(RELEASE, sizeof(RELEASE));
}


But when I put this into my loop(), my Arduino Uno doesn't seem to do anything... Is there any way to encapsulate the press, delay, and release into a helper function? It works when it's not in a helper function.

This doesn't work:
Code: [Select]
    else if (vf < 512) { //navigate left
 /*      mySerial.write(LEFT, sizeof(LEFT));
       delay(100);
       mySerial.write(RELEASE, sizeof(RELEASE)); */
       
       sendKey(LEFT, 100);

     }




This works:
Code: [Select]
     else if (vf < 512) { //navigate left
      mySerial.write(LEFT, sizeof(LEFT));
       delay(100);
       mySerial.write(RELEASE, sizeof(RELEASE));

     }


What am I doing wrong?

Arrch

We don't work with snippits down here, post ALL of your code. If it is too big to fit into a single sketch, attach the code.

Go Up