final form

Dependencies:   mbed C12832

main.cpp

Committer:
mark1998
Date:
2018-10-23
Revision:
2:c95f08525bea
Parent:
1:fa25df63b18f
Child:
3:c9057d642843

File content as of revision 2:c95f08525bea:

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

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 
AnalogIn button1(p18);
AnalogIn button2(p19);

C12832 lcd(p5, p7, p6, p8, p11);

/*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() 
{
    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);*/
    
    for(;;)
    {
       if(t > 8)
       {
           break;
       }
       
       if(LDR1 == 1)//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 == 1)
       {
        n[1]++;
        a[1] = n[1]*v[1];
        t.reset();
        t.start();
       }
       if(LDR3 == 1)
       {
        n[2]++;
        a[2] = n[2]*v[2];
        t.reset();
        t.start();
       }
       if(LDR4 == 1)
       {
        n[3]++;
        a[3] = n[3]*v[3];
        t.reset();
        t.start();
       }
       if(LDR5 == 1)
       {
        n[4]++;
        a[4] = n[4]*v[4];
        t.reset();
        t.start();
       }
       if(LDR6 == 1)
       {
        n[5]++;
        a[5] = n[5]*v[5];
        t.reset();
        t.start();
       }
       if(LDR7 == 1)
       {
        n[6]++;
        a[6] = n[6]*v[6];
        t.reset();
        t.start();
       }
       if(LDR8 == 1)
       {
        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);
       lcd.printf("Your total amount is %d %c",ta,char(163));
       wait(5);
       lcd.cls();
       
       lcd.printf("Please select witch number \nof coins you would like to see.");
       wait(5);
       lcd.cls();
       lcd.printf("Confirm your choice by using the switch.");
       wait(3);
       
       /*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]);
           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(1)
       {
           if (button1 == 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;
           }
           if (button2 == 1)
           {
               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
               break;
           }
       }
       wait(5);
       lcd.cls();
       lcd.printf("Thank you for using 'Coounting Machine'. \nGood Bye. :-)");
       wait(5);
       /*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);
}