Sensitivity Converter now working! Rough sensitivity values for now

This commit is contained in:
2025-08-15 11:13:50 +02:00
parent 5a0c0e35b4
commit e70cf1117b
2 changed files with 77 additions and 9 deletions

View File

@ -1,3 +1,13 @@
; PlatformIO Project Configuration File
;
; Build options: build flags, source filter
; Upload options: custom upload port, speed and extra flags
; Library options: dependencies, extra library storages
; Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html
[env:esp32-s3-supermini] [env:esp32-s3-supermini]
platform = espressif32 platform = espressif32
board = esp32-s3-devkitc-1 board = esp32-s3-devkitc-1
@ -5,11 +15,13 @@ framework = arduino
monitor_speed = 115200 monitor_speed = 115200
upload_speed = 460800 upload_speed = 460800
board_upload.flash_size = 4MB board_upload.flash_size = 4MB
board_build.psram = enabled board_build.psram = enabled
board_build.partitions = default.csv board_build.partitions = default.csv
build_flags = build_flags =
-D ARDUINO_USB_CDC_ON_BOOT=1 -D ARDUINO_USB_CDC_ON_BOOT=1
-D ARDUINO_USB_MODE=1 -D ARDUINO_USB_MODE=1
upload_port = COM3
monitor_port = COM3

View File

@ -1,19 +1,75 @@
#include <Arduino.h> #include <Arduino.h>
#include <USB.h>
#include <USBHIDMouse.h>
#include <tusb.h>
USBHIDMouse Mouse;
#define LED_BUILTIN 48 #define LED_BUILTIN 48
const int buttonPin = 0;
int previousButtonState = HIGH;
void smoothMouseMove(int xOffset, int yOffset, unsigned long durationMs, float steps) {
if (steps <= 0) {
// Avoid division by zero or infinite loop if steps is non-positive
Mouse.move(xOffset, yOffset); // Fallback to instant move
return;
}
// Calculate the movement per step for X and Y
float xStep = (float)xOffset / steps;
float yStep = (float)yOffset / steps;
// Calculate the delay between each step
unsigned long delayPerStep = durationMs / steps;
// Perform the movement in small steps
for (int i = 0; i < steps; i++) {
// Move the mouse by the calculated step amount.
// We cast to int because Mouse.move expects integers,
// but float calculations ensure more accurate distribution over steps.
Mouse.move((int)xStep, (int)yStep);
delay(delayPerStep); // Pause for a short duration
}
// Handle any remaining fractional movement due to integer casting
// This ensures the mouse ends up exactly at the target offset
int remainingX = xOffset - (int)(xStep * steps);
int remainingY = yOffset - (int)(yStep * steps);
if (remainingX != 0 || remainingY != 0) {
Mouse.move(remainingX, remainingY);
}
}
void setup() { void setup() {
delay(1000); delay(1000);
Serial.begin(115200); Serial.begin(115200);
Serial.println("ESP32-S3 Blink Starting..."); Serial.println("Starting ESP32-S3 USB Mouse");
pinMode(LED_BUILTIN, OUTPUT); pinMode(LED_BUILTIN, OUTPUT);
USB.begin();
Mouse.begin();
delay(2000);
} }
void loop() { void loop() {
Serial.println("Beep Beep..."); int buttonState = digitalRead(buttonPin);
const int purepixels = 8182;
const int kiripurepixels = 27300;
const int input = purepixels;
if ((buttonState != previousButtonState) && (buttonState == LOW)) {
digitalWrite(LED_BUILTIN, LOW);
smoothMouseMove(input, 0, 1000, (input / 10));
delay(500);
Serial.println("Button Pressed - Mouse should have sent event.");
}
previousButtonState = buttonState;
digitalWrite(LED_BUILTIN, HIGH); digitalWrite(LED_BUILTIN, HIGH);
delay(500);
digitalWrite(LED_BUILTIN, LOW);
delay(1000);
} }