I can fully control single FDD. When send "20" by object "comport" from the PD then run a line of code:
if (incomingByte == 20) vibe (40, 4291);
and so on
My problem is that I connected two FDD and I would like to have played two different sounds simultaneously that is run two commands at once. Unfortunately, it works like this:
- 20 launches drive A
- 30 launches both drives, despite the fact that should work only drive B
- 20 and 30 simultaneously - launches first drive A and B after a long delay
I Make a mistake somewhere, but I do not understand where.
Arduino code:
/*
SETTINGS
*/
#define StepA 2
#define DirA 3
#define SelA 4
#define StepB 5
#define DirB 6
#define SelB 7
int incomingByte = 0;
/*
START
*/
void setup() {
Serial.begin(9600); // opens serial port, sets data rate to 9600 bps
pinMode(DirA, OUTPUT);
pinMode(StepA, OUTPUT);
pinMode(SelA, OUTPUT);
digitalWrite(SelA, HIGH);
pinMode(DirB, OUTPUT);
pinMode(StepB, OUTPUT);
pinMode(SelB, OUTPUT);
digitalWrite(SelB, HIGH);
initHead(); // move header half way
}
void initHead() {
digitalWrite(StepA, HIGH);
digitalWrite(DirA, HIGH);
doSteps(80, 1911); // move header to start position wherever it is, 80 steps at ~261 step/s
digitalWrite(DirA, LOW);
doSteps(40, 1911);
digitalWrite(StepB, HIGH);
digitalWrite(DirB, HIGH);
doSteps(80, 1911); // move header to start position wherever it is, 80 steps at ~261 step/s
digitalWrite(DirB, LOW);
doSteps(40, 1911);
}
void doSteps(int steps, int stepDelay) {
digitalWrite(SelA, LOW);
for(int i=0;i<steps; i++) {
digitalWrite(StepA,LOW);
delayMicroseconds(stepDelay);
digitalWrite(StepA,HIGH);
delayMicroseconds(stepDelay);
digitalWrite(StepB,LOW);
delayMicroseconds(stepDelay);
digitalWrite(StepB,HIGH);
delayMicroseconds(stepDelay);
}
digitalWrite(SelA, HIGH);
}
/*
VIBE VIBE VIBE
*/
void vibeA(int count, int period) {
for(int l=0;l<count; l++) {
digitalWrite(DirA, HIGH);
doSteps(1, period);
digitalWrite(DirA, LOW);
doSteps(1, period);
}
}
void vibeB(int count, int period) {
for(int l=0;l<count; l++) {
digitalWrite(DirB, HIGH);
doSteps(1, period);
digitalWrite(DirB, LOW);
doSteps(1, period);
}
}
/*
FIRST FDD
*/
void loop() {
if (Serial.available()>0) {
incomingByte=Serial.read();
if (incomingByte == 20) vibeA(40, 4291); //C
if (incomingByte == 21) vibeA(40, 4050);
if (incomingByte == 22) vibeA(40, 3823);
if (incomingByte == 23) vibeA(40, 3609);
/*
SECOND FDD
*/
if (incomingByte == 30) vibeB(40, 4291); //C
if (incomingByte == 31) vibeB(40, 4050);
if (incomingByte == 32) vibeB(40, 3823);
if (incomingByte == 33) vibeB(40, 3609);
}
}