Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int motorPin = 2;
- int directionPin = 4;
- int stepPin = 5;
- int trackZeroPin = 8;
- int indexPin = 1;
- int driveSelPin = 3;
- int writeDataPin = 6;
- int writeEnablePin = 7;
- int writeProtectPin = 9;
- int headSelectPin = 11;
- int readDataPin = 10;
- int diskReadyPin = 12;
- ////////////////////////
- int currentTrack = 0;
- int trackContor = 0;
- int tmpVec[500];
- int vecCont = 0;
- int onThisTrack = 0;
- int zeros = 0;
- int ones = 0;
- int onesArray[30];
- int zerosArray[30];
- ////////////////////////
- void setup()
- {
- pinMode(motorPin,OUTPUT);
- pinMode(directionPin,OUTPUT);
- pinMode(stepPin,OUTPUT);
- pinMode(driveSelPin,OUTPUT);
- pinMode(writeEnablePin,OUTPUT);
- pinMode(writeDataPin,OUTPUT);
- pinMode(trackZeroPin,INPUT_PULLUP);
- pinMode(indexPin,INPUT_PULLUP);
- pinMode(readDataPin,INPUT_PULLUP);
- pinMode(writeProtectPin,INPUT_PULLUP);
- pinMode(diskReadyPin,INPUT_PULLUP);
- Serial.begin(9600);
- driveEnable();
- motorDisable();
- jiggle();
- jumpOutermost();
- motorEnable();
- execute();
- writeDisable();
- }
- int data = 1;
- void loop()
- {
- Serial.print(readDataRaw());
- // writeDisable();
- // if (currentTrack<30)
- // {
- // if (hasIndexPulsed())
- // {
- // onThisTrack++;
- // if (onThisTrack>=3)
- // {
- // onThisTrack = 0;
- // onesArray[currentTrack]=ones;
- // zerosArray[currentTrack]=zeros;
- // stepIn();
- // ones = 0;
- // zeros = 0;
- // }
- // }
- // else
- // {
- // if (readDataRaw()==HIGH)
- // {
- // ones++;
- // }
- // else
- // {
- // zeros++;
- // }
- // }
- // }
- // else
- // {
- //
- // motorDisable();
- // for (int i=0;i<currentTrack;i++)
- // {
- // Serial.println(String(i)+" "+String(onesArray[i])+" "+String(zerosArray[i])+" "+(onesArray[i] - zerosArray[i]));
- // delay(100);
- // }
- // jumpOutermost();
- // currentTrack = 0;
- // motorEnable();
- // }
- // writeEnable();
- // if (currentTrack<30)
- // {
- // if (hasIndexPulsed())
- // {
- // onThisTrack++;
- // if (onThisTrack>=3)
- // {
- // onThisTrack = 0;
- //
- // stepIn();
- // }
- // }
- // else
- // {
- // setWriteData(data);
- // data = 1 - data;
- // }
- // }
- // else
- // {
- // jumpOutermost();
- // currentTrack = 0;
- // }
- }
- void execute()
- {
- // int Data = 1;
- // motorEnable();
- // writeEnable();
- //
- // LoopB:
- // if (readIndex()==0) goto LoopB;
- // LoopC:
- // if (readIndex()==1) goto LoopC;
- // LoopD:
- // setWriteData(0);
- // if (readIndex()==0) goto LoopD;
- //
- // LoopE:
- // if (readIndex()==1) goto LoopE;
- // stepIn();
- // if (currentTrack<40) goto LoopD;
- //
- // writeDisable();
- // for (int i=1;i<=currentTrack;i++)
- // {
- // stepOut();
- // }
- // int data = 0;
- // writeDisable();
- // LoopB:
- // if (readIndex()==0) goto LoopB;
- // LoopC:
- // if (readIndex()==1) goto LoopC;
- //
- // LoopD:
- // data = readData();
- // if (vecCont<499)
- // {
- // tmpVec[vecCont++] = data;
- // }
- // if (readIndex()==LOW) goto LoopD;
- // LoopE:
- // if (readIndex()==HIGH) goto LoopE;
- //
- // stepIn();
- // if (currentTrack<10) goto LoopD;
- //
- // for (int i=0;i<vecCont;i++)
- // {
- // Serial.print(tmpVec[vecCont]);
- // delay(20);
- // }
- }
- ////////////////////////////////////////////////
- int jumpToTrack(int track)
- {
- if (track<84)
- {
- if (track>currentTrack)
- {
- int steps = track-currentTrack;
- for (int i=1;i<=steps;i++)
- {
- stepIn();
- }
- }
- else if (track<currentTrack)
- {
- int steps = currentTrack-track;
- for (int i=1;i<=steps;i++)
- {
- stepOut();
- }
- }
- }
- }
- int stepOut()
- {
- digitalWrite(directionPin,HIGH);
- digitalWrite(stepPin,LOW);
- delayMicroseconds(1);
- digitalWrite(stepPin,HIGH);
- delayMicroseconds(3000);
- currentTrack-=1;
- }
- int stepIn()
- {
- digitalWrite(directionPin,LOW);
- digitalWrite(stepPin,LOW);
- delayMicroseconds(1);
- digitalWrite(stepPin,HIGH);
- delayMicroseconds(3000);
- currentTrack+=1;
- }
- int readTrackZero()
- {
- return digitalRead(trackZeroPin);
- }
- int readIndex()
- {
- return digitalRead(indexPin);
- }
- int readDataRaw()
- {
- return digitalRead(readDataPin);
- }
- int lastData = LOW;
- int readData()
- {
- int curData = readDataRaw();
- if (curData == LOW && lastData == HIGH)
- {
- lastData = curData;
- return 1;
- }
- else
- {
- lastData = curData;
- return 0;
- }
- }
- int readDiskReady()
- {
- return digitalRead(diskReadyPin);
- }
- int motorEnable()
- {
- digitalWrite(motorPin,LOW);
- }
- int motorDisable()
- {
- digitalWrite(motorPin,HIGH);
- }
- int jumpOutermost()
- {
- while (readTrackZero()==HIGH)
- {
- stepOut();
- }
- }
- int jiggle()
- {
- stepIn();
- stepOut();
- }
- int driveEnable()
- {
- digitalWrite(driveSelPin,LOW);
- }
- int driveDisable()
- {
- digitalWrite(driveSelPin,HIGH);
- }
- int lastIndex = LOW;
- int hasIndexPulsed()
- {
- int curIndex = readIndex();
- if (curIndex == LOW && lastIndex == HIGH)
- {
- lastIndex = curIndex;
- return 1;
- }
- else
- {
- lastIndex = curIndex;
- return 0;
- }
- }
- int isWriteProtected()
- {
- if (digitalRead(writeProtectPin)==LOW)
- {
- return 1;
- }
- else
- {
- return 0;
- }
- }
- int writeEnable()
- {
- digitalWrite(writeEnablePin,HIGH);
- }
- int writeDisable()
- {
- digitalWrite(writeEnablePin,LOW);
- }
- int setWriteData(int data)
- {
- digitalWrite(writeDataPin,data);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement