final form

Dependencies:   mbed C12832

Committer:
chenniges
Date:
Tue Oct 16 10:21:28 2018 +0000
Revision:
0:733afbfa4d3f
Child:
1:fa25df63b18f
V3 hopefully working

Who changed what in which revision?

UserRevisionLine numberNew contents of line
chenniges 0:733afbfa4d3f 1 #include "mbed.h"
chenniges 0:733afbfa4d3f 2 #include "C12832.h"
chenniges 0:733afbfa4d3f 3
chenniges 0:733afbfa4d3f 4 DigitalIn LDR1(p9); //1p
chenniges 0:733afbfa4d3f 5 DigitalIn LDR2(p10); //2p
chenniges 0:733afbfa4d3f 6 DigitalIn LDR3(p12); //5p
chenniges 0:733afbfa4d3f 7 DigitalIn LDR4(p13); //10p
chenniges 0:733afbfa4d3f 8 DigitalIn LDR5(p14); //20p
chenniges 0:733afbfa4d3f 9 DigitalIn LDR6(p15); //50p
chenniges 0:733afbfa4d3f 10 DigitalIn LDR7(p16); //1GBP
chenniges 0:733afbfa4d3f 11 DigitalIn LDR8(p17); //2GBP //I don't know the mistake
chenniges 0:733afbfa4d3f 12 AnalogIn button1(p18);
chenniges 0:733afbfa4d3f 13 AnalogIn button2(p19);
chenniges 0:733afbfa4d3f 14
chenniges 0:733afbfa4d3f 15 C12832 lcd(p5, p7, p6, p8, p11);
chenniges 0:733afbfa4d3f 16
chenniges 0:733afbfa4d3f 17 /*int main()
chenniges 0:733afbfa4d3f 18 {
chenniges 0:733afbfa4d3f 19 int j=0;
chenniges 0:733afbfa4d3f 20 lcd.cls();
chenniges 0:733afbfa4d3f 21 lcd.locate(0,3);
chenniges 0:733afbfa4d3f 22 lcd.printf("mbed application board!");
chenniges 0:733afbfa4d3f 23
chenniges 0:733afbfa4d3f 24 while(true)
chenniges 0:733afbfa4d3f 25 { // this is the third thread
chenniges 0:733afbfa4d3f 26 lcd.locate(0,15);
chenniges 0:733afbfa4d3f 27 lcd.printf("Counting : %d",j);
chenniges 0:733afbfa4d3f 28 j++;
chenniges 0:733afbfa4d3f 29 wait(1.0);
chenniges 0:733afbfa4d3f 30 }
chenniges 0:733afbfa4d3f 31 }*/
chenniges 0:733afbfa4d3f 32
chenniges 0:733afbfa4d3f 33
chenniges 0:733afbfa4d3f 34 int main()
chenniges 0:733afbfa4d3f 35 {
chenniges 0:733afbfa4d3f 36 float a[8]={0,0,0,0,0,0,0,0}; //number of 1p coins
chenniges 0:733afbfa4d3f 37 int n[8]={0,0,0,0,0,0,0,0}; //amount of 1p coins
chenniges 0:733afbfa4d3f 38 float v[8]={0.01,0.02,0.05,0.1,0.2,0.5,1,2};// value of coins
chenniges 0:733afbfa4d3f 39 //...
chenniges 0:733afbfa4d3f 40 float ta=0; //total amount of all coins
chenniges 0:733afbfa4d3f 41 //int c=0; //counting variable
chenniges 0:733afbfa4d3f 42 //float tm; // token money
chenniges 0:733afbfa4d3f 43 //int buttons; //one for selection of coins, one for confirming and programm ending
chenniges 0:733afbfa4d3f 44 int an = 0;//number in which of the arrays we are
chenniges 0:733afbfa4d3f 45
chenniges 0:733afbfa4d3f 46 time_t start, end; //time counting
chenniges 0:733afbfa4d3f 47 double elapsed; // seconds
chenniges 0:733afbfa4d3f 48 start = time(NULL);
chenniges 0:733afbfa4d3f 49
chenniges 0:733afbfa4d3f 50 for(;;)
chenniges 0:733afbfa4d3f 51 {
chenniges 0:733afbfa4d3f 52 if(LDR1 == 1)//we could also use switch-case here for every diode
chenniges 0:733afbfa4d3f 53 {
chenniges 0:733afbfa4d3f 54 n[0]++;
chenniges 0:733afbfa4d3f 55 a[0] = n[0]*v[0];
chenniges 0:733afbfa4d3f 56 //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:733afbfa4d3f 57 //why is LED1 = 0; a failure?
chenniges 0:733afbfa4d3f 58 //c = 0;
chenniges 0:733afbfa4d3f 59 time(0);
chenniges 0:733afbfa4d3f 60 }
chenniges 0:733afbfa4d3f 61
chenniges 0:733afbfa4d3f 62
chenniges 0:733afbfa4d3f 63
chenniges 0:733afbfa4d3f 64 end = time(NULL);
chenniges 0:733afbfa4d3f 65 elapsed = difftime(end, start);
chenniges 0:733afbfa4d3f 66 if (elapsed >= 8.0 /* seconds */)
chenniges 0:733afbfa4d3f 67 {
chenniges 0:733afbfa4d3f 68 break;
chenniges 0:733afbfa4d3f 69 }
chenniges 0:733afbfa4d3f 70
chenniges 0:733afbfa4d3f 71
chenniges 0:733afbfa4d3f 72 /*if(LDR2 == 1)
chenniges 0:733afbfa4d3f 73 {
chenniges 0:733afbfa4d3f 74 n[1]++;
chenniges 0:733afbfa4d3f 75 a[1] = n[1]*v[1];
chenniges 0:733afbfa4d3f 76 }
chenniges 0:733afbfa4d3f 77 if(LDR3 == 1)
chenniges 0:733afbfa4d3f 78 {
chenniges 0:733afbfa4d3f 79 n[2]++;
chenniges 0:733afbfa4d3f 80 a[2] = n[2]*v[2];
chenniges 0:733afbfa4d3f 81 }
chenniges 0:733afbfa4d3f 82 if(LDR4 == 1)
chenniges 0:733afbfa4d3f 83 {
chenniges 0:733afbfa4d3f 84 n[3]++;
chenniges 0:733afbfa4d3f 85 a[3] = n[3]*v[3];
chenniges 0:733afbfa4d3f 86 }
chenniges 0:733afbfa4d3f 87 if(LDR5 == 1)
chenniges 0:733afbfa4d3f 88 {
chenniges 0:733afbfa4d3f 89 n[4]++;
chenniges 0:733afbfa4d3f 90 a[4] = n[4]*v[4];
chenniges 0:733afbfa4d3f 91 }
chenniges 0:733afbfa4d3f 92 if(LDR6 == 1)
chenniges 0:733afbfa4d3f 93 {
chenniges 0:733afbfa4d3f 94 n[5]++;
chenniges 0:733afbfa4d3f 95 a[5] = n[5]*v[5];
chenniges 0:733afbfa4d3f 96 }
chenniges 0:733afbfa4d3f 97 if(LDR7 == 1)
chenniges 0:733afbfa4d3f 98 {
chenniges 0:733afbfa4d3f 99 n[6]++;
chenniges 0:733afbfa4d3f 100 a[6] = n[6]*v[6];
chenniges 0:733afbfa4d3f 101 }
chenniges 0:733afbfa4d3f 102 if(LDR8 == 1)
chenniges 0:733afbfa4d3f 103 {
chenniges 0:733afbfa4d3f 104 n[7]++;
chenniges 0:733afbfa4d3f 105 a[7] = n[7]*v[7];
chenniges 0:733afbfa4d3f 106 }*/
chenniges 0:733afbfa4d3f 107 //... other types of coins
chenniges 0:733afbfa4d3f 108 /*c++;
chenniges 0:733afbfa4d3f 109 if (c >= 100)//depands how long the programm per cycle needs
chenniges 0:733afbfa4d3f 110 {
chenniges 0:733afbfa4d3f 111 break;
chenniges 0:733afbfa4d3f 112 }*/
chenniges 0:733afbfa4d3f 113 }
chenniges 0:733afbfa4d3f 114 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
chenniges 0:733afbfa4d3f 115 wait(5);
chenniges 0:733afbfa4d3f 116 lcd.cls();
chenniges 0:733afbfa4d3f 117 //doing these things for the other coins as well
chenniges 0:733afbfa4d3f 118
chenniges 0:733afbfa4d3f 119 ta = a[0]+a[1]+a[2]+a[3]+a[4]+a[5]+a[6]+a[7];
chenniges 0:733afbfa4d3f 120 lcd.locate(0,0);
chenniges 0:733afbfa4d3f 121 lcd.printf("Your total amount is %d %c",ta,char(163));
chenniges 0:733afbfa4d3f 122 wait(5);
chenniges 0:733afbfa4d3f 123 lcd.cls();
chenniges 0:733afbfa4d3f 124
chenniges 0:733afbfa4d3f 125 lcd.printf("Please select witch number \nof coins you would like to see \nby pressing the button.");
chenniges 0:733afbfa4d3f 126 wait(5);
chenniges 0:733afbfa4d3f 127 lcd.cls();
chenniges 0:733afbfa4d3f 128 lcd.printf("Please finish process than \nby using the Start-Stop button.");
chenniges 0:733afbfa4d3f 129
chenniges 0:733afbfa4d3f 130 /*switch (buttons)
chenniges 0:733afbfa4d3f 131 {
chenniges 0:733afbfa4d3f 132 case button1: an = an+1;
chenniges 0:733afbfa4d3f 133 if (an > 8)
chenniges 0:733afbfa4d3f 134 {
chenniges 0:733afbfa4d3f 135 an = 1
chenniges 0:733afbfa4d3f 136 }
chenniges 0:733afbfa4d3f 137 lcd.cls();
chenniges 0:733afbfa4d3f 138 lcd.printf("Do you want to see the number of %d coins?",v[an]);
chenniges 0:733afbfa4d3f 139 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
chenniges 0:733afbfa4d3f 140 break;
chenniges 0:733afbfa4d3f 141 }*/
chenniges 0:733afbfa4d3f 142 while(1)
chenniges 0:733afbfa4d3f 143 {
chenniges 0:733afbfa4d3f 144 if (button1 == 1)
chenniges 0:733afbfa4d3f 145 {
chenniges 0:733afbfa4d3f 146 an++;
chenniges 0:733afbfa4d3f 147 if (an > 8)
chenniges 0:733afbfa4d3f 148 {
chenniges 0:733afbfa4d3f 149 an = 1;
chenniges 0:733afbfa4d3f 150 }
chenniges 0:733afbfa4d3f 151 lcd.cls();
chenniges 0:733afbfa4d3f 152 lcd.printf("Do you want to see the number of %d coins?",v[an]);
chenniges 0:733afbfa4d3f 153 //button1 = 0;
chenniges 0:733afbfa4d3f 154 }
chenniges 0:733afbfa4d3f 155 if (button2 == 1)
chenniges 0:733afbfa4d3f 156 {
chenniges 0:733afbfa4d3f 157 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
chenniges 0:733afbfa4d3f 158 break;
chenniges 0:733afbfa4d3f 159 }
chenniges 0:733afbfa4d3f 160 }
chenniges 0:733afbfa4d3f 161 wait(5);
chenniges 0:733afbfa4d3f 162 lcd.cls();
chenniges 0:733afbfa4d3f 163 lcd.printf("Thank you for using 'Coounting Machine'. \nGood Bye.");
chenniges 0:733afbfa4d3f 164 wait(5);
chenniges 0:733afbfa4d3f 165 /*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.
chenniges 0:733afbfa4d3f 166 {
chenniges 0:733afbfa4d3f 167 lcd.printf("Please enter the mount of money you took:");
chenniges 0:733afbfa4d3f 168 scanf("%f",&tm);
chenniges 0:733afbfa4d3f 169 lcd.printf("%f",tm);
chenniges 0:733afbfa4d3f 170 wait(2);
chenniges 0:733afbfa4d3f 171 ta = ta-tm;
chenniges 0:733afbfa4d3f 172 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:733afbfa4d3f 173 }*/
chenniges 0:733afbfa4d3f 174
chenniges 0:733afbfa4d3f 175 return(0);
chenniges 0:733afbfa4d3f 176 }