// Simple Hard Sector Floppy Emulator // TAS 02/21/21 // for Adafruit Metro Mini // 4ms (4000us) index pulse width - matches 5.25" 10 sector floppy // sector delay in two parts to guarantee delay < 16383us // loop overhead estimated at 125us, verified empirically // constants won't change. They're used here to set pin numbers: const int SS_ix_in = 4; const int HS_ix_out = 5; const int idx_width = 4000; const int loop_oh = 125; const int sec_delay = 20000 - loop_oh - idx_width - 10000; const int idx_delay = (20000 - loop_oh - 2*idx_width)/2; // Variables will change: bool index_state = HIGH; int rotary = 0; void setup() { Serial.begin(9600); Serial.println("Arduino HSFE"); pinMode(SS_ix_in, INPUT_PULLUP); pinMode(HS_ix_out, OUTPUT); digitalWrite(HS_ix_out, HIGH); } void loop() { wait_for_index(); index_pulse(); delayMicroseconds(idx_delay); index_pulse(); delayMicroseconds(idx_delay); for (int i = 0; i < 8; i ++) { index_pulse(); delayMicroseconds(10000); delayMicroseconds(sec_delay); } // no programmed delay after last sector pulse this rotation // program will wait for next index pulse index_pulse(); } void wait_for_index() { index_state=HIGH; while (index_state == HIGH) { index_state=digitalRead(SS_ix_in); } } void index_pulse() { digitalWrite(HS_ix_out,LOW); delayMicroseconds(idx_width); digitalWrite(HS_ix_out, HIGH); }