Skittles Dispenser by Benjamin Kim and Alex Zdanov

Dependencies:   4DGL-uLCD-SE HC_SR04_Ultrasonic_Library LSM9DS1_Library_cal Servo mbed

Revision:
4:8952303a18be
Parent:
3:2087575bfd0e
--- a/main.cpp	Tue Mar 14 21:54:45 2017 +0000
+++ b/main.cpp	Tue Mar 14 23:40:15 2017 +0000
@@ -21,6 +21,7 @@
 DigitalOut led3(LED3);
 DigitalOut led4(LED4);
 int passIndex = 0;
+//Change password here. 
 int password[4] = {1, 32, 1024, 2048};
 int attempt[4];
 int correct = 1; //correct is 1 if they havent put in 3 digits. it's 2 if they're correct and it's 3 if they are incorrect.
@@ -88,6 +89,7 @@
 int main()
 {
 
+    //Inclue this if you have gyroscope connected. We only had 3 Serial buses so we were unable to use the gyroscope.
     /*LSM9DS1 IMU(p9, p10, 0xD6, 0x3C);
     IMU.begin();
     if (!IMU.begin()) {
@@ -103,9 +105,10 @@
     interrupt.fall(&fallInterrupt);
     interrupt.mode(PullUp);
 
-    uLCD.printf("Enter code for \n candy\n");
+    uLCD.printf("Enter code for \ncandy\n");
 
     while(1) {
+        //Inclue this if you have gyroscope connected. We only had 3 Serial buses so we were unable to use the gyroscope.
         /*//Checking if someone is skaing the machine
         while(!IMU.gyroAvailable())
             IMU.readGyro();
@@ -126,16 +129,16 @@
         yval = IMU.calcGyro(IMU.gy);
         zval = IMU.calcGyro(IMU.gz);
         */
-        /*while(bluemod.readable()) {
+        while(bluemod.readable()) {
             if (bluemod.getc() == 'd') {
-                correct = 2;
+                correct = 4;
                 bluemod.puts("Dispensing Candy!");
             }
             if (bluemod.getc() == 'c') {
                 voltage = in.read();
 
             }
-        }*/
+        }
 
         if(correct == 2) { // They inputted the correct password
             uLCD.cls();
@@ -149,15 +152,29 @@
             uLCD.cls();
             wait(0.2);
             correct = 1;
-            uLCD.printf("Enter code for \n candy\n");
+            uLCD.printf("Enter code for \ncandy\n");
         }
         if(correct == 3) { // they inputted the incorrect password
             uLCD.cls();
-            uLCD.printf("Incorrect Password\n\n Try again, bitch.");
+            uLCD.printf("Incorrect Password\n\n Try again.");
             wait(2.0);
             correct = 1;
             uLCD.cls();
-            uLCD.printf("Enter code for \n candy\n");
+            uLCD.printf("Enter code for \ncandy\n");
+        }
+        if(correct == 4) { // They inputted the correct password
+            uLCD.cls();
+            uLCD.printf("Dispensing via\nbluetooth!");
+            myservo = 1;
+            wait(1.3333);
+            myservo = 0.5;
+            uLCD.cls();
+            uLCD.printf("Enjoy!");
+            wait(2.0);
+            uLCD.cls();
+            wait(0.2);
+            correct = 1;
+            uLCD.printf("Enter code for \ncandy\n");
         }