Hallo liebe Leute,
ich probiere seit Tagen ein kleines Problem zu lösen und komme nicht richtig weiter....
Ich lese die Positionsdaten eines Maussensors aus (X u. Y) und lasse diesen einen Zeitwert zuordnen, damit ich später die zurückgelegte Strecke usw. berechnen kann. Das klappt auch alles wunderbar.
Ich bekomme es aber nich hin, die Zeit vom Programmstart zur ersten Bewegegung der Maus zu erfassen, damit ich mit der Funktion millis() auch wirklich bei erst 0000 ms die erste Bewegung zuordne.
Vielleicht kann mir jemand von eich helfen, wäre super!
Danke schonmal,
Grüße,
Sebbo
Hier noch das Programm:
#include "ADNS2051.h"
#define SCLK 2 // Serial clock pin on the Arduino
#define SDIO 3 // Serial data (I/O) pin on the Arduino
ADNS2051 Optical1 = ADNS2051(SCLK, SDIO);
signed long x = 0; // Variables for our 'cursor'
signed long y = 0; //
unsigned int c = 0; // Counter variable for coordinate reporting
unsigned long zeit = millis();
void setup()
{
Serial.begin(115200);
Optical1.begin(); // Resync (not really necessary?)
}
void loop()
{
// The status commands are available only for the PAN3101 and the ADNS2051:
Optical1.updateStatus(); // Get the latest motion status
if (Optical1.motion()) // If the 'Motion' status bit is set,
{
x += Optical1.dx(); // Read the dX register and in/decrease X with that value
y += Optical1.dy(); // Same thing for dY register.....
}
if (y != 0) //Datenausgabe beginnt erst bei Bewegung der Maus!
{
if (c++ & 0x80)
{ // Report the coordinates once in a while...
Serial.print("x=");
Serial.print(x, DEC);
Serial.print(" y=");
Serial.print(y, DEC);
Serial.print(" Zeit: ");
zeit = millis(); //prints time since program started
Serial.println(zeit);
// Serial.println(" ms");
Serial.println();
if (c==1000) c = 0;
//c = 0; // Reset the report counter
}
}
}