Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
- Version 2.71828, December 2014
- Copyright (C) 2014 me <vomitme @g mail>
- Everyone is permitted to copy and distribute verbatim or modified
- copies of this license document, and changing it is allowed as long
- as the name is changed.
- DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
- TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
- 0. You just DO WHAT THE FUCK YOU WANT TO.
- */
- #include <digitalIOPerformance.h>
- #define PIN_PDIODE A0
- #define PIN_BUTTON 2
- #define BUTTON_PRESSED LOW
- void setup()
- {
- Mouse.begin();
- Serial.begin(9600); //somehow it can act as a mouse and a serial thing simultaneously
- pinModeFast(PIN_PDIODE, INPUT);
- pinModeFast(PIN_BUTTON, INPUT);
- }
- void loop()
- {
- while (digitalReadFast(PIN_BUTTON) == BUTTON_PRESSED) {
- unsigned long i = 0, s, n;
- while (digitalReadFast(PIN_PDIODE) != LOW) {
- Serial.print(analogRead(PIN_PDIODE));
- Serial.println("starting position too bright :P");
- }
- //shake mouse before the twitchnot necessary
- for (i = 0; i < 12; i++) {
- Mouse.move(0,1,0);
- delayMicroseconds(2000);
- Mouse.move(0,-1,0);
- delayMicroseconds(2000);
- }
- //twitch
- i = 0;
- Mouse.move(0,-100,0);
- //measure time until screen change detected
- s = micros(); //~3us
- while (digitalReadFast(PIN_PDIODE) != HIGH) i++; //~0.6us per cycle when using digitalReadFast
- n = micros(); //~3us
- //print results
- //Serial.print("time (us):\t");
- Serial.println(n - s);
- //Serial.print("\tcycles:\t");
- //Serial.println(i);
- delay(10);
- Mouse.move(0,100,0);
- delay(random(14,62));
- //delay(100); //uncomment this if vsync
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement