final form

Dependencies:   mbed C12832

Revision:
4:67766287a6a0
Parent:
3:c9057d642843
Child:
5:cb60f96b36c9
diff -r c9057d642843 -r 67766287a6a0 main.cpp
--- a/main.cpp	Tue Oct 23 12:00:45 2018 +0000
+++ b/main.cpp	Tue Nov 06 10:42:39 2018 +0000
@@ -3,12 +3,12 @@
 
 DigitalIn LDR1(p9);   //1p
 DigitalIn LDR2(p10);  //2p
-DigitalIn LDR3(p12);  //5p
-DigitalIn LDR4(p13);  //10p
-DigitalIn LDR5(p14);  //20p
-DigitalIn LDR6(p15);  //50p
-DigitalIn LDR7(p16);  //1GBP
-DigitalIn LDR8(p17);  //2GBP //I don't know the mistake 
+DigitalIn LDR3(p21);  //5p
+DigitalIn LDR4(p22);  //10p
+DigitalIn LDR5(p23);  //20p
+DigitalIn LDR6(p24);  //50p
+DigitalIn LDR7(p29);  //1GBP
+DigitalIn LDR8(p30);  //2GBP //I don't know the mistake 
 DigitalIn switch1(p18);
 //AnalogIn button2(p19);
 
@@ -47,14 +47,14 @@
             double elapsed;  // seconds
             start = time(NULL);*/
     
-    for(;;)
+    while(t < 8)
     {
-       if(t > 1)
-       {
-           break;
-       }
+       //if(t > 1)
+       //{
+         //  break;
+       //}
        
-       if(LDR1 == 1)//we could also use switch-case here for every diode
+       if(LDR1 == 0)//we could also use switch-case here for every diode
        {
         n[0]++;
         a[0] = n[0]*v[0];
@@ -76,49 +76,49 @@
        }
      */  
        
-       if(LDR2 == 1)
+       if(LDR2.read() == 0)
        {
         n[1]++;
         a[1] = n[1]*v[1];
         t.reset();
         t.start();
        }
-       if(LDR3 == 1)
+       if(LDR3.read() == 0)
        {
         n[2]++;
         a[2] = n[2]*v[2];
         t.reset();
         t.start();
        }
-       if(LDR4 == 1)
+       if(LDR4.read() == 0)
        {
         n[3]++;
         a[3] = n[3]*v[3];
         t.reset();
         t.start();
        }
-       if(LDR5 == 1)
+       if(LDR5.read() == 0)
        {
         n[4]++;
         a[4] = n[4]*v[4];
         t.reset();
         t.start();
        }
-       if(LDR6 == 1)
+       if(LDR6.read() == 0)
        {
         n[5]++;
         a[5] = n[5]*v[5];
         t.reset();
         t.start();
        }
-       if(LDR7 == 1)
+       if(LDR7.read() == 0)
        {
         n[6]++;
         a[6] = n[6]*v[6];
         t.reset();
         t.start();
        }
-       if(LDR8 == 1)
+       if(LDR8.read() == 0)
        {
         n[7]++;
         a[7] = n[7]*v[7];
@@ -162,21 +162,23 @@
            case button2:    lcd.printf("You have %d of this type of coins. \nThat means you have %f£ of this type of coin.",n[an],a[an]); //it doesn't know button1 and button2 yet
                             break;
        }*/
-       do
-       {
-           if (switch1 == 1)
+       //while(switch1 == 1)
+       //{
+           do
            {
-               an++;
-               if (an > 8)
+               if (switch1 == 1)
                {
-                  an = 1;
+                   an++;
+                   if (an > 8)
+                   {
+                       an = 1;
+                   }
+                   lcd.cls();
+                   lcd.printf("Do you want to see the number of %d %c coins?",v[an],char(163));
+                   wait(3);
+                   //button1 = 0;
                }
-               lcd.cls();
-               lcd.printf("Do you want to see the number of %d %c coins?",v[an],char(163));
-               wait(3);
-               //button1 = 0;
-           }
-           else
+           if(switch1 == 0)
            {
                lcd.printf("You have %d of this type of coins. \nThat means you have %f %c of this type of coin.",n[an],a[an],char(163)); //it doesn't know button1 and button2 yet
                wait(5);
@@ -185,24 +187,37 @@
                wait(5);
                lcd.cls();
            }
-       }
-       while(switch1 == 1);
+           }while(switch1 == 1);
+           
+           /*if (switch1 == 0)
+           {
+               lcd.printf("You have %d of this type of coins. \nThat means you have %f %c of this type of coin.",n[an],a[an],char(163)); //it doesn't know button1 and button2 yet
+               wait(5);
+               lcd.cls();
+               lcd.printf("If you would like to see other \ntypes of coins as well, please \nuse switch again.");
+               wait(5);
+               lcd.cls();
+           }
+       }*/
        //wait(5);
        //lcd.cls();
        
        
        lcd.printf("Please use the switch for finishing process.");
-       wait(4);
-       do
+       //wait(4);
+       while(switch1 == 0)
        {
-           if(switch1 == 1)
-           {
+       }
+       //do
+       //{
+         //  if(switch1 == 1)
+           //{
                lcd.cls();
                lcd.printf("Thank you for using 'Coounting Machine'. \nGood Bye. :-)");
                wait(5);
                lcd.cls();
-           }
-       }while (switch1 == 0);
+           //}
+       //}while (switch1 == 0);
        /*if() //press button or something like that         //total amount which is left when the user took money and entered the amount of it in the machine.
        {
            lcd.printf("Please enter the mount of money you took:");