commit e392e59689c22921f4ddf0f3ee8935f7c4b4275e Author: Sasha Kovar Date: Sat Mar 7 23:36:17 2020 -0800 already in process - debounce started diff --git a/AutoClicker3000.ino b/AutoClicker3000.ino new file mode 100644 index 0000000..1871932 --- /dev/null +++ b/AutoClicker3000.ino @@ -0,0 +1,194 @@ +#include +#include +#include +#include "Keyboard.h" +#include "Mouse.h" + +// The shield uses the I2C SCL and SDA pins. On classic Arduinos +// this is Analog 4 and 5 so you can't use those for analogRead() anymore +// However, you can connect other I2C sensors to the I2C bus and share +// the I2C bus. +Adafruit_RGBLCDShield lcd = Adafruit_RGBLCDShield(); + +// These #defines make it easy to set the backlight color +#define RED 0x1 +#define YELLOW 0x3 +#define GREEN 0x2 +#define TEAL 0x6 +#define BLUE 0x4 +#define VIOLET 0x5 +#define WHITE 0x7 + + +bool doClicking = false; +bool isOn = false; + +unsigned long lcdTimeout = 3000; +unsigned long lcdLastSet; + +unsigned long debounceDelay = 50; + +typedef struct +{ + unsigned long lastDebounceTime = 0; + bool state = false; + bool lastState = false; +} DebounceButton; + +DebounceButton down; + +void setup() { + // Debugging output + Serial.begin(9600); + + // set up the LCD's number of columns and rows: + lcd.begin(16, 2); + + Mouse.begin(); + Keyboard.begin(); + + Serial.println("Autoclicker3000"); + //lcd.print("Autoclicker on!"); + //lcd.setBacklight(WHITE); + + lcdLastSet = millis(); +} + +void debounce(DebounceButton &b, bool reading) { + lcd.setCursor(0, 0); + lcd.print(String(reading)); + lcd.setCursor(1, 0); + lcd.print(String(b.state)); +// lcd.setCursor(2, 0); +// lcd.print(String(reading != b.state)); + +// lcd.setCursor(4, 0); +// lcd.print(String(b.lastDebounceTime)); +// +// lcd.setCursor(10, 0); +// lcd.print(String(millis())); + + // if (reading) { + // lcd.print("true "); + // } else { + // lcd.print("false"); + // } + +// if (reading != b.state) { +// +// } + +// lcd.setCursor(10, 1); + if ((millis() - b.lastDebounceTime) > debounceDelay) { +// lcd.print("update"); + //if (reading != b.state) { + b.lastState = b.state; + b.state = reading; + //} + b.lastDebounceTime = millis(); +// } else { +// lcd.print("------"); + } + +// lcd.setCursor(0, 1); +// if (b.state) { +// lcd.print("true "); +// } else { +// lcd.print("false"); +// } +} + +void updateLCD(char* msg, int color) { + lcd.setCursor(0, 1); + lcd.print(msg); + lcd.setBacklight(color); +} + +int clickDelay = 100; // millis +int delayChange = 10; // millis +char modeName[] = "Roblox "; + +//uint8_t i = 0; + +void loop() { + uint8_t buttons = lcd.readButtons(); + + debounce(down, buttons & BUTTON_DOWN); + + if (buttons) { + // //lcd.clear(); + // // lcd.setCursor(0, 0); + // // lcd.print(modeName); + // + // + // if (buttons & BUTTON_UP) { + // //Keyboard.write('u'); + // Serial.println("UP"); + // lcdLastSet = millis(); + // } + // + if (down.state and !down.lastState) { + doClicking = !doClicking; + lcd.setCursor(0, 1); + if (doClicking) { + lcd.print("Start clicking "); + } else { + lcd.print("Stop clicking "); + } + lcd.setBacklight(YELLOW); + lcdLastSet = millis(); + } + + // if (buttons & BUTTON_LEFT) { + // lcd.setCursor(0, 1); + // lcd.print("Slower "); + // // lcd.setBacklight(GREEN); + // + // // slow down clicking + // if (clickDelay < 1000) { + // clickDelay += delayChange; + // } + // lcdLastSet = millis(); + // } + // + // if (buttons & BUTTON_RIGHT) { + // lcd.setCursor(0, 1); + // lcd.print("Faster "); + // // lcd.setBacklight(TEAL); + // + // // speed up clicking + // if (clickDelay > 50) { + // clickDelay -= delayChange; + // } + // lcdLastSet = millis(); + // } + // if (buttons & BUTTON_SELECT) { + // lcd.setCursor(0, 1); + // lcd.print("SELECT "); + // // lcd.setBacklight(VIOLET); + // lcdLastSet = millis(); + // } + } + // + // if (doClicking) { + // //digitalWrite(onLedPin, HIGH); + // if (isOn) { + // lcd.setBacklight(RED); + // // Mouse.click(MOUSE_LEFT); + // isOn = false; + // delay(clickDelay); + // } else { + // lcd.setBacklight(WHITE); + // isOn = true; + // delay(clickDelay); + // } + // } + // + // // clear second lcd line after a while + // if (millis() > lcdLastSet + lcdTimeout) { + // lcd.setCursor(0, 1); + // lcd.print(" "); + // } + +// delay(3); +}