Hi all,
I am trying to build a floppy disk, controlled by Pure Data. I'm new to Arduino and quite experienced in Pure Data.
Based on code fragments found on this forum, I have created working code:
#define Dir 3
#define Step 6
#define Sel 4
int incomingByte = 0;
void setup() {
Serial.begin(9600); // opens serial port, sets data rate to 9600 bps
pinMode(Dir, OUTPUT);
pinMode(Step, OUTPUT);
pinMode(Sel, OUTPUT);
digitalWrite(Sel, HIGH);
initHead(); // move header half way
}
void initHead() {
digitalWrite(Step, HIGH);
digitalWrite(Dir, HIGH);
doSteps(80, 1911); // move header to start position wherever it is, 80 steps at ~261 step/s
digitalWrite(Dir, LOW);
doSteps(40, 1911);
delay(1000);
}
void doSteps(int steps, int stepDelay) {
digitalWrite(Sel, LOW);
for(int i=0;i<steps; i++) {
digitalWrite(Step,LOW);
delayMicroseconds(stepDelay);
digitalWrite(Step,HIGH);
delayMicroseconds(stepDelay);
}
digitalWrite(Sel, HIGH);
}
void vibe(int count, int period) {
for(int l=0;l<count; l++) {
digitalWrite(Dir, HIGH);
doSteps(1, period);
digitalWrite(Dir, LOW);
doSteps(1, period);
}
}
void loop() {
if (Serial.available()>0) {
incomingByte=Serial.read();
digitalWrite(Step, incomingByte);
vibe(30, 3823); //D
vibe(35, 3214);
vibe(40, 2552);
}
}
By sending any number from PD, it runs a sequence of three sounds.
vibe (30, 3823);
vibe (35, 3214);
vibe (40, 2552);
(d minor, BTW)
I just need to find a way to send a specific number from PD to run a specific line of code, rather than all at once.
Thanks in advance for your help!