These are the lines of code that are run at startup:
void FloppyDrives::setup() {
// Prepare pins (0 and 1 are reserved for Serial communications)
pinMode(2, OUTPUT); // Step control 1
pinMode(3, OUTPUT); // Direction 1
pinMode(4, OUTPUT); // Step control 2
pinMode(5, OUTPUT); // Direction 2
pinMode(6, OUTPUT); // Step control 3
pinMode(7, OUTPUT); // Direction 3
pinMode(8, OUTPUT); // Step control 4
pinMode(9, OUTPUT); // Direction 4
pinMode(10, OUTPUT); // Step control 5
pinMode(11, OUTPUT); // Direction 5
pinMode(12, OUTPUT); // Step control 6
pinMode(13, OUTPUT); // Direction 6
pinMode(14, OUTPUT); // Step control 7
pinMode(15, OUTPUT); // Direction 7
pinMode(16, OUTPUT); // Step control 8
pinMode(17, OUTPUT); // Direction 8
// With all pins setup, let's do a first run reset
resetAll();
delay(500); // Wait a half second for safety
// Setup timer to handle interrupts for floppy driving
MoppyTimer::initialize(TIMER_RESOLUTION, tick);
// If MoppyConfig wants a startup sound, play the startupSound on the
// first drive.
if (PLAY_STARTUP_SOUND) {
startupSound(FIRST_DRIVE);
startupSound(2);
startupSound(3);
startupSound(4);
startupSound(5);
startupSound(6);
startupSound(7);
startupSound(8);
delay(500);
resetAll();
}
}
With resetAll() being:
void FloppyDrives::resetAll()
{
DDRF |= (1 << PF6) | ( 1 << PF7) | ( 1 << PF4) | ( 1 << PF5);
// Stop all drives and set to reverse
for (byte d=FIRST_DRIVE;d<=LAST_DRIVE;d++) {
byte stepPin = d * 2;
currentPeriod[d] = 0;
digitalWrite(stepPin+1,HIGH);
}
// Reset all drives together
for (unsigned int s=0;s<MAX_POSITION[0];s+=2){ //Half max because we're stepping directly (no toggle); grab max from index 0
for (byte d=FIRST_DRIVE;d<=LAST_DRIVE;d++) {
byte stepPin = d * 2;
digitalWrite(stepPin,HIGH);
digitalWrite(stepPin,LOW);
}
delay(5);
}
// Return tracking to ready state
for (byte d=FIRST_DRIVE;d<=LAST_DRIVE;d++) {
byte stepPin = d * 2;
currentPosition[d] = 0; // We're reset.
currentState[stepPin] = LOW;
digitalWrite(stepPin+1,LOW);
stepPin = d*2;
currentState[stepPin+1] = LOW; // Ready to go forward.
setMovement(d, true); // Set movement to true by default
}
}
And startupSound(); being:
void FloppyDrives::startupSound(byte driveNum) {
unsigned int chargeNotes[] = {
noteDoubleTicks[31],
noteDoubleTicks[36],
noteDoubleTicks[38],
noteDoubleTicks[43],
0
};
byte i = 0;
unsigned long lastRun = 0;
while(i < 5) {
if (millis() - 200 > lastRun) {
lastRun = millis();
currentPeriod[driveNum] = chargeNotes[i++];
}
}
}