From 1b0b2fa685e13ce6f89be32417aa97c940e1b162 Mon Sep 17 00:00:00 2001 From: JbLb Date: Tue, 7 Jan 2020 00:39:27 +0100 Subject: [PATCH] nunchunk stuff --- src/hoverserial.ino | 51 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 49 insertions(+), 2 deletions(-) diff --git a/src/hoverserial.ino b/src/hoverserial.ino index b11684b..fdfbc83 100644 --- a/src/hoverserial.ino +++ b/src/hoverserial.ino @@ -41,7 +41,7 @@ #include #include #include -#include +#include // https://github.com/dmadison/NintendoExtensionCtrl // #include @@ -239,6 +239,49 @@ void Nunchuk_display() } +// ########################## nunchuk ########################## + +void show_dot() +{ +int old_cursorX, old_cursorY; + +char text[22]; + + if (nchuk.update()) { + display.setCursor(0, 20); + display.setTextSize(1); // Draw 1X-scale text + display.setTextColor(SSD1306_WHITE); + display.print("X : "); + old_cursorX = display.getCursorX(); + old_cursorY = display.getCursorY(); + display.fillRect(old_cursorX, old_cursorY, (6 * 4), 8, SSD1306_BLACK); // erase previous display + display.setCursor(old_cursorX, old_cursorY); + display.print(nchuk.joyX()); + display.setCursor(0, 50); + display.setTextSize(1); // Draw 1X-scale text + display.setTextColor(SSD1306_WHITE); + display.print("Y : "); + old_cursorX = display.getCursorX(); + old_cursorY = display.getCursorY(); + display.fillRect(old_cursorX, old_cursorY, (6 * 4), 8, SSD1306_BLACK); // erase previous display + display.setCursor(old_cursorX, old_cursorY); + display.print(nchuk.joyY()); + + int y_d = int(41 + (44*(nchuk.joyY()-128))/256); + int x_d = int(80 + (44*(nchuk.joyX()-128))/256); + + if (Serial) { + sprintf (text,"y_d : %d | x_d : %d", y_d , x_d ); + Serial.println(text); + } + + display.drawPixel(x_d,y_d,SSD1306_WHITE); + } + else { + nchuk.reconnect(); + } +} + // ########################## LOOP ########################## unsigned long iTimeSend = 0; @@ -253,7 +296,11 @@ void loop(void) // Check for new received data Receive(); - Nunchuk_display(); +// Nunchuk_display(); +// show_dot(); +// display.display(); + + // Send commands if (iTimeSend > timeNow) return;