Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //-------------------------------------------------------
- #define SDIO 8
- #define SCLK 9
- //-------------------------------------------------------
- /*class ADNS2610
- {
- public:
- ADNS2610(int sdio,int sclk);
- void sync();
- char read(char address);
- void write(char address,char value);
- private:
- int _sdio;
- int _sclk;
- }*/
- //-------------------------------------------------------
- byte DriverRead(byte address)
- {
- pinMode (SDIO, OUTPUT);
- for (byte i=128; i >0 ; i >>= 1)
- {
- digitalWrite (SCLK, LOW);
- delayMicroseconds(10);
- digitalWrite (SDIO, (address & i) != 0 ? HIGH : LOW);
- delayMicroseconds(10);
- digitalWrite (SCLK, HIGH);
- delayMicroseconds(10);
- }
- delayMicroseconds(120);
- pinMode (SDIO, INPUT);
- byte res = 0;
- for (byte i=128; i >0 ; i >>= 1)
- {
- digitalWrite (SCLK, LOW);
- delayMicroseconds(10);
- digitalWrite (SCLK, HIGH);
- delayMicroseconds(10);
- if( digitalRead (SDIO) == HIGH )
- {
- res |= i;
- }
- }
- delayMicroseconds(100);
- return res;
- }
- //-------------------------------------------------------
- void DriverWrite(byte address, byte data)
- {
- address |= 0x80;
- pinMode (SDIO, OUTPUT);
- for (byte i = 128; i > 0 ; i >>= 1)
- {
- digitalWrite (SCLK, LOW);
- delayMicroseconds(10);
- digitalWrite (SDIO, (address & i) != 0 ? HIGH : LOW);
- delayMicroseconds(10);
- digitalWrite (SCLK, HIGH);
- delayMicroseconds(10);
- }
- delayMicroseconds(120);
- for (byte i = 128; i > 0 ; i >>= 1)
- {
- digitalWrite (SCLK, LOW);
- delayMicroseconds(10);
- digitalWrite (SDIO, (data & i) != 0 ? HIGH : LOW);
- delayMicroseconds(10);
- digitalWrite (SCLK, HIGH);
- delayMicroseconds(10);
- }
- delayMicroseconds(100);
- }
- //-------------------------------------------------------
- void DriverInit()
- {
- pinMode(SCLK, OUTPUT);
- pinMode(SDIO, OUTPUT);
- digitalWrite(SCLK, HIGH);
- delayMicroseconds(5);
- digitalWrite(SCLK, LOW);
- delayMicroseconds(1);
- digitalWrite(SCLK, HIGH);
- delay(1025);
- DriverWrite(0x00, 0x01);
- delay(3000);
- }
- //-------------------------------------------------------
- int DriverReadFrame(byte *arr, int len)
- {
- byte *pos=arr;
- byte *uBound=arr+len;
- unsigned long timeout = millis() + 1000;
- byte val;
- DriverWrite(0x08, 0x2A);
- while( millis() < timeout && pos < uBound)
- {
- val = DriverRead(0x08);
- //Only bother with the next bit if the pixel data is valid.
- if( !(val & 64) )
- {
- continue;
- }
- //If we encounter a start-of-field indicator, and the cursor isn't at the first pixel,
- //then stop. ('Cause the last pixel was the end of the frame.)
- if( ( val & 128 ) && ( pos != arr) )
- {
- break;
- }
- *pos = val & 63;
- pos++;
- }
- return (pos-arr);
- }
- //-------------------------------------------------------
- void setup()
- {
- Serial.begin(9600);
- DriverInit();
- }
- //-------------------------------------------------------
- void loop()
- {
- /*byte x = DriverRead(0x02);
- byte y = DriverRead(0x03);
- if(x || y)
- {
- Serial.print("X:");
- Serial.print(x,DEC);
- Serial.print(" Y:");
- Serial.println(y,DEC);
- }*/
- if (Serial.available() > 0)
- {
- byte c = Serial.read();
- if (c == 'F')
- {
- byte tmp[324];
- int len = DriverReadFrame(tmp,324);
- for(int i=0;i<len;i++)
- {
- Serial.write(tmp[i]);
- }
- Serial.println();
- Serial.println(len);
- }
- }
- }
- //-------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement