Closed rohitsahu7 closed 3 years ago
I don't understand what's the issue, can you be more specific?
If you look at the first code example, the stick position will be stored in two short ints in the struct wii_i2c_nunchuk_state
after decoding the state data with wii_i2c_decode_nunchuk()
.
Please help, I am using ESP32 - I want the stick position
// analog stick:
signed char x;
signed char y;
// buttons: char c; char z;
then compare them to do some task to control a robot car
Have you looked at the example code in the repository README.md
? It continually reads and prints the stick position:
void loop()
{
const unsigned char *data = wii_i2c_read_state();
wii_i2c_request_state();
if (! data) {
Serial.printf("no data available :(")
} else {
wii_i2c_nunchuk_state state;
wii_i2c_decode_nunchuk(data, &state);
Serial.printf("Stick position: (%d,%d)\n", state.x, state.y); // <-- here state.x and state.y contain the stick position
Serial.printf("C button is %s\n", (state.c) ? "pressed" : "not pressed");
Serial.printf("Z button is %s\n", (state.z) ? "pressed" : "not pressed");
}
delay(1000);
}
You can copy the example code to your project, and replace the Serial.printf()
s with your code that uses the stick position values state.x
and state.y
to do whatever you want with them.
Thank you , worked
I need the values in the int format