0
votes

I uploaded the following program to my Arduino micro:

#include <Mouse.h>

int buttonPin;

void setup() {
   pinMode(buttonPin, INPUT);
   Mouse.begin();
}

void loop() {
   if(digitalRead(buttonPin) == HIGH) {
      Mouse.click(MOUSE_LEFT);
   }
}

First of all, yes I already know that I haven't defined buttonPin (I realized after the fact) but, this is the code as I uploaded it. Now when ever I plug my Arduino in to try to upload a program it spam clicks, causing the Arduino IDE to overload and not upload my program. It should also be noted that one time it also overloaded my computer forcing me to unplug the Arduino and reset my computer. My question is: #1: is there any way to actually fix the Arduino (I also have an Arduino Uno if I need to hook it up to that for some reason) and #2: when or if I get the Arduino working again, how would I fix my code. (I'm guessing the answer to #2 would be changing int buttonPin; to int buttonPin = 2)

1

1 Answers

0
votes

Connect pull-down resistor to pin 0 because global variables are initialized to theirs default values. This should stop spam from mouse and it should be possible to upload code.

Otherwise you need another Arduino as Arduino ISP and upload new code over 6pin serial interface.