fmattiussi
Published © MIT

Arduino External Mouse Buttons

I built the right and left mouse buttons with wall switches.

BeginnerProtip2,089
Arduino External Mouse Buttons

Things used in this project

Hardware components

Pushbutton switch 12mm
SparkFun Pushbutton switch 12mm
The wall switches
×1
Arduino Nano R3
Arduino Nano R3
×1
Jumper wires (generic)
Jumper wires (generic)
×2
Breadboard (generic)
Breadboard (generic)
×1
Resistor 10k ohm
Resistor 10k ohm
×2
USB A to Mini-B Cable
Digilent USB A to Mini-B Cable
×1

Software apps and online services

Python IDLE
Arduino IDE
Arduino IDE

Story

Read more

Code

switches.ino

C/C++
The Arduino Code
int pulsante1 = 2;
int pulsante2 = 9;
int button1stato = 0;
int button2stato = 0;
int valorepotenziometro = 0;

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  pinMode(pulsante1, INPUT);
  pinMode(pulsante2, INPUT);
  pinMode(LED_BUILTIN, OUTPUT);

}

void loop() {
  button1stato = digitalRead(pulsante1);
  button2stato = digitalRead(pulsante2);
  valorepotenziometro = analogRead(A7);
  
  if(button1stato == HIGH){
    Serial.println("sx");
    digitalWrite(LED_BUILTIN, HIGH);
    delay(200);
  }
  if(button2stato == HIGH){
    Serial.println("dx");
    digitalWrite(LED_BUILTIN, LOW);
    delay(200);
  }

}

commands.py

Python
The Python Code
import serial
import pyautogui
import time

arduino = "dx"
arduino2 = "sx"

ser = serial.Serial('COM45', 9600)
time.sleep(1)

while True:
    val = ser.readline().strip()
    if(val == arduino):
        pyautogui.click()
    if(val == arduino2):
        pyautogui.rightClick()

if __name__ == "__main__":
	main()


    

Credits

fmattiussi
5 projects • 2 followers
Contact

Comments

Please log in or sign up to comment.