Skip to content

Instantly share code, notes, and snippets.

@houmei
Created September 15, 2013 16:20
  • 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?
Cookie Clicker (Mouse Click)
#include <SoftwareSerial.h>
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);
}
int trig=0;
int s;
int i,t;
const int countMIN=0;
const int countMAX=999;
int counter=countMIN;
void loop() {
s=digitalRead(ABTN);
if (s==LOW && counter>countMIN) {
counter--;
}
s=digitalRead(BBTN);
if (s==LOW && counter<countMAX) {
counter++;
}
Serial1.write(0x76);
Serial1.print(counter,DEC);
s=digitalRead(CBTN);
if (s==LOW) {
if (trig==0) {
trig=1;
} else {
trig=0;
}
}
for(i=0;i<=countMAX;i++) {
if (trig==1 && i<counter) {
t=i%2;
digitalWrite(LED,t);
Mouse.click();
delay(1);
} else {
digitalWrite(LED,0);
delay(1);
}
}
delay(100);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment