#include #include #include #include MeDCMotor motor_L(9); MeDCMotor motor_R(10); int buttonPressed() { return analogRead(A7) <= 10 ? 1 : 0; } void mBot_setMotorLeft(int8_t dir, int16_t speed) { speed = speed/100.0*255; motor_L.run((9) == M1 ? -(dir*speed) : (dir*speed)); } void mBot_setMotorRight(int8_t dir, int16_t speed) { speed = speed/100.0*255; motor_R.run((10) == M1 ? -(dir*speed) : (dir*speed)); } void setup() { pinMode(A7,INPUT); } void loop() { if (buttonPressed()) { mBot_setMotorRight(1, 25); mBot_setMotorLeft(1, 25); delay(1000*1); mBot_setMotorRight(-1, 25); mBot_setMotorLeft(-1, 25); delay(1000*1); mBot_setMotorRight(0, 0); mBot_setMotorLeft(0, 0); } }