/* File Name: Dinsmore1 Date Started: 3/24/13 Compass: Dinsmore 1490 Digital Compass Program Description: Dinsmore compass sends LOWS to Arduino board that prints compass direction to the serial monitor. */ const int compassOut1 = 2; // assign name "compassOut1" to Pin 2 const int compassOut2 = 3; // assign name "compassOut2" to Pin 3 const int compassOut3 = 4; // assign name "compassOut3" to Pin 4 const int compassOut4 = 5; // assign name "compassOut4" to Pin 5 int compassOut1State = 0; // create variable "compassOut1State", // whose value is 0, and whose // type is int. int compassOut2State = 0; int compassOut3State = 0; int compassOut4State = 0; void setup() { Serial.begin(9600); pinMode(compassOut1, INPUT); // initialize the compassOut1 pin // as an input pinMode(compassOut2, INPUT); pinMode(compassOut3, INPUT); pinMode(compassOut4, INPUT); } void loop() { compassOut1State = digitalRead(compassOut1); // read the state of // compassOut1 compassOut2State = digitalRead(compassOut2); compassOut3State = digitalRead(compassOut3); compassOut4State = digitalRead(compassOut4); // Check states of each compass output and send compass bearing to serial monitor. if (compassOut1State == LOW & compassOut2State == HIGH & compassOut3State == HIGH & compassOut4State == HIGH) { Serial.println("N"); } if (compassOut1State == LOW & compassOut2State == LOW & compassOut3State == HIGH & compassOut4State == HIGH) { Serial.println("NE"); } if (compassOut1State == HIGH & compassOut2State == LOW & compassOut3State == HIGH & compassOut4State == HIGH) { Serial.println("E"); } if (compassOut1State == HIGH & compassOut2State == LOW & compassOut3State == LOW & compassOut4State == HIGH) { Serial.println("SE"); } if (compassOut1State == HIGH & compassOut2State == HIGH & compassOut3State == LOW & compassOut4State == HIGH) { Serial.println("S"); } if (compassOut1State == HIGH & compassOut2State == HIGH & compassOut3State == LOW & compassOut4State == LOW) { Serial.println("SW"); } if (compassOut1State == HIGH & compassOut2State == HIGH & compassOut3State == HIGH & compassOut4State == LOW) { Serial.println("W"); } if (compassOut1State == LOW & compassOut2State == HIGH & compassOut3State == HIGH & compassOut4State == LOW) { Serial.println("NW"); } delay(500); // pause program 500 ms }