I am trying to use the digital pins A0 and A2 instead of the digital pins 2 and 3 for my Arduino pro micro and GY-521 accelerometer module. I believe I need to change the coding but am not sure what to do. If anyone could help that would be amazing. Here is the existing code i am wanting to edit.
#include <Wire.h>
#include <MPU6050.h>
#include <Mouse.h>
MPU6050 mpu;
int16_t ax, ay, az, gx, gy, gz;
int vx, vy;
int button1 = 6;
int button2 = 7;
int buttonState1 = 0;
int buttonState2 = 0;
void setup() {
// initialize serial communications at 9600 bps:
Serial.begin(9600);
Wire.begin();
Mouse.begin();
// For versions prior to Arduino 1.0.1
// pinMode(buttonPin, INPUT);
// digitalWrite(buttonPin, HIGH);
// put your setup code here, to run once:
pinMode(button1, INPUT);
digitalWrite(button1, HIGH);
pinMode(button2, INPUT);
digitalWrite(button2, HIGH);
mpu.initialize();
if (!mpu.testConnection()) { while (1); }
}
void loop() {
mpu.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);
vx = -(gx+150)/150;
vy = (gy-150)/150;
Serial.print("gx = ");
Serial.print(gx);
Serial.print(" | gy = ");
Serial.print(gy);
Serial.print(" | X = ");
Serial.print(vx);
Serial.print(" | Y = ");
Serial.println(vy);
Mouse.move(vx, vy);
attachInterrupt(1, keyboard, CHANGE);
attachInterrupt(7,fire,HIGH);
if (digitalRead(button1) == HIGH) {
if (!Mouse.isPressed(MOUSE_LEFT)) {
Mouse.press(MOUSE_LEFT);
}
}
else {
if (Mouse.isPressed(MOUSE_LEFT)) {
Mouse.release(MOUSE_LEFT);
}
}
if (digitalRead(button2) == HIGH) {
if (!Mouse.isPressed(MOUSE_RIGHT)) {
Mouse.press(MOUSE_RIGHT);
}
}
else {
if (Mouse.isPressed(MOUSE_RIGHT)) {
Mouse.release(MOUSE_RIGHT);
}
}
delay(20);
vx = analogRead(vx);
vy = analogRead(vy);
buttonState1 = digitalRead(button1);
Serial.print("X: ");
Serial.print(vx);
Serial.print(" | Y: ");
Serial.print(vy);
Serial.print(" | Button: ");
Serial.println(buttonState1);
// delay(100); // add some delay between reads
}
void keyboard()
{
vx = analogRead(vx);
vy = analogRead(vy);
buttonState1 = digitalRead(button1);
Serial.print("X: ");
Serial.print(vx);
Serial.print(" | Y: ");
Serial.print(vy);
Serial.print(" | Button: ");
Serial.println(buttonState1);
//delay(100); // add some delay between reads
}
void fire()
{
}