I want void 'move _forward' to repeat three times when I press the button in the android app. How should I change the blocks?
This is the sketch:
#include "HCPCA9685.h"
#include <BluetoothSerial.h>
BluetoothSerial BT;
char state=0;
/* I2C slave address for the device/module. For the HCMODU0097 the default I2C address
is 0x40 */
#define I2CAdd_1 0x40
#define I2CAdd_2 0x41
int pos1 = 200;
int pos2 = 220;
int pos3 = 180;
int pos4 = 0;
int pos5 = 130;
int pos6 = 100;
int pos7=50;
int pos8=260;
int pos9=140;
int delay1;
int delay2 = 500;
/* Create an instance of the library */
HCPCA9685 HCPCA9685_1(I2CAdd_1);
HCPCA9685 HCPCA9685_2(I2CAdd_2);
void setup() {
/* Initialise the library and set it to 'servo mode' */
// Initialise both modules
HCPCA9685_1.Init(SERVO_MODE);
HCPCA9685_2.Init(SERVO_MODE);
// Wake both devices up
HCPCA9685_1.Sleep(false);
HCPCA9685_2.Sleep(false);
unsigned int Pos;
Serial.begin(9600);
BT.begin(9600);
}
/* Move Forward */
void move_forward() {
for (int Pos = pos5 ; Pos >= pos7 ; Pos--) {
HCPCA9685_1.Servo(1, Pos);
HCPCA9685_1.Servo(7, Pos);
HCPCA9685_1.Servo(13, Pos);
delay(delay1);
}
}
/* Move Backward */
void move_backward() {
for (int PosC = pos3 , PosD = pos2 ; PosC <= pos2 || PosD >= pos3 ; PosC++ , PosD--) {
HCPCA9685_1.Servo(0, PosC);
HCPCA9685_1.Servo(3, PosD);
HCPCA9685_1.Servo(6, PosC);
HCPCA9685_1.Servo(9, PosC);
HCPCA9685_1.Servo(12, PosD);
HCPCA9685_1.Servo(15, PosC);
delay(delay1);
}
}
/* Turn Right */
void turn_right() {
for (int PosC = pos2 , PosD = pos3 ; PosC >= pos3 || PosD <= pos2 ; PosC-- , PosD++) {
HCPCA9685_1.Servo(0, PosD);
HCPCA9685_1.Servo(6, PosD);
HCPCA9685_1.Servo(12, PosD);
delay(delay1);
}
}
/* Turn Left */
void turn_left() {
for (int Pos = pos7 ; Pos <= pos5 ; Pos++) {
HCPCA9685_1.Servo(4, Pos);
HCPCA9685_1.Servo(10, Pos);
HCPCA9685_2.Servo(0, Pos);
delay(1);
}
}
/* Stop Move */
void move_stop() {
}
void loop() {
if (BT.available() >0) {
int ch = BT.read();
switch(ch){
case 250: move_forward(); break;
case 260: turn_right(); break;
case 270: turn_left(); break;
}
Serial.print(ch);
// }
}
}
This is the block: