Commits

Leigh Honeywell committed 9ab5dda

working with 4 LEDs and shift register, buzzer still not implemented.

Comments (0)

Files changed (1)

 Hmc6352 hmc6352;
 
 int buzzerPin = 3;
-int ledPin1 =  6;    // LED connected to digital pin 13
-int ledPin2 =  9;
-int ledPin3 = 10;
-int ledPin4 = 11;
+
+//Pin connected to latch pin (ST_CP) of 74HC595
+const int latchPin = 8;
+//Pin connected to clock pin (SH_CP) of 74HC595
+const int clockPin = 12;
+////Pin connected to Data in (DS) of 74HC595
+const int dataPin = 11;
+
 int heading =  3;
 
 // The setup() method runs once, when the sketch starts
  
   // initialize the digital pin as an output:
   pinMode(buzzerPin, OUTPUT);
-  pinMode(ledPin1, OUTPUT);
-  pinMode(ledPin2, OUTPUT);
-  pinMode(ledPin3, OUTPUT);
-  pinMode(ledPin4, OUTPUT);
   analogWrite(buzzerPin, LOW);
-  digitalWrite(ledPin1, LOW);
-  digitalWrite(ledPin2, LOW);
-  digitalWrite(ledPin3, LOW);
-  digitalWrite(ledPin4, LOW);
+  
+  //set pins to output because they are addressed in the main loop
+  pinMode(latchPin, OUTPUT);
+  pinMode(dataPin, OUTPUT);  
+  pinMode(clockPin, OUTPUT);
+
 }
 
 // the loop() method runs over and over again,
   heading = (int)(heading / 90);
   Serial.print(heading,DEC);
   Serial.print(" comparison\r\n");
-  switch (heading) { 
-  case 0:
-    digitalWrite(ledPin1, HIGH);   // set the LED on
-    delay(100);                  // wait for a second
-    digitalWrite(ledPin1, LOW);    // set the LED off
-    break;
-  case 1:
-    digitalWrite(ledPin2, HIGH);   // set the LED on
-    delay(100);                  // wait for a second
-    digitalWrite(ledPin2, LOW);    // set the LED off
-    break;
-  case 2:
-    digitalWrite(ledPin3, HIGH);   // set the LED on
-    delay(100);                  // wait for a second
-    digitalWrite(ledPin3, LOW);    // set the LED off
-    break;
-  case 3:
-    digitalWrite(ledPin4, HIGH);   // set the LED on
-    delay(100);                 // wait for a second
-    digitalWrite(ledPin4, LOW);    // set the LED off
-    break;
-  default:
-    digitalWrite(buzzerPin, HIGH);
-    delay(100);
-    digitalWrite(buzzerPin, LOW);
-    break;
+  // ASCII '0' through '9' characters are
+  // represented by the values 48 through 57.
+  // so if the user types a number from 0 through 9 in ASCII, 
+  // you can subtract 48 to get the actual value:
+  int bitToSet = heading + 1;
+  
+  // write to the shift register with the correct bit set high:
+  registerWrite(bitToSet, HIGH);
   }
+
+// This method sends bits to the shift register:
+void registerWrite(int whichPin, int whichState) {
+// the bits you want to send
+  byte bitsToSend = 0;
+
+  // turn off the output so the pins don't light up
+  // while you're shifting bits:
+  digitalWrite(latchPin, LOW);
+
+  // turn on the next highest bit in bitsToSend:
+  bitWrite(bitsToSend, whichPin, whichState);
+
+  // shift the bits out:
+  shiftOut(dataPin, clockPin, MSBFIRST, bitsToSend);
+
+    // turn on the output so the LEDs can light up:
+  digitalWrite(latchPin, HIGH);
 }
+
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.