Hello
I'm not very skilled in C/C++ programming, that's why I'm requesting the help of this community.
My project concerns a device with an arduino pro mini and a 5-buttons keyboard (to manage a menu). I have found a library which matches perfectly my need. However, the code is very complex for me and I cannot find how to use it.
Here is the example code, wich works great on the serial output :
/*
Ozan Oner
Library test for http://www.cooking-hacks.com/adkeyboard-module
Connections (ADKeyboard-Arduino)
VCC-5v
GND-GND
S-A0
*/
#include <Arduino.h>
#include <AdKeyboard.h>
AdKeyboard adKeyboard(6);
void setup() {
Serial.begin(9600);
adKeyboard.setClickCallback(clickHandler);
adKeyboard.setPressCallback(pressHandler);
adKeyboard.setTwoPressCallback(twoPressHandler);
}
void loop() {
adKeyboard.update();
// here I would like to insert the code to manage my menu
// I cannot find how to get the value of 'key' from this part of the program.
}
int clickHandler(int key) {
Serial.print("clickHandler: ");
Serial.println(key);
}
void pressHandler(int key) {
Serial.print("pressHandler: ");
Serial.println(key);
}
void twoPressHandler(int k1, int k2) {
Serial.print("twoPressHandler: ");
Serial.print(k1);
Serial.print(" ");
Serial.println(k2);
}
I have attached the library files in the post.
My goal is to manage a menu into the main loop, but for that, I need to know which key is pressed. The function clickHandler can provide the key pressed (0 for Left, 1 for Up, 2 for Down, 3 for Right, 4 for Enter) but I cannot manage to get the key value from the main loop.
The callback function are too tricky for me. So if someone can help me to understand, I really will appreciate !
Hervé
AdKeyboard.cpp (2.71 KB)
AdKeyboard.h (1.7 KB)