View difference between Paste ID: DvgkM9Ab and ajWPN1vt
SHOW: | | - or go back to the newest paste.
1
/*
2
           DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
3-
                   Version 2, December 2004
3+
                 Version 2.71828, December 2014
4
5
Copyright (C) 2014 me <vomitme @g mail>
6
7
Everyone is permitted to copy and distribute verbatim or modified
8
copies of this license document, and changing it is allowed as long
9
as the name is changed.
10
11
           DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
12
  TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
13
14
 0. You just DO WHAT THE FUCK YOU WANT TO.
15
*/
16
17
#include <digitalIOPerformance.h>
18
19
#define PIN_PDIODE A0
20
#define PIN_BUTTON 2
21
#define BUTTON_PRESSED LOW
22
23
void setup()
24
{
25
  Mouse.begin();
26
  Serial.begin(9600); //somehow it can act as a mouse and a serial thing simultaneously
27
  pinModeFast(PIN_PDIODE, INPUT);
28
  pinModeFast(PIN_BUTTON, INPUT);
29
}
30
31
void loop()
32
{
33
  while (digitalReadFast(PIN_BUTTON) == BUTTON_PRESSED) {
34
    unsigned long i = 0, s, n;
35
36
    while (digitalReadFast(PIN_PDIODE) != LOW) {
37
      Serial.print(analogRead(PIN_PDIODE));
38
      Serial.println("starting position too bright :P");
39
    }
40
41
    //shake mouse before the twitchnot necessary
42
    for (i = 0; i < 12; i++) {
43
      Mouse.move(0,1,0);
44
      delayMicroseconds(2000);
45
      Mouse.move(0,-1,0);
46
      delayMicroseconds(2000);
47
    }
48
    
49
    //twitch
50
    i = 0;
51
    Mouse.move(0,-100,0);
52
53
    //measure time until screen change detected
54
    s = micros(); //~3us
55
    while (digitalReadFast(PIN_PDIODE) != HIGH) i++; //~0.6us per cycle when using digitalReadFast
56
    n = micros(); //~3us
57
58
    //print results
59
    //Serial.print("time (us):\t");
60
    Serial.println(n - s);
61
    //Serial.print("\tcycles:\t");
62
    //Serial.println(i);
63
    
64
    delay(10);
65
    Mouse.move(0,100,0);
66
    delay(random(14,62));
67
    //delay(100); //uncomment this if vsync
68
  }
69
}