Leider mußt ich denen erst mal beibringen das Lötfett ganz doll Bähhh ist.
Aber einen (oder eigentlich 2) Arduino später läst sich der Mauszeiger per Joystick verschieben.
Zusammen mit nem OTG-Kabel geht das auch mit nem Handy.
Sogar mit Apfel-Geräten.
Hier das aus den Beispielen zusammengesetzte Code für analoge Joysticks (aus alten elektrischen Rollstühlen):
Code: Alles auswählen
/*
This example is in the public domain.
*/
const int numReadings = 25;
int readings1[numReadings]; // the readings from the analog input
int readIndex1 = 0; // the index of the current reading
int total1 = 0; // the running total
//int average = 0; // the average
int xValue = 0;
int inputPin1 = A0;
int readings2[numReadings]; // the readings from the analog input
int readIndex2 = 0; // the index of the current reading
int total2 = 0; // the running total
//int average = 0; // the average
int yValue = 0;
int inputPin2 = A1;
void setup() {
Serial.begin(9600); // setup serial
Mouse.begin(); // take control of the mouse
// initialize the buttons' inputs:
pinMode(2, INPUT);
pinMode(3, INPUT);
digitalWrite(2, HIGH); // pull-up
digitalWrite(3, HIGH); // pull-up
// initialize all the readings to 0:
for (int thisReading1 = 0; thisReading1 < numReadings; thisReading1++)
readings1[thisReading1] = 0;
}
void loop() {
//int xValue = analogRead(A0); // read the joystick's X position
//int yValue = analogRead(A1); // read the joystick's Y position
Serial.print("Joystick X: "); // print a label for the X value
Serial.print(xValue); // print the X value
Serial.print("\tY: "); // print a tab character and a label for the Y value
Serial.print(yValue); // print the Y value
// subtract the last reading:
total1 = total1 - readings1[readIndex1];
// read from the sensor:
readings1[readIndex1] = analogRead(inputPin1);
// add the reading to the total:
total1 = total1 + readings1[readIndex1];
// advance to the next position in the array:
readIndex1 = readIndex1 + 1;
// if we're at the end of the array...
if (readIndex1 >= numReadings)
// ...wrap around to the beginning:
readIndex1 = 0;
// calculate the average:
xValue = total1 / numReadings;
// subtract the last reading:
total2 = total2 - readings2[readIndex1];
// read from the sensor:
readings2[readIndex2] = analogRead(inputPin2);
// add the reading to the total:
total2 = total2 + readings2[readIndex2];
// advance to the next position in the array:
readIndex2 = readIndex2 + 1;
// if we're at the end of the array...
if (readIndex2 >= numReadings)
// ...wrap around to the beginning:
readIndex2 = 0;
// calculate the average:
yValue = total2 / numReadings;
int mouseX = map(xValue, 415, 609, -10, 10); // map the X value to a range of movement for the mouse X
int mouseY = map(yValue, 415, 565, -10, 10); // map the Y value to a range of movement for the mouse Y
Mouse.move(mouseX, mouseY, 0); // move the mouse
int clickState1 = !digitalRead(2);
int clickState2 = !digitalRead(3);
// if the mouse button 1 is pressed:
if (clickState1 == HIGH) {
// if the mouse is not pressed, press it:
if (!Mouse.isPressed(MOUSE_LEFT)) {
Mouse.press(MOUSE_LEFT);
}
}
// else the mouse button is not pressed:
else {
// if the mouse is pressed, release it:
if (Mouse.isPressed(MOUSE_LEFT)) {
Mouse.release(MOUSE_LEFT);
}
}
// if the mouse button 2 is pressed:
if (clickState2 == HIGH) {
// if the mouse is not pressed, press it:
if (!Mouse.isPressed(MOUSE_RIGHT)) {
Mouse.press(MOUSE_RIGHT);
}
}
// else the mouse button is not pressed:
else {
// if the mouse is pressed, release it:
if (Mouse.isPressed(MOUSE_RIGHT)) {
Mouse.release(MOUSE_RIGHT);
}
}
delay(10); // a short delay before moving again
}
Da fehlt mir aber noch ne Rampenfunktion für sanften Anlauf und genauere Positionierung.
Code: Alles auswählen
/*
ButtonMouseControl
For Leonardo and Due boards only.
Controls the mouse from five pushbuttons on an Arduino Leonardo, Micro or Due.
Hardware:
* 6 pushbuttons attached to D2, D3, D4, D5, D6, D7
The mouse movement is always relative. This sketch reads
four pushbuttons, and uses them to set the movement of the mouse.
WARNING: When you use the Mouse.move() command, the Arduino takes
over your mouse! Make sure you have control before you use the mouse commands.
created 15 Mar 2012
modified 27 Mar 2012
by Tom Igoe
modified 22 aug 2015
by Lars Neufurth
this code is in the public domain
*/
// set pin numbers for the five buttons:
const int upButton = 2;
const int downButton = 3;
const int leftButton = 4;
const int rightButton = 5;
const int mouseButton1 = 6;
const int mouseButton2 = 7;
int range = 5; // output range of X or Y movement; affects movement speed
int responseDelay = 10; // response delay of the mouse, in ms
void setup() {
// initialize the buttons' inputs:
pinMode(upButton, INPUT);
pinMode(downButton, INPUT);
pinMode(leftButton, INPUT);
pinMode(rightButton, INPUT);
pinMode(mouseButton1, INPUT);
pinMode(mouseButton2, INPUT);
digitalWrite(upButton, HIGH); // pull-up
digitalWrite(downButton, HIGH); // pull-up
digitalWrite(leftButton, HIGH); // pull-up
digitalWrite(rightButton, HIGH); // pull-up
digitalWrite(mouseButton1, HIGH); // pull-up
digitalWrite(mouseButton2, HIGH); // pull-up
// initialize mouse control:
Mouse.begin();
}
void loop() {
// read the buttons:
int upState = !digitalRead(upButton);
int downState = !digitalRead(downButton);
int rightState = !digitalRead(rightButton);
int leftState = !digitalRead(leftButton);
int clickState1 = !digitalRead(mouseButton1);
int clickState2 = !digitalRead(mouseButton2);
// calculate the movement distance based on the button states:
int xDistance = (leftState - rightState) * range;
int yDistance = (upState - downState) * range;
// if X or Y is non-zero, move:
if ((xDistance != 0) || (yDistance != 0)) {
Mouse.move(xDistance, yDistance, 0);
}
// if the mouse button is pressed:
if (clickState1 == HIGH) {
// if the mouse is not pressed, press it:
if (!Mouse.isPressed(MOUSE_LEFT)) {
Mouse.press(MOUSE_LEFT);
}
}
// else the mouse button is not pressed:
else {
// if the mouse is pressed, release it:
if (Mouse.isPressed(MOUSE_LEFT)) {
Mouse.release(MOUSE_LEFT);
}
}
// if the mouse button is pressed:
if (clickState2 == HIGH) {
// if the mouse is not pressed, press it:
if (!Mouse.isPressed(MOUSE_RIGHT)) {
Mouse.press(MOUSE_RIGHT);
}
}
// else the mouse button is not pressed:
else {
// if the mouse is pressed, release it:
if (Mouse.isPressed(MOUSE_RIGHT)) {
Mouse.release(MOUSE_RIGHT);
}
}
// a delay so the mouse doesn't move too fast:
delay(responseDelay);
}
@fritzler
Es steht dir frei den Code in richtiges C zu gießen und an einen AVR zu verfüttern.
Ich selbst könne et vielecht auch aber ich hab keine Lust mich damit zu befassen.
Zumal das Ergebnis von Meschen reproduzirbar sein muß die grad so wissen welches Ende des Lötkolbens heiß wird.
Microcontroller und deren Programmmierung sind da bömische Dörfer.