From 25e94d609d1228821a89812cd6640bff65cc7b12 Mon Sep 17 00:00:00 2001 From: JbLb Date: Sat, 4 Jan 2020 22:00:04 +0100 Subject: [PATCH] function for displaying nunchuck values --- src/hoverserial.ino | 66 ++++++++++++++++++++++++++------------------- 1 file changed, 39 insertions(+), 27 deletions(-) diff --git a/src/hoverserial.ino b/src/hoverserial.ino index 5edb7cf..136aed6 100644 --- a/src/hoverserial.ino +++ b/src/hoverserial.ino @@ -159,11 +159,11 @@ void Receive() if (idx == sizeof(SerialFeedback)) { uint16_t checksum; checksum = - (uint16_t) (NewFeedback.start ^ NewFeedback. - cmd1 ^ NewFeedback.cmd2 ^ NewFeedback. - speedR ^ NewFeedback.speedL ^ NewFeedback. - speedR_meas ^ NewFeedback.speedL_meas ^ - NewFeedback.batVoltage ^ NewFeedback.boardTemp); + (uint16_t) (NewFeedback.start ^ NewFeedback.cmd1 ^ NewFeedback. + cmd2 ^ NewFeedback.speedR ^ NewFeedback. + speedL ^ NewFeedback.speedR_meas ^ NewFeedback. + speedL_meas ^ NewFeedback.batVoltage ^ NewFeedback. + boardTemp); // Check validity of the new data if (NewFeedback.start == START_FRAME @@ -201,11 +201,44 @@ void Receive() incomingBytePrev = incomingByte; } +// ########################## nunchuk ########################## + +void Nunchuk_display() +{ + if (!nchuk.update()) { + if (Serial) { + Serial.println("Controller disconnected!"); + } + nchuk.reconnect(); + } else { + if (Serial) { + // Read a button (on/off, C and Z) + Serial.print("Z: "); + nchuk.buttonZ()? Serial.print("On ") : Serial.print("Off "); + Serial.print("C: "); + nchuk.buttonC()? Serial.print("On ") : Serial.print("Off "); + + // Read joystick axis (0-255, X and Y) + Serial.print("The joystick's Y axis is at "); + Serial.print(nchuk.joyY()); + Serial.print(" and X axis is at "); + Serial.print(nchuk.joyX()); + + // Read an accelerometer and print values (0-1023, X, Y, and Z) + Serial.print(" - The accelerometer's X-axis is at "); + Serial.println(nchuk.accelX()); + } + } + +} + // ########################## LOOP ########################## unsigned long iTimeSend = 0; int iTestMax = SPEED_MAX_TEST; int iTest = 0; +int16_t old_cursorX; +int16_t old_cursorY; void loop(void) { @@ -213,28 +246,7 @@ void loop(void) // Check for new received data Receive(); - // Get new data from the controller - if (!nchuk.update()) { - Serial.println("Controller disconnected!"); - nchuk.reconnect(); - } else { - // Read a button (on/off, C and Z) - Serial.print("Z: "); - nchuk.buttonZ()? Serial.print("On ") : Serial.print("Off "); - Serial.print("C: "); - nchuk.buttonC()? Serial.print("On ") : Serial.print("Off "); - - // Read joystick axis (0-255, X and Y) - Serial.print("The joystick's Y axis is at "); - Serial.print(nchuk.joyY()); - Serial.print(" and X axis is at "); - Serial.print(nchuk.joyX()); - - // Read an accelerometer and print values (0-1023, X, Y, and Z) - Serial.print(" - The accelerometer's X-axis is at "); - Serial.println(nchuk.accelX()); - } - + Nunchuk_display(); // Send commands if (iTimeSend > timeNow) return;