control for robotic arm that can play chess using a granular gripper

Dependencies:   Encoder mbed HIDScope Servo MODSERIAL

Fork of chessRobot by a steenbeek

Revision:
32:2006977785f5
Parent:
30:a20f16bf8dda
Child:
34:f315b2b38555
--- a/buttons.cpp	Wed Oct 07 15:09:52 2015 +0200
+++ b/buttons.cpp	Wed Oct 07 20:55:28 2015 +0200
@@ -7,18 +7,69 @@
 AnalogIn pot2(pot2Pin);
 AnalogIn pot1(pot1Pin);
 
+// Led states: 	
+// 	0 leds: motors disabled
+//	led1: 	control X speed
+//	led2:	control Y speed
+//	led1&led2: control Servo pos
+AnalogOut led1(led1Pin);
+AnalogOut led2(led2Pin);
+
+AnalogIn button1(button1Pin);
+AnalogIn button2(button2Pin);
+int prevState1 = 0;
+int prevState2 = 0;
+int actuatorState = 0;
+
+
 void checkSwitches(){
-    // read motor enable switch
-    
-    // read pump enable switch
-    
-    // read servo potmeter position
-    
-    // read x speed potmeter position
-        motorSetSpeed2 = 300*pot2.read();
-    
-    // read y speed potmeter position
-        motorSetSpeed2 = motorSetSpeed2 - 300*pot1.read();
-    // read killswitches
-    
-    }
\ No newline at end of file
+
+	// 3 states: X control, Y control en Servo control
+	//	 button 1 to enable/disable actuators
+	// 	 button 2 to switch between states
+
+	if(button1 !=0 && prevState1 == 0){
+		button1Pressed();
+	}
+	if(button2 !=0 && prevState2 ==0){
+		button2Pressed();
+	}
+	prevState1 = button1;
+	prevState2 = button2;
+
+    pot1Val = pot1.read();
+    pot2Val = pot2.read();
+
+    if(motorsEnable){
+    	switch (actuatorState){
+        	case 0: 				// potmeters control X speed
+        		led1 = 1; led2=0;
+        		motorSetSPeed1 = 300*(pot2.read()-pot1.read());
+        		break;
+        	case 1:         		// potmeters control Y speed
+        		led1=0; led2=1;
+        		motorSetSpeed2 = 300*(pot2.read()-pot1.read());
+        		break;
+        	case 2:         		// potmeters control Servo pos
+        		led1=1; led2=1;
+        		servoPos = pot2.read();
+        		break;
+        }
+    }else{
+    	led1=0; led2=0;
+    }
+    motorSetSpeed2 = motorSetSpeed2 - 300*pot1.read();
+   }
+
+
+void button1Pressed(){
+	motorEnable = !motorEnable;
+}
+
+void button2Pressed(){
+	actuatorState++;
+	if(actuatorState=3){
+		actuatorState = 0;
+	}
+
+}
\ No newline at end of file