Bastelstunde 3.Teil Joystck an Handy

Der chaotische Hauptfaden

Moderatoren: Heaterman, Finger, Sven, TDI, Marsupilami72, duese

Antworten
Lars_Original
Beiträge: 506
Registriert: Mo 12. Aug 2013, 08:21
Wohnort: Burghaun (im Zentrum des Wahnsinns)

Bastelstunde 3.Teil Joystck an Handy

Beitrag von Lars_Original »

In der hiesigen Werkstatt gibts nen guten Lötkolben ...

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
}
Für digitale Stcks ist das etwas einfacher.
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.
Benutzeravatar
Chemnitzsurfer
Beiträge: 7859
Registriert: So 11. Aug 2013, 14:10
Wohnort: Chemnitz (OT Hutholz)
Kontaktdaten:

Re: Bastelstunde 3.Teil Joystck an Handy

Beitrag von Chemnitzsurfer »

Schön mal wieder etwas von dir zu höhren.
...aus alten elektrischen Rollstühlen...
Hast du dich in der Orthopädisches Schwerpunktklinik mit den Hausmeistern angefreundet oder wie bist du daran gekommen?
Jedenfalls eine tolle forumstypischen Lösung!
Weiter so und gute Besserung 8-)
Lukas94
Beiträge: 820
Registriert: Di 13. Aug 2013, 21:34

Re: Bastelstunde 3.Teil Joystck an Handy

Beitrag von Lukas94 »

Juhu, der Lars ist wieder da :)
Klasse Fricklerlösungen!
plottermeier
Beiträge: 1458
Registriert: Fr 16. Aug 2013, 14:32

Re: Bastelstunde 3.Teil Joystck an Handy

Beitrag von plottermeier »

Hallo,

klasse Gebastel! Man kann echt viel an Hilfsmitteln selber bauen und die Anwender freuen sich oft gewaltig drüber!
Sowas ähnliches für normale PCs hatte ich als Zivi mal gebastelt. Ich hatte den Nummernblock von ner Tastatur auf
ne Sub-D-Buchse gelegt. Da kam dann der Joystick dran.
Wenn man die Windows-Eingabehilfen aktiviert, kann man sogar Beschleunigungsrampen einstellen.
Die Anwender brauchten zwar ewig, konnten den PC aber relativ normal bedienen.

Viele Grüße
Jens
Lars_Original
Beiträge: 506
Registriert: Mo 12. Aug 2013, 08:21
Wohnort: Burghaun (im Zentrum des Wahnsinns)

Re: Bastelstunde 3.Teil Joystck an Handy

Beitrag von Lars_Original »

Chemnitzsurfer hat geschrieben: Hast du dich in der Orthopädisches Schwerpunktklinik mit den Hausmeistern angefreundet oder wie bist du daran gekommen?
Jedenfalls eine tolle forumstypischen Lösung!)
So in etwa. Jedenfalls hab ich das erst mal mit der digitalen Eingabe gelöst und somit die zuständigen Techniker für mich gewonnen.
Dann bekam ich besagtes Alt-Teil. Allerdings hat das schon nen Schlag weg. Es hält die Mittelposition eher schlecht.

Die Disziplin wäre ja auch die vorhandene Steuerung im Stuhl anzuzapfen. Die Kommunikation zwischen Eingabe und Leistungselektronik ist wohl CAN-Bus. Irgendwelche Tipps bzl. Transmittiern (Sollte bei Reichelt zu beziehen sein) und Software für die Snifferei ?


Lars
Benutzeravatar
gafu
Beiträge: 6393
Registriert: Mi 14. Aug 2013, 20:56
Wohnort: nahe Jena
Kontaktdaten:

Re: Bastelstunde 3.Teil Joystck an Handy

Beitrag von gafu »

vielleicht kann man das/die verschlissenen teile auswechseln oder instandsetzen?
Lars_Original
Beiträge: 506
Registriert: Mo 12. Aug 2013, 08:21
Wohnort: Burghaun (im Zentrum des Wahnsinns)

Re: Bastelstunde 3.Teil Joystck an Handy

Beitrag von Lars_Original »

Teilweise wird das ja auch gemacht. Wenn aber das Ding mechanisch durch ist, loht sich praktisch nur das Ausschlachten um Teile für den nächsten Stuhl zu gewinnen.
Und zu guter Letzt steht über allem ja noch das Medezinprodukte.Gesetz.

Lars
Benutzeravatar
zauberkopf
Beiträge: 9535
Registriert: So 11. Aug 2013, 15:33
Wohnort: gefährliches Halbwissen

