final form

Dependencies:   mbed C12832

main.cpp

Committer:
mark1998
Date:
2018-11-21
Revision:
6:21c45f712206
Parent:
5:cb60f96b36c9
Child:
7:b522dd5a5d39

File content as of revision 6:21c45f712206:

#include "mbed.h"
#include "C12832.h"

DigitalIn LDR1(p9);   //1p
DigitalIn LDR2(p10);  //2p
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);

C12832 lcd(p5, p7, p6, p8, p11);
Serial pc(USBTX, USBRX); // USB serial interface

/*int main()
{
    int j=0;
    lcd.cls();
    lcd.locate(0,3);
    lcd.printf("mbed application board!");
    
    while(true) 
    {   // this is the third thread
        lcd.locate(0,15);
        lcd.printf("Counting : %d",j);
        j++;
        wait(1.0);
    }
}*/


int main() 
{
    //pc.baud(921600);
    float a[8]={0,0,0,0,0,0,0,0}; //number of 1p coins
    int n[8]={0,0,0,0,0,0,0,0}; //amount of 1p coins
    float v[8]={0.01,0.02,0.05,0.1,0.2,0.5,1,2};// value of coins
    //...
    float ta=0; //total amount of all coins
    //int c=0; //counting variable
    //float tm; // token money 
    //int buttons; //one for selection of coins, one for confirming and programm ending
    int an = 0;//number in which of the arrays we are
    Timer t;
            /*time_t start, end;      //time counting
            double elapsed;  // seconds
            start = time(NULL);*/
    
    while(t < 8)
    {
       //if(t > 1)
       //{
         //  break;
       //}
       
       if(LDR1 == 0)//we could also use switch-case here for every diode
       {
        n[0]++;
        a[0] = n[0]*v[0];
        t.reset();
        t.start();
        //wait(0.2); //I don't know if the programm would count a coin twice when we reset the LED immediately because the programm runs faster than the coins fall 
        //why is LED1 = 0; a failure?
        //c = 0;
        //time(0);
       }
            
           
   /*
     end = time(NULL);
     elapsed = difftime(end, start);
     if (elapsed >= 8.0)//seconds
       {
           break;
       }
     */  
       
       if(LDR2.read() == 0)
       {
        n[1]++;
        a[1] = n[1]*v[1];
        t.reset();
        t.start();
       }
       if(LDR3.read() == 0)
       {
        n[2]++;
        a[2] = n[2]*v[2];
        t.reset();
        t.start();
       }
       if(LDR4.read() == 0)
       {
        n[3]++;
        a[3] = n[3]*v[3];
        t.reset();
        t.start();
       }
       if(LDR5.read() == 0)
       {
        n[4]++;
        a[4] = n[4]*v[4];
        t.reset();
        t.start();
       }
       if(LDR6.read() == 0)
       {
        n[5]++;
        a[5] = n[5]*v[5];
        t.reset();
        t.start();
       }
       if(LDR7.read() == 0)
       {
        n[6]++;
        a[6] = n[6]*v[6];
        t.reset();
        t.start();
       }
       if(LDR8.read() == 0)
       {
        n[7]++;
        a[7] = n[7]*v[7];
        t.reset();
        t.start();
       }
       //... other types of coins
       /*c++;
       if (c >= 100)//depands how long the programm per cycle needs
       {
           break;
       }*/ 
    } 
       /*lcd.printf("You have %d coins of 1p \nwhich means you have %f$*ps",n[0],a[0]); // it looks like we have to use only printf and not lcd.printf
       wait(5);
       lcd.cls();
       //doing these things for the other coins as well*/
       
       ta = a[0]+a[1]+a[2]+a[3]+a[4]+a[5]+a[6]+a[7];
       //lcd.locate(0,0);
       //pc.printf("Your total value is %d %c.",ta,char(163));
         pc.printf( "your total value is %f %c.",ta,char(163));
       wait(5);
       system("CLS");
       
       pc.printf("Please select witch number \nof coins you would like to see.");
       wait(5);
      // pc.cls();
       system("CLS");
       pc.printf("Confirm your choice by using the switch.");
       wait(3);
       system("CLS"); 
      // pc.cls();
       /*switch (buttons)
       {
           case button1:    an = an+1;
                            if (an > 8)
                            {
                                an = 1
                            }
                            lcd.cls();
                            lcd.printf("Do you want to see the number of %d coins?",v[an]);
                            break;
           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;
       }*/
       //while(switch1 == 1)
       //{
           do
           {
               if (switch1 == 1)
               {
                 
                // an++;
                 //  if (an > 8)
                  // {
                   //    an = 1;
                  // }
                   //pc.cls();
                
                   

                   system("CLS");
                   pc.printf("Do you want to see the number of %d %c coins?",v[an],char(163));
                   na++;
                   if (an > 7);
                   {
                   an= 0 ;
                   }
                   wait(3);
                   //button1 = 0;
               }
           if(switch1 == 0)
           {
               pc.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();
               system("CLS");
               pc.printf("If you would like to see other \ntypes of coins as well, please \nuse switch again.");
               wait(5);
               system("CLS");
               //lcd.cls();
           }
           }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();
       
       
       pc.printf("Please use the switch for finishing process.");
       //wait(4);
       while(switch1 == 0)
       {
       }
       //do
       //{
         //  if(switch1 == 1)
           //{
               //pc.cls();
               system("CLS");
               pc.printf("Thank you for using 'Coounting Machine'. \nGood Bye. :-)");
               wait(5);
               system("CLS");
               //pc.cls();
           //}
       //}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:");
           scanf("%f",&tm);
           lcd.printf("%f",tm);
           wait(2);
           ta = ta-tm;
           lcd.printf("Now you have only %f \bx156 left", ta); //\b for one step backword and I guess that x156 for £ //I'm not sure
       }*/
       
    return(0);
}
//change all 1 to 0 at LDR1,2,...