44 Gripper(
byte idPin,
byte in1Pin,
byte in2Pin,
byte pwmPin,
byte standbyPin,
45 byte gripperOpenPin,
byte gripperClosePin) :
50 fStandbyPin(standbyPin),
51 fGripperOpenPin(gripperOpenPin),
52 fGripperClosePin(gripperClosePin)
54 pinMode(fID, INPUT_PULLUP);
55 pinMode(fGripperOpenPin, INPUT_PULLUP);
56 pinMode(fGripperClosePin, INPUT_PULLUP);
57 pinMode(fIn1Pin, OUTPUT);
58 pinMode(fIn2Pin, OUTPUT);
59 pinMode(fPWMPin, OUTPUT);
60 pinMode(fStandbyPin, OUTPUT);
66 return !digitalRead(fID);
71 return !digitalRead(fGripperOpenPin);
76 return !digitalRead(fGripperClosePin);
109 if (fArmed && fCount == 0)
113 fCount = random(20, 40);
115 fNextTime = millis();
140 if (*cmd++ ==
'G' && *cmd++ ==
'P')
145 if (cmd[0] ==
'O' && cmd[1] ==
'N' && cmd[2] ==
'\0')
149 else if (cmd[0] ==
'O' && cmd[1] ==
'F' && cmd[2] ==
'F' && cmd[3] ==
'\0')
161 if (!fArmed || fDirection == 0)
163 uint32_t currentTime = millis();
164 if (fNextTime < currentTime)
166 fNextTime = currentTime + random(150,350);
169 fDirection = -fDirection;
183 fDirection = -fDirection;
189 fDirection = (fCount > 0) ? -fDirection : 0;
212 byte fGripperOpenPin;
213 byte fGripperClosePin;
219 void drive(
int speed)
221 digitalWrite(fStandbyPin, HIGH);
224 digitalWrite(fIn1Pin, HIGH);
225 digitalWrite(fIn2Pin, LOW);
226 analogWrite(fPWMPin, speed);
230 digitalWrite(fIn1Pin, LOW);
231 digitalWrite(fIn2Pin, HIGH);
232 analogWrite(fPWMPin, -speed);
238 digitalWrite(fIn1Pin, HIGH);
239 digitalWrite(fIn2Pin, HIGH);
240 analogWrite(fPWMPin, 0);
245 digitalWrite(fStandbyPin, LOW);