Moved Moppy to a containing folder

This commit is contained in:
Sam Archer 2011-10-08 14:24:45 -07:00
parent b06bf0e3cc
commit 9728c2992c
2 changed files with 50 additions and 7 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
/Java/MoppyDesk/nbproject/private/
/Java/MoppyDesk/build/

View File

@ -1,18 +1,38 @@
boolean firstRun = true; // Used for one-run-only stuffs; boolean firstRun = true; // Used for one-run-only stuffs;
//First pin being used for floppies, and the last pin. Used for looping over all pins.
const byte FIRST_PIN = 2; const byte FIRST_PIN = 2;
const byte PIN_MAX = 9; const byte PIN_MAX = 9;
/*NOTE: Many of the arrays below contain unused indexes. This is
to prevent the Arduino from having to convert a pin input to an alternate
array index and save as many cycles as possible. In other words information
for pin 2 will be stored in index 2, and information for pin 4 will be
stored in index 4.*/
/*An array of maximum track positions for each step-control pin. Even pins
are used for control, so only even numbers need a value here. 3.5" Floppies have
80 tracks, 5.25" have 50 (use 79 and 49).
*/
byte MAX_POSITION[] = { byte MAX_POSITION[] = {
0,0,79,0,79,0,79,0,49,0}; 0,0,79,0,79,0,79,0,79,0};
//Array to track the current position of each floppy head. (Only even indexes (i.e. 2,4,6...) are used)
byte currentPosition[] = { byte currentPosition[] = {
0,0,0,0,0,0,0,0,0,0}; 0,0,0,0,0,0,0,0,0,0};
//Array to keep track of the direction for each floppy head. (Only even indexes are used)
boolean stepDirection[] = { boolean stepDirection[] = {
false,false,false,false,false,false,false,false,false,false}; // false = forward, true=reverse (i.e. true=HIGH) false,false,false,false,false,false,false,false,false,false}; // false = forward, true=reverse (i.e. true=HIGH)
//Current period assigned to each pin. 0 = off.
unsigned int currentPeriod[] = { unsigned int currentPeriod[] = {
0,0,0,0,0,0,0,0,0,0 0,0,0,0,0,0,0,0,0,0
}; };
//Setup pins (Even-odd pairs for step control and direction
void setup(){ void setup(){
pinMode(13, OUTPUT);// Pin 13 has an LED connected on most Arduino boards pinMode(13, OUTPUT);// Pin 13 has an LED connected on most Arduino boards
pinMode(2, OUTPUT); // Step control 1 pinMode(2, OUTPUT); // Step control 1
@ -29,15 +49,18 @@ void setup(){
void loop(){ void loop(){
//The first loop, reset all the drives, and wait 2 seconds...
if (firstRun) if (firstRun)
{ {
firstRun = false; firstRun = false;
resetAll(); resetAll();
delay(2000); delay(2000);
//runOnce();
} }
//Only read if we have
if (Serial.available() > 2){ if (Serial.available() > 2){
//Watch for special 100-message to reset the drives
if (Serial.peek() == 100) { if (Serial.peek() == 100) {
resetAll(); resetAll();
Serial.flush(); Serial.flush();
@ -50,6 +73,10 @@ void loop(){
voice(); voice();
} }
/*
The voice() method controls WHEN each pin will be stepped by mod'ing the Arduino system-clock
against the currentPeriod for each pin. A period of 0 will skip the pin (i.e. pin is off)
*/
void voice() void voice()
{ {
if (currentPeriod[2] > 0 && micros()%currentPeriod[2] < 100){ if (currentPeriod[2] > 0 && micros()%currentPeriod[2] < 100){
@ -66,32 +93,45 @@ void voice()
} }
} }
void stepPin(byte pin, byte control_pin, byte wait) { /*
The stepPin() method controls the actual stepping of each pin. It uses the
stepDireciton array to determine the state of the direction_pin, and will automatically
reverse the direction when needed.
*/
void stepPin(byte pin, byte direction_pin, byte wait) {
//Switch directions if end has been reached
if (currentPosition[pin] >= MAX_POSITION[pin]) { if (currentPosition[pin] >= MAX_POSITION[pin]) {
stepDirection[pin] = true; stepDirection[pin] = true;
} }
if (currentPosition[pin] <= 0) { else if (currentPosition[pin] <= 0) {
stepDirection[pin] = false; stepDirection[pin] = false;
} }
//Set direction_pin state, and update currentPosition
if (stepDirection[pin]){ if (stepDirection[pin]){
digitalWrite(control_pin,HIGH); digitalWrite(direction_pin,HIGH);
currentPosition[pin]--; currentPosition[pin]--;
} }
else { else {
digitalWrite(control_pin,LOW); digitalWrite(direction_pin,LOW);
currentPosition[pin]++; currentPosition[pin]++;
} }
//Pulse the control pin
digitalWrite(pin,HIGH); digitalWrite(pin,HIGH);
delayMicroseconds(wait); delayMicroseconds(wait);
digitalWrite(pin,LOW); digitalWrite(pin,LOW);
} }
//Not used now, but good for debugging...
void blinkLED(){ void blinkLED(){
digitalWrite(13, HIGH); // set the LED on digitalWrite(13, HIGH); // set the LED on
delay(250); // wait for a second delay(250); // wait for a second
digitalWrite(13, LOW); digitalWrite(13, LOW);
} }
//For a given controller pin, runs the read-head all the way back to 0
void reset(byte pin) void reset(byte pin)
{ {
digitalWrite(pin+1,HIGH); // Go in reverse digitalWrite(pin+1,HIGH); // Go in reverse
@ -104,6 +144,7 @@ void reset(byte pin)
stepDirection[pin] = false; // Ready to go forward. stepDirection[pin] = false; // Ready to go forward.
} }
//Resets all the pins
void resetAll(){ void resetAll(){
for (byte p=FIRST_PIN;p<=PIN_MAX;p+=2){ for (byte p=FIRST_PIN;p<=PIN_MAX;p+=2){
reset(p); reset(p);