int switchValue, xValue, yValue; //declare variables
void setup(){
pinMode(9,OUTPUT); //initialize the motorIn1 pin as output
pinMode(10,OUTPUT); //initialize the motorIn2 pin as output
pinMode(2, INPUT);
digitalWrite(2, HIGH);
Serial.begin(9600);
}
void loop(){
switchValue=digitalRead(2); //read the button
xValue=analogRead(A0); //read x-axis
yValue=analogRead(A1); //read y-axis
Serial.print("Switch: ");
Serial.println(switchValue);
Serial.print("X-axis: ");
Serial.println(xValue);
Serial.print("Y-axis: ");
Serial.println(yValue);
Serial.print("\n\n");
if(switchValue==0){
analogWrite(9,255); // Turn the motor on clockwise, full speed (255)
analogWrite(10,0); //
}
else{
analogWrite(9,0); //Turn the motor off
analogWrite(10,0); //
}
}