final form

Dependencies:   mbed C12832

Committer:
chenniges
Date:
Tue Nov 06 10:42:39 2018 +0000
Revision:
4:67766287a6a0
Parent:
3:c9057d642843
Child:
5:cb60f96b36c9
Final version with wrong printing

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);
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
mark1998 2:c95f08525bea 45 Timer t;
mark1998 2:c95f08525bea 46 /*time_t start, end; //time counting
chenniges 0:733afbfa4d3f 47 double elapsed; // seconds
mark1998 2:c95f08525bea 48 start = time(NULL);*/
chenniges 0:733afbfa4d3f 49
chenniges 4:67766287a6a0 50 while(t < 8)
chenniges 0:733afbfa4d3f 51 {
chenniges 4:67766287a6a0 52 //if(t > 1)
chenniges 4:67766287a6a0 53 //{
chenniges 4:67766287a6a0 54 // break;
chenniges 4:67766287a6a0 55 //}
mark1998 2:c95f08525bea 56
chenniges 4:67766287a6a0 57 if(LDR1 == 0)//we could also use switch-case here for every diode
chenniges 0:733afbfa4d3f 58 {
chenniges 0:733afbfa4d3f 59 n[0]++;
chenniges 0:733afbfa4d3f 60 a[0] = n[0]*v[0];
mark1998 2:c95f08525bea 61 t.reset();
mark1998 2:c95f08525bea 62 t.start();
chenniges 0:733afbfa4d3f 63 //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 64 //why is LED1 = 0; a failure?
chenniges 0:733afbfa4d3f 65 //c = 0;
mark1998 2:c95f08525bea 66 //time(0);
chenniges 0:733afbfa4d3f 67 }
chenniges 0:733afbfa4d3f 68
mark1998 2:c95f08525bea 69
mark1998 2:c95f08525bea 70 /*
chenniges 0:733afbfa4d3f 71 end = time(NULL);
chenniges 0:733afbfa4d3f 72 elapsed = difftime(end, start);
mark1998 2:c95f08525bea 73 if (elapsed >= 8.0)//seconds
chenniges 0:733afbfa4d3f 74 {
chenniges 0:733afbfa4d3f 75 break;
chenniges 0:733afbfa4d3f 76 }
mark1998 2:c95f08525bea 77 */
chenniges 0:733afbfa4d3f 78
chenniges 4:67766287a6a0 79 if(LDR2.read() == 0)
chenniges 0:733afbfa4d3f 80 {
chenniges 0:733afbfa4d3f 81 n[1]++;
chenniges 0:733afbfa4d3f 82 a[1] = n[1]*v[1];
mark1998 2:c95f08525bea 83 t.reset();
mark1998 2:c95f08525bea 84 t.start();
chenniges 0:733afbfa4d3f 85 }
chenniges 4:67766287a6a0 86 if(LDR3.read() == 0)
chenniges 0:733afbfa4d3f 87 {
chenniges 0:733afbfa4d3f 88 n[2]++;
chenniges 0:733afbfa4d3f 89 a[2] = n[2]*v[2];
mark1998 2:c95f08525bea 90 t.reset();
mark1998 2:c95f08525bea 91 t.start();
chenniges 0:733afbfa4d3f 92 }
chenniges 4:67766287a6a0 93 if(LDR4.read() == 0)
chenniges 0:733afbfa4d3f 94 {
chenniges 0:733afbfa4d3f 95 n[3]++;
chenniges 0:733afbfa4d3f 96 a[3] = n[3]*v[3];
mark1998 2:c95f08525bea 97 t.reset();
mark1998 2:c95f08525bea 98 t.start();
chenniges 0:733afbfa4d3f 99 }
chenniges 4:67766287a6a0 100 if(LDR5.read() == 0)
chenniges 0:733afbfa4d3f 101 {
chenniges 0:733afbfa4d3f 102 n[4]++;
chenniges 0:733afbfa4d3f 103 a[4] = n[4]*v[4];
mark1998 2:c95f08525bea 104 t.reset();
mark1998 2:c95f08525bea 105 t.start();
chenniges 0:733afbfa4d3f 106 }
chenniges 4:67766287a6a0 107 if(LDR6.read() == 0)
chenniges 0:733afbfa4d3f 108 {
chenniges 0:733afbfa4d3f 109 n[5]++;
chenniges 0:733afbfa4d3f 110 a[5] = n[5]*v[5];
mark1998 2:c95f08525bea 111 t.reset();
mark1998 2:c95f08525bea 112 t.start();
chenniges 0:733afbfa4d3f 113 }
chenniges 4:67766287a6a0 114 if(LDR7.read() == 0)
chenniges 0:733afbfa4d3f 115 {
chenniges 0:733afbfa4d3f 116 n[6]++;
chenniges 0:733afbfa4d3f 117 a[6] = n[6]*v[6];
mark1998 2:c95f08525bea 118 t.reset();
mark1998 2:c95f08525bea 119 t.start();
chenniges 0:733afbfa4d3f 120 }
chenniges 4:67766287a6a0 121 if(LDR8.read() == 0)
chenniges 0:733afbfa4d3f 122 {
chenniges 0:733afbfa4d3f 123 n[7]++;
chenniges 0:733afbfa4d3f 124 a[7] = n[7]*v[7];
mark1998 2:c95f08525bea 125 t.reset();
mark1998 2:c95f08525bea 126 t.start();
mark1998 2:c95f08525bea 127 }
chenniges 0:733afbfa4d3f 128 //... other types of coins
chenniges 0:733afbfa4d3f 129 /*c++;
chenniges 0:733afbfa4d3f 130 if (c >= 100)//depands how long the programm per cycle needs
chenniges 0:733afbfa4d3f 131 {
chenniges 0:733afbfa4d3f 132 break;
chenniges 0:733afbfa4d3f 133 }*/
chenniges 0:733afbfa4d3f 134 }
mark1998 2:c95f08525bea 135 /*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 136 wait(5);
chenniges 0:733afbfa4d3f 137 lcd.cls();
mark1998 2:c95f08525bea 138 //doing these things for the other coins as well*/
chenniges 0:733afbfa4d3f 139
chenniges 0:733afbfa4d3f 140 ta = a[0]+a[1]+a[2]+a[3]+a[4]+a[5]+a[6]+a[7];
chenniges 0:733afbfa4d3f 141 lcd.locate(0,0);
mark1998 3:c9057d642843 142 lcd.printf("Your total value is %d %c.",ta,char(163));
chenniges 0:733afbfa4d3f 143 wait(5);
chenniges 0:733afbfa4d3f 144 lcd.cls();
chenniges 0:733afbfa4d3f 145
mark1998 2:c95f08525bea 146 lcd.printf("Please select witch number \nof coins you would like to see.");
chenniges 0:733afbfa4d3f 147 wait(5);
chenniges 0:733afbfa4d3f 148 lcd.cls();
mark1998 2:c95f08525bea 149 lcd.printf("Confirm your choice by using the switch.");
mark1998 2:c95f08525bea 150 wait(3);
mark1998 3:c9057d642843 151 lcd.cls();
chenniges 0:733afbfa4d3f 152 /*switch (buttons)
chenniges 0:733afbfa4d3f 153 {
chenniges 0:733afbfa4d3f 154 case button1: an = an+1;
chenniges 0:733afbfa4d3f 155 if (an > 8)
chenniges 0:733afbfa4d3f 156 {
chenniges 0:733afbfa4d3f 157 an = 1
chenniges 0:733afbfa4d3f 158 }
chenniges 0:733afbfa4d3f 159 lcd.cls();
chenniges 0:733afbfa4d3f 160 lcd.printf("Do you want to see the number of %d coins?",v[an]);
mark1998 3:c9057d642843 161 break;
chenniges 0:733afbfa4d3f 162 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 163 break;
chenniges 0:733afbfa4d3f 164 }*/
chenniges 4:67766287a6a0 165 //while(switch1 == 1)
chenniges 4:67766287a6a0 166 //{
chenniges 4:67766287a6a0 167 do
chenniges 0:733afbfa4d3f 168 {
chenniges 4:67766287a6a0 169 if (switch1 == 1)
chenniges 0:733afbfa4d3f 170 {
chenniges 4:67766287a6a0 171 an++;
chenniges 4:67766287a6a0 172 if (an > 8)
chenniges 4:67766287a6a0 173 {
chenniges 4:67766287a6a0 174 an = 1;
chenniges 4:67766287a6a0 175 }
chenniges 4:67766287a6a0 176 lcd.cls();
chenniges 4:67766287a6a0 177 lcd.printf("Do you want to see the number of %d %c coins?",v[an],char(163));
chenniges 4:67766287a6a0 178 wait(3);
chenniges 4:67766287a6a0 179 //button1 = 0;
chenniges 0:733afbfa4d3f 180 }
chenniges 4:67766287a6a0 181 if(switch1 == 0)
chenniges 0:733afbfa4d3f 182 {
chenniges 0:733afbfa4d3f 183 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
mark1998 3:c9057d642843 184 wait(5);
mark1998 3:c9057d642843 185 lcd.cls();
mark1998 3:c9057d642843 186 lcd.printf("If you would like to see other \ntypes of coins as well, please \nuse switch again.");
mark1998 3:c9057d642843 187 wait(5);
mark1998 3:c9057d642843 188 lcd.cls();
chenniges 0:733afbfa4d3f 189 }
chenniges 4:67766287a6a0 190 }while(switch1 == 1);
chenniges 4:67766287a6a0 191
chenniges 4:67766287a6a0 192 /*if (switch1 == 0)
chenniges 4:67766287a6a0 193 {
chenniges 4:67766287a6a0 194 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 195 wait(5);
chenniges 4:67766287a6a0 196 lcd.cls();
chenniges 4:67766287a6a0 197 lcd.printf("If you would like to see other \ntypes of coins as well, please \nuse switch again.");
chenniges 4:67766287a6a0 198 wait(5);
chenniges 4:67766287a6a0 199 lcd.cls();
chenniges 4:67766287a6a0 200 }
chenniges 4:67766287a6a0 201 }*/
mark1998 3:c9057d642843 202 //wait(5);
mark1998 3:c9057d642843 203 //lcd.cls();
mark1998 3:c9057d642843 204
mark1998 3:c9057d642843 205
mark1998 3:c9057d642843 206 lcd.printf("Please use the switch for finishing process.");
chenniges 4:67766287a6a0 207 //wait(4);
chenniges 4:67766287a6a0 208 while(switch1 == 0)
mark1998 3:c9057d642843 209 {
chenniges 4:67766287a6a0 210 }
chenniges 4:67766287a6a0 211 //do
chenniges 4:67766287a6a0 212 //{
chenniges 4:67766287a6a0 213 // if(switch1 == 1)
chenniges 4:67766287a6a0 214 //{
mark1998 3:c9057d642843 215 lcd.cls();
mark1998 3:c9057d642843 216 lcd.printf("Thank you for using 'Coounting Machine'. \nGood Bye. :-)");
mark1998 3:c9057d642843 217 wait(5);
mark1998 3:c9057d642843 218 lcd.cls();
chenniges 4:67766287a6a0 219 //}
chenniges 4:67766287a6a0 220 //}while (switch1 == 0);
chenniges 0:733afbfa4d3f 221 /*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 222 {
chenniges 0:733afbfa4d3f 223 lcd.printf("Please enter the mount of money you took:");
chenniges 0:733afbfa4d3f 224 scanf("%f",&tm);
chenniges 0:733afbfa4d3f 225 lcd.printf("%f",tm);
chenniges 0:733afbfa4d3f 226 wait(2);
chenniges 0:733afbfa4d3f 227 ta = ta-tm;
chenniges 0:733afbfa4d3f 228 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 229 }*/
chenniges 0:733afbfa4d3f 230
chenniges 0:733afbfa4d3f 231 return(0);
chenniges 0:733afbfa4d3f 232 }
mark1998 3:c9057d642843 233 //change all 1 to 0 at LDR1,2,...