Skip to content

Instantly share code, notes, and snippets.

@houmei
Created September 18, 2013 15:36
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
CookieClicker3 click mouse-button with TimerOne library
#include <TimerOne.h>
// CookieClicker TimerOne version
// 20130919
const int ABTN=8;
const int BBTN=9;
const int CBTN=10;
const int LED=13;
// SoftwareSerial LedSerial(2,3); // for UNO
void setup() {
// Serial.begin(9600);
// while(!Serial);
// LedSerial.begin(9600);
Serial1.begin(9600); // for Leonardo
while(!Serial1);
Mouse.begin();
pinMode(ABTN,INPUT_PULLUP);
pinMode(BBTN,INPUT_PULLUP);
pinMode(CBTN,INPUT_PULLUP);
pinMode(LED,OUTPUT);
Timer1.initialize();
Timer1.attachInterrupt(readkey,30000); // 30ms
}
int trig=0;
int i;
const int countMIN=0;
const int countMAX=999;
int counter=50;
volatile int Send=0;
volatile int Up=0;
volatile int Down=0;
volatile int Psend=0;
volatile int Pup=0;
volatile int Pdown=0;
void loop() {
noInterrupts();
if (Down==1 && counter>countMIN) {
counter--;
Down=0;
}
if (Up==1 && counter<countMAX) {
counter++;
Up=0;
}
if (Send==1) {
trig=!trig;
Send=0;
}
Serial1.write(0x76);
Serial1.print(counter,DEC);
interrupts();
if (trig) {
digitalWrite(LED,1);
Mouse.click();
}
for(i=0;i<=counter;i++) {
delay(1);
digitalWrite(LED,0);
}
}
void readkey() {
int key;
key=digitalRead(ABTN);
if (key==LOW && Pdown==LOW) Down=1;
Pdown=key;
key=digitalRead(BBTN);
if (key==LOW && Pup==LOW) Up=1;
Pup=key;
key=digitalRead(CBTN);
if (key==LOW && Psend==LOW) Send=1;
Psend=key;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment