#include const byte interruptPin = 3; const int XPin = A0; const int YPin = A1; int default_X = 0; int default_Y = 0; unsigned long clickTime = 0; bool shortClick = false; bool longClick = false; const int ARRAYSIZE = 3; String modes[ARRAYSIZE] = { "jogging", "runto", "set null" }; void click() { // wenn "down" dann down Zeit merken if ( digitalRead(interruptPin) == LOW){ clickTime = millis();} else{ // "up" feststellen und Zeit merken unsigned long time = millis() - clickTime; if (time < 300){ shortClick = true; Serial.println("short click"); } else { longClick=true; Serial.println("long click"); } } } void setup() { pinMode(interruptPin, INPUT_PULLUP); attachInterrupt(digitalPinToInterrupt(interruptPin), click, CHANGE); Serial.begin(9600); // für x und y die leerlaufwerte holen, und eine Toleranz von 3 einbauen, bei der nichts gemacht wird. default_X = analogRead(XPin); // read the input pin default_Y = analogRead(YPin); // read the input pin } void move(int stepnumber, int MaxPower, int wait) { /* delayMicroseconds(wait); */ } void loop() { int analogX = analogRead(XPin) - default_X; // read the input pin int analogY = analogRead(YPin) - default_Y; // read the input pin // berechnung delay-x // berechnung delay-y float x = (analogX *100.0f )/ default_X; if (analogX > 0){ x = (analogX *100.0f )/ (1023-default_X); } float y = (analogY *100.0f )/ default_Y; if (analogY > 0){ x = (analogY *100.0f )/ (1023-default_Y); } if ((abs(analogX) > 2) || (abs(analogY) > 2)) { Serial.print("X:"); Serial.print(analogX); Serial.print (" "); Serial.print(x); Serial.print(" Y:"); Serial.print(analogY); Serial.print (" "); Serial.println(y); } else { // immediate stop } delay(100); }