V1

Dependencies:   mbed C12832

Committer:
chenniges
Date:
Tue Oct 09 09:43:27 2018 +0000
Revision:
1:bf8737118d3d
Parent:
0:d9d4f644fecc
Child:
2:370f188e2590
V1_uncompled

Who changed what in which revision?

UserRevisionLine numberNew contents of line
chenniges 0:d9d4f644fecc 1 #include "mbed.h"
chenniges 0:d9d4f644fecc 2 #include "C12832.h"
chenniges 0:d9d4f644fecc 3
chenniges 1:bf8737118d3d 4 DigitalIn LDR1(p9); //1p
chenniges 1:bf8737118d3d 5 DigitalIn LDR2(p10); //2p
chenniges 1:bf8737118d3d 6 DigitalIn LDR3(p12); //5p
chenniges 1:bf8737118d3d 7 DigitalIn LDR4(p13); //10p
chenniges 1:bf8737118d3d 8 DigitalIn LDR5(p14); //20p
chenniges 1:bf8737118d3d 9 DigitalIn LDR6(p15); //50p
chenniges 1:bf8737118d3d 10 DigitalIn LDR7(p16); //1GBP
chenniges 1:bf8737118d3d 11 DigitalIn LDR8(p17); //2GBP //I don't know the mistake
chenniges 0:d9d4f644fecc 12
chenniges 1:bf8737118d3d 13 C12832 lcd(p5,p6,p7,p8,p11)
chenniges 0:d9d4f644fecc 14
chenniges 0:d9d4f644fecc 15 int main() {
chenniges 0:d9d4f644fecc 16 int n1; //number of 1p coins
chenniges 0:d9d4f644fecc 17 float a1; //amount of 1p coins
chenniges 1:bf8737118d3d 18 //...
chenniges 0:d9d4f644fecc 19 float ta; //total amount of all coins
chenniges 0:d9d4f644fecc 20 int c; //counting variable
chenniges 0:d9d4f644fecc 21 float tm; // token money
chenniges 0:d9d4f644fecc 22
chenniges 0:d9d4f644fecc 23 for(;;)
chenniges 0:d9d4f644fecc 24 {
chenniges 0:d9d4f644fecc 25 if(LDR1 == 1)
chenniges 0:d9d4f644fecc 26 {
chenniges 0:d9d4f644fecc 27 a1++;
chenniges 0:d9d4f644fecc 28 n1 = a1*0.01;
chenniges 0:d9d4f644fecc 29 //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
chenniges 0:d9d4f644fecc 30 //why is LED1 = 0; a failure?
chenniges 0:d9d4f644fecc 31 c = 0;
chenniges 0:d9d4f644fecc 32 }
chenniges 0:d9d4f644fecc 33 //... other types of coins
chenniges 0:d9d4f644fecc 34 c++;
chenniges 0:d9d4f644fecc 35 if (c >= 100)//depands how long the programm per cycle needs
chenniges 0:d9d4f644fecc 36 {
chenniges 0:d9d4f644fecc 37 break;
chenniges 0:d9d4f644fecc 38 }
chenniges 0:d9d4f644fecc 39 }
chenniges 0:d9d4f644fecc 40 lcd.printf("You have %d coins of 1p which means you have %d",a1,n1); // it looks like we have to use only printf and not lcd.printf
chenniges 0:d9d4f644fecc 41 wait(3);
chenniges 0:d9d4f644fecc 42 lcd.cls();
chenniges 0:d9d4f644fecc 43 //doing these things for the other coins as well
chenniges 0:d9d4f644fecc 44
chenniges 0:d9d4f644fecc 45 //ta = n1+n2+n5+n10+n20+n50+n100+n200;
chenniges 0:d9d4f644fecc 46 lcd.printf("Your total amount is %d",ta);
chenniges 0:d9d4f644fecc 47 wait(3);
chenniges 0:d9d4f644fecc 48 lcd.cls();
chenniges 0:d9d4f644fecc 49
chenniges 0:d9d4f644fecc 50 //if() //press button or something like that
chenniges 0:d9d4f644fecc 51 {
chenniges 0:d9d4f644fecc 52 lcd.printf("Please enter the mount of money you took:");
chenniges 0:d9d4f644fecc 53 scanf("%f",&tm);
chenniges 0:d9d4f644fecc 54 lcd.printf("%f",tm);
chenniges 0:d9d4f644fecc 55 wait(2);
chenniges 0:d9d4f644fecc 56 ta = ta-tm;
chenniges 0:d9d4f644fecc 57 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
chenniges 0:d9d4f644fecc 58 }
chenniges 0:d9d4f644fecc 59
chenniges 0:d9d4f644fecc 60 return(0);
chenniges 0:d9d4f644fecc 61 }