// Define pins for the vibration motors
const int motor1 = 3;
const int motor2 = 5;
const int motor3 = 7;
const int motor4 = 9;
// Define the duration and frequency of vibration bursts
const int vibrationDuration = 100; // Duration of each vibration burst in milliseconds
const int baseInterval = 667; // Base interval between bursts in milliseconds
const float jitterFactor = 0.235; // Jitter factor for variability in the interval
// Function to deliver a single vibratory burst to a specific motor
void vibrateMotor(int motorPin) {
digitalWrite(motorPin, HIGH);
delay(vibrationDuration);
digitalWrite(motorPin, LOW);
}
// Function to add jitter to the interval
int addJitter(int baseInterval) {
float jitter = random(-baseInterval * jitterFactor, baseInterval * jitterFactor + 1);
return baseInterval + jitter;
}
void setup() {
// Initialize the motor pins as outputs
pinMode(motor1, OUTPUT);
pinMode(motor2, OUTPUT);
pinMode(motor3, OUTPUT);
pinMode(motor4, OUTPUT);
// Initialize serial communication for debugging
Serial.begin(9600);
}
void loop() {
// vCR sequence (3:2 ON-OFF pattern)
for (int i = 0; i < 3; i++) { // Three ON cycles
vibrateMotor(motor1);
delay(addJitter(baseInterval));
vibrateMotor(motor2);
delay(addJitter(baseInterval));
vibrateMotor(motor3);
delay(addJitter(baseInterval));
vibrateMotor(motor4);
delay(addJitter(baseInterval));
}
// Two OFF cycles (pauses)
delay(2 * baseInterval);
// Short delay before the next 3:2 cycle
delay(baseInterval);
}