final form

Dependencies:   mbed C12832

Committer:
mark1998
Date:
Tue Nov 06 11:11:29 2018 +0000
Revision:
5:cb60f96b36c9
Parent:
4:67766287a6a0
Child:
6:21c45f712206
pc. printf;

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 4:67766287a6a0 6 DigitalIn LDR3(p21); //5p
chenniges 4:67766287a6a0 7 DigitalIn LDR4(p22); //10p
chenniges 4:67766287a6a0 8 DigitalIn LDR5(p23); //20p
chenniges 4:67766287a6a0 9 DigitalIn LDR6(p24); //50p
chenniges 4:67766287a6a0 10 DigitalIn LDR7(p29); //1GBP
chenniges 4:67766287a6a0 11 DigitalIn LDR8(p30); //2GBP //I don't know the mistake
mark1998 3:c9057d642843 12 DigitalIn switch1(p18);
mark1998 3:c9057d642843 13 //AnalogIn button2(p19);
chenniges 0:733afbfa4d3f 14
chenniges 0:733afbfa4d3f 15 C12832 lcd(p5, p7, p6, p8, p11);
mark1998 5:cb60f96b36c9 16 Serial pc(USBTX, USBRX); // USB serial interface
chenniges 0:733afbfa4d3f 17
chenniges 0:733afbfa4d3f 18 /*int main()
chenniges 0:733afbfa4d3f 19 {
chenniges 0:733afbfa4d3f 20 int j=0;
chenniges 0:733afbfa4d3f 21 lcd.cls();
chenniges 0:733afbfa4d3f 22 lcd.locate(0,3);
chenniges 0:733afbfa4d3f 23 lcd.printf("mbed application board!");
chenniges 0:733afbfa4d3f 24
chenniges 0:733afbfa4d3f 25 while(true)
chenniges 0:733afbfa4d3f 26 { // this is the third thread
chenniges 0:733afbfa4d3f 27 lcd.locate(0,15);
chenniges 0:733afbfa4d3f 28 lcd.printf("Counting : %d",j);
chenniges 0:733afbfa4d3f 29 j++;
chenniges 0:733afbfa4d3f 30 wait(1.0);
chenniges 0:733afbfa4d3f 31 }
chenniges 0:733afbfa4d3f 32 }*/
chenniges 0:733afbfa4d3f 33
chenniges 0:733afbfa4d3f 34
chenniges 0:733afbfa4d3f 35 int main()
chenniges 0:733afbfa4d3f 36 {
mark1998 5:cb60f96b36c9 37 pc.baud(921600);
chenniges 0:733afbfa4d3f 38 float a[8]={0,0,0,0,0,0,0,0}; //number of 1p coins
chenniges 0:733afbfa4d3f 39 int n[8]={0,0,0,0,0,0,0,0}; //amount of 1p coins
chenniges 0:733afbfa4d3f 40 float v[8]={0.01,0.02,0.05,0.1,0.2,0.5,1,2};// value of coins
chenniges 0:733afbfa4d3f 41 //...
chenniges 0:733afbfa4d3f 42 float ta=0; //total amount of all coins
chenniges 0:733afbfa4d3f 43 //int c=0; //counting variable
chenniges 0:733afbfa4d3f 44 //float tm; // token money
chenniges 0:733afbfa4d3f 45 //int buttons; //one for selection of coins, one for confirming and programm ending
chenniges 0:733afbfa4d3f 46 int an = 0;//number in which of the arrays we are
mark1998 2:c95f08525bea 47 Timer t;
mark1998 2:c95f08525bea 48 /*time_t start, end; //time counting
chenniges 0:733afbfa4d3f 49 double elapsed; // seconds
mark1998 2:c95f08525bea 50 start = time(NULL);*/
chenniges 0:733afbfa4d3f 51
chenniges 4:67766287a6a0 52 while(t < 8)
chenniges 0:733afbfa4d3f 53 {
chenniges 4:67766287a6a0 54 //if(t > 1)
chenniges 4:67766287a6a0 55 //{
chenniges 4:67766287a6a0 56 // break;
chenniges 4:67766287a6a0 57 //}
mark1998 2:c95f08525bea 58
chenniges 4:67766287a6a0 59 if(LDR1 == 0)//we could also use switch-case here for every diode
chenniges 0:733afbfa4d3f 60 {
chenniges 0:733afbfa4d3f 61 n[0]++;
chenniges 0:733afbfa4d3f 62 a[0] = n[0]*v[0];
mark1998 2:c95f08525bea 63 t.reset();
mark1998 2:c95f08525bea 64 t.start();
chenniges 0:733afbfa4d3f 65 //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 66 //why is LED1 = 0; a failure?
chenniges 0:733afbfa4d3f 67 //c = 0;
mark1998 2:c95f08525bea 68 //time(0);
chenniges 0:733afbfa4d3f 69 }
chenniges 0:733afbfa4d3f 70
mark1998 2:c95f08525bea 71
mark1998 2:c95f08525bea 72 /*
chenniges 0:733afbfa4d3f 73 end = time(NULL);
chenniges 0:733afbfa4d3f 74 elapsed = difftime(end, start);
mark1998 2:c95f08525bea 75 if (elapsed >= 8.0)//seconds
chenniges 0:733afbfa4d3f 76 {
chenniges 0:733afbfa4d3f 77 break;
chenniges 0:733afbfa4d3f 78 }
mark1998 2:c95f08525bea 79 */
chenniges 0:733afbfa4d3f 80
chenniges 4:67766287a6a0 81 if(LDR2.read() == 0)
chenniges 0:733afbfa4d3f 82 {
chenniges 0:733afbfa4d3f 83 n[1]++;
chenniges 0:733afbfa4d3f 84 a[1] = n[1]*v[1];
mark1998 2:c95f08525bea 85 t.reset();
mark1998 2:c95f08525bea 86 t.start();
chenniges 0:733afbfa4d3f 87 }
chenniges 4:67766287a6a0 88 if(LDR3.read() == 0)
chenniges 0:733afbfa4d3f 89 {
chenniges 0:733afbfa4d3f 90 n[2]++;
chenniges 0:733afbfa4d3f 91 a[2] = n[2]*v[2];
mark1998 2:c95f08525bea 92 t.reset();
mark1998 2:c95f08525bea 93 t.start();
chenniges 0:733afbfa4d3f 94 }
chenniges 4:67766287a6a0 95 if(LDR4.read() == 0)
chenniges 0:733afbfa4d3f 96 {
chenniges 0:733afbfa4d3f 97 n[3]++;
chenniges 0:733afbfa4d3f 98 a[3] = n[3]*v[3];
mark1998 2:c95f08525bea 99 t.reset();
mark1998 2:c95f08525bea 100 t.start();
chenniges 0:733afbfa4d3f 101 }
chenniges 4:67766287a6a0 102 if(LDR5.read() == 0)
chenniges 0:733afbfa4d3f 103 {
chenniges 0:733afbfa4d3f 104 n[4]++;
chenniges 0:733afbfa4d3f 105 a[4] = n[4]*v[4];
mark1998 2:c95f08525bea 106 t.reset();
mark1998 2:c95f08525bea 107 t.start();
chenniges 0:733afbfa4d3f 108 }
chenniges 4:67766287a6a0 109 if(LDR6.read() == 0)
chenniges 0:733afbfa4d3f 110 {
chenniges 0:733afbfa4d3f 111 n[5]++;
chenniges 0:733afbfa4d3f 112 a[5] = n[5]*v[5];
mark1998 2:c95f08525bea 113 t.reset();
mark1998 2:c95f08525bea 114 t.start();
chenniges 0:733afbfa4d3f 115 }
chenniges 4:67766287a6a0 116 if(LDR7.read() == 0)
chenniges 0:733afbfa4d3f 117 {
chenniges 0:733afbfa4d3f 118 n[6]++;
chenniges 0:733afbfa4d3f 119 a[6] = n[6]*v[6];
mark1998 2:c95f08525bea 120 t.reset();
mark1998 2:c95f08525bea 121 t.start();
chenniges 0:733afbfa4d3f 122 }
chenniges 4:67766287a6a0 123 if(LDR8.read() == 0)
chenniges 0:733afbfa4d3f 124 {
chenniges 0:733afbfa4d3f 125 n[7]++;
chenniges 0:733afbfa4d3f 126 a[7] = n[7]*v[7];
mark1998 2:c95f08525bea 127 t.reset();
mark1998 2:c95f08525bea 128 t.start();
mark1998 2:c95f08525bea 129 }
chenniges 0:733afbfa4d3f 130 //... other types of coins
chenniges 0:733afbfa4d3f 131 /*c++;
chenniges 0:733afbfa4d3f 132 if (c >= 100)//depands how long the programm per cycle needs
chenniges 0:733afbfa4d3f 133 {
chenniges 0:733afbfa4d3f 134 break;
chenniges 0:733afbfa4d3f 135 }*/
chenniges 0:733afbfa4d3f 136 }
mark1998 2:c95f08525bea 137 /*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 138 wait(5);
chenniges 0:733afbfa4d3f 139 lcd.cls();
mark1998 2:c95f08525bea 140 //doing these things for the other coins as well*/
chenniges 0:733afbfa4d3f 141
chenniges 0:733afbfa4d3f 142 ta = a[0]+a[1]+a[2]+a[3]+a[4]+a[5]+a[6]+a[7];
mark1998 5:cb60f96b36c9 143 //lcd.locate(0,0);
mark1998 5:cb60f96b36c9 144 pc.printf("Your total value is %d %c.",ta,char(163));
chenniges 0:733afbfa4d3f 145 wait(5);
mark1998 5:cb60f96b36c9 146 system("CLS");
chenniges 0:733afbfa4d3f 147
mark1998 5:cb60f96b36c9 148 pc.printf("Please select witch number \nof coins you would like to see.");
chenniges 0:733afbfa4d3f 149 wait(5);
mark1998 5:cb60f96b36c9 150 // pc.cls();
mark1998 5:cb60f96b36c9 151 system("CLS");
mark1998 5:cb60f96b36c9 152 pc.printf("Confirm your choice by using the switch.");
mark1998 2:c95f08525bea 153 wait(3);
mark1998 5:cb60f96b36c9 154 system("CLS");
mark1998 5:cb60f96b36c9 155 // pc.cls();
chenniges 0:733afbfa4d3f 156 /*switch (buttons)
chenniges 0:733afbfa4d3f 157 {
chenniges 0:733afbfa4d3f 158 case button1: an = an+1;
chenniges 0:733afbfa4d3f 159 if (an > 8)
chenniges 0:733afbfa4d3f 160 {
chenniges 0:733afbfa4d3f 161 an = 1
chenniges 0:733afbfa4d3f 162 }
chenniges 0:733afbfa4d3f 163 lcd.cls();
chenniges 0:733afbfa4d3f 164 lcd.printf("Do you want to see the number of %d coins?",v[an]);
mark1998 3:c9057d642843 165 break;
chenniges 0:733afbfa4d3f 166 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 167 break;
chenniges 0:733afbfa4d3f 168 }*/
chenniges 4:67766287a6a0 169 //while(switch1 == 1)
chenniges 4:67766287a6a0 170 //{
chenniges 4:67766287a6a0 171 do
chenniges 0:733afbfa4d3f 172 {
chenniges 4:67766287a6a0 173 if (switch1 == 1)
chenniges 0:733afbfa4d3f 174 {
chenniges 4:67766287a6a0 175 an++;
chenniges 4:67766287a6a0 176 if (an > 8)
chenniges 4:67766287a6a0 177 {
chenniges 4:67766287a6a0 178 an = 1;
chenniges 4:67766287a6a0 179 }
mark1998 5:cb60f96b36c9 180 //pc.cls();
mark1998 5:cb60f96b36c9 181 system("CLS");
mark1998 5:cb60f96b36c9 182 pc.printf("Do you want to see the number of %d %c coins?",v[an],char(163));
chenniges 4:67766287a6a0 183 wait(3);
chenniges 4:67766287a6a0 184 //button1 = 0;
chenniges 0:733afbfa4d3f 185 }
chenniges 4:67766287a6a0 186 if(switch1 == 0)
chenniges 0:733afbfa4d3f 187 {
mark1998 5:cb60f96b36c9 188 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
mark1998 3:c9057d642843 189 wait(5);
mark1998 5:cb60f96b36c9 190 //lcd.cls();
mark1998 5:cb60f96b36c9 191 system("CLS");
mark1998 5:cb60f96b36c9 192 pc.printf("If you would like to see other \ntypes of coins as well, please \nuse switch again.");
mark1998 3:c9057d642843 193 wait(5);
mark1998 5:cb60f96b36c9 194 system("CLS");
mark1998 5:cb60f96b36c9 195 //lcd.cls();
chenniges 0:733afbfa4d3f 196 }
chenniges 4:67766287a6a0 197 }while(switch1 == 1);
chenniges 4:67766287a6a0 198
chenniges 4:67766287a6a0 199 /*if (switch1 == 0)
chenniges 4:67766287a6a0 200 {
chenniges 4:67766287a6a0 201 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 4:67766287a6a0 202 wait(5);
chenniges 4:67766287a6a0 203 lcd.cls();
chenniges 4:67766287a6a0 204 lcd.printf("If you would like to see other \ntypes of coins as well, please \nuse switch again.");
chenniges 4:67766287a6a0 205 wait(5);
chenniges 4:67766287a6a0 206 lcd.cls();
chenniges 4:67766287a6a0 207 }
chenniges 4:67766287a6a0 208 }*/
mark1998 3:c9057d642843 209 //wait(5);
mark1998 3:c9057d642843 210 //lcd.cls();
mark1998 3:c9057d642843 211
mark1998 3:c9057d642843 212
mark1998 5:cb60f96b36c9 213 pc.printf("Please use the switch for finishing process.");
chenniges 4:67766287a6a0 214 //wait(4);
chenniges 4:67766287a6a0 215 while(switch1 == 0)
mark1998 3:c9057d642843 216 {
chenniges 4:67766287a6a0 217 }
chenniges 4:67766287a6a0 218 //do
chenniges 4:67766287a6a0 219 //{
chenniges 4:67766287a6a0 220 // if(switch1 == 1)
chenniges 4:67766287a6a0 221 //{
mark1998 5:cb60f96b36c9 222 //pc.cls();
mark1998 5:cb60f96b36c9 223 system("CLS");
mark1998 5:cb60f96b36c9 224 pc.printf("Thank you for using 'Coounting Machine'. \nGood Bye. :-)");
mark1998 3:c9057d642843 225 wait(5);
mark1998 5:cb60f96b36c9 226 system("CLS");
mark1998 5:cb60f96b36c9 227 //pc.cls();
chenniges 4:67766287a6a0 228 //}
chenniges 4:67766287a6a0 229 //}while (switch1 == 0);
chenniges 0:733afbfa4d3f 230 /*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 231 {
chenniges 0:733afbfa4d3f 232 lcd.printf("Please enter the mount of money you took:");
chenniges 0:733afbfa4d3f 233 scanf("%f",&tm);
chenniges 0:733afbfa4d3f 234 lcd.printf("%f",tm);
chenniges 0:733afbfa4d3f 235 wait(2);
chenniges 0:733afbfa4d3f 236 ta = ta-tm;
chenniges 0:733afbfa4d3f 237 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 238 }*/
chenniges 0:733afbfa4d3f 239
chenniges 0:733afbfa4d3f 240 return(0);
chenniges 0:733afbfa4d3f 241 }
mark1998 3:c9057d642843 242 //change all 1 to 0 at LDR1,2,...