Re: Bastelstunde 3.Teil Joystck an Handy

Beitrag von zauberkopf »

Übrigens.. mittlerweile dort auch nur noch bleifrei..
Matt
Beiträge: 6094
Registriert: So 24. Aug 2014, 21:22

Re: Bastelstunde 3.Teil Joystck an Handy

Beitrag von Matt »

Korrekt, dass Ausnahmegenehmigung mit bleihaltige Lötzinn in medizinische und militärische Bereich ausläuft, vielleicht schon auslaufend oder bald auslaufend.

Beruflich befasse ich damit und fast alle ist bereits umgestellt und Neuentwicklung ist 100% EU-freundlich

Grüss
Matt
Matt
Beiträge: 6094
Registriert: So 24. Aug 2014, 21:22

Re: Bastelstunde 3.Teil Joystck an Handy

Beitrag von Matt »

Für Lars tut ich hier, da er versehtlich an mir über PN geschickt hat.
Wo ich euch hier grad mal sehe...

Hier wird noch ein Hersteller für eine Puste- und Schlag-Klingel gesucht.
Also ein Eingabegerät für die Patientenrufanlage.
Da brauchts ausgangsseitig nur nen Kontakt. Bisher wurde das mit Druckschaltern und nem Endschalter mit Federaufsatz gelöst. Allerdings in Eigenproduktion.

Lars
Benutzeravatar
zauberkopf
Beiträge: 9535
Registriert: So 11. Aug 2013, 15:33
Wohnort: gefährliches Halbwissen

Re: Bastelstunde 3.Teil Joystck an Handy

Beitrag von zauberkopf »

Lars :

Was auch ganz cool ist, wenn Du mal über die Hintergründe schreibst.
Ich fand es schon immer faszinierend zu sehen, wie ein Produkt an das man immer irgendwie mitgearbeitet hat,
etwas wirklich bewirkt.
z.B. Anti-Dekubitus-OP-Auflage..Systeme... etc..
Es gibt übrigens, auch irgendwo ne Maker-Scene, die sich genau solchen Problemstellungen widmet.

lg JAn
Hausmeister
Beiträge: 494
Registriert: So 11. Aug 2013, 20:24

Re: Bastelstunde 3.Teil Joystck an Handy

Beitrag von Hausmeister »

Chemnitzsurfer hat geschrieben:Schön mal wieder etwas von dir zu höhren.
...aus alten elektrischen Rollstühlen...
Hast du dich in der Orthopädisches Schwerpunktklinik mit den Hausmeistern angefreundet oder wie bist du daran gekommen?
Jedenfalls eine tolle forumstypischen Lösung!
Weiter so und gute Besserung 8-)
Was sollen denn hier immer die Anspielungen auf Hausmeister?
Problem oder was? :mrgreen:

Schön wieder von dir zu lesen Lars!
Benutzeravatar
Andreas_P
Beiträge: 1400
Registriert: Mo 12. Aug 2013, 11:35
Wohnort: Lohr am Main
Kontaktdaten:

Re: Bastelstunde 3.Teil Joystck an Handy

Beitrag von Andreas_P »

Die Disziplin wäre ja auch die vorhandene Steuerung im Stuhl anzuzapfen. Die Kommunikation zwischen Eingabe und Leistungselektronik ist wohl CAN-Bus. Irgendwelche Tipps bzl. Transmittiern (Sollte bei Reichelt zu beziehen sein) und Software für die Snifferei ?
Wenn ich es noch richtig in Erinnerung habe war es bei dem E-Stuhl Supertrans von Otto Bock möglich,
den Joystick der Steuerung, oder besser Bordcomputer als PC Eingabegerät zu benutzen.
Die Steuerung von dem hatte außerdem noch eine IR Schnittstelle um damit TV oder Hi-Fi Geräte steuern zu können.
Benutzeravatar
Fritzler
Beiträge: 12604
Registriert: So 11. Aug 2013, 19:42
Wohnort: D:/Berlin/Adlershof/Technologiepark
Kontaktdaten:

Re: Bastelstunde 3.Teil Joystck an Handy

Beitrag von Fritzler »

Äh ja? Wadd? ich wurde angesprochen? :lol:
Erstmal schön, wieder was von dir zu hören mit fortgeschrittener Bastellaune!
Und natürlich wird erstmal das Wichtigste gefixt.
Würd ich aber erst zu der vorlesungsfreien Zeit zu Weihnachten rum schaffen, vorher is bei mir Landunter :oops:
Man schicke mir eine pöse Erinenrungs PN, falls ich das verpenne.

GIbts Bilder?
Antworten