I have working code for my digispark clone, the attiny85. I would like for the code to make clicks act like a mouse where when the key I have soldered to the attiny85 is pressed, it acts like a mouse being pressed down and would hold the click and when released it would stop holding left click. I have the 2 pins of the button soldered to the pin 2 and ground pin of my board. I am using the DigiMouse.h library. This is the link to the schematic of the attiny85. Here is my code
See the File->Examples->02.Digital->StateChangeDetection example. It shows how to use a global variable to keep track of the previous state of the button. That way you can tell when the button state changes.
You will end up with something like:
const byte ButtonPin = 2;
bool ButtonWasPressed = false; // previous state of the button
bool buttonIsPressed = digitalRead(ButtonPin) == LOW;
if (buttinIsPressed != ButtonWasPressed)
// Button state has changed
ButtonWasPressed = buttonIsPressed;
DigiMouse.setButtons(1 << 0); // Click button 0
DigiMouse.setButtons(0); //unclick all
No, the error reads "'buttinIsPressed' was not declared". That means "I don't recognize this name. " If you compare the spelling with the declaration: bool buttonIsPressed =
You will see that I typed "buttinIsPressed" one place where I should have typed "buttonIsPressed" to match the declaration. In this case, you can tell the "buttonIsPressed" is the right spelling because it is used three times where "buttinIsPressed" is used only once.
I have 4 of them and they work with the first code I sent and others I've tried. I followed this. The only thing that is different is my programmer is micronucleus, There is no option to change that setting for me.