Connect USB HID Barcode Scanner and Scan any product. Add a case for storing your products in the database
Fork of USBHostKeyboard_HelloWorld by
Revision 7:4e0c80b26ba6, committed 2015-03-15
- Comitter:
- Parkz
- Date:
- Sun Mar 15 11:37:05 2015 +0000
- Parent:
- 6:10bb61d790cd
- Commit message:
- Scan a product from barcode scanner and display total bill amount & no. of items scanned. Just 4 products stored for reference
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r 10bb61d790cd -r 4e0c80b26ba6 main.cpp --- a/main.cpp Thu Mar 14 14:22:49 2013 +0000 +++ b/main.cpp Sun Mar 15 11:37:05 2015 +0000 @@ -1,12 +1,39 @@ #include "mbed.h" #include "USBHostKeyboard.h" - +int price=0,items=0,temp=0; +unsigned long long int code=0; DigitalOut led(LED1); - +void update_price(int p); void onKey(uint8_t key) { - printf("Key: %c\r\n", key); + printf("%c", key); + if(key!=0x0A) + { + temp=key; + temp-=48; + code=temp+code*10; + } + else + { + switch(code) + { + case 42204268: update_price(200); + break; + case 8906002080021: update_price(25); + break; + case 8904043901015: update_price(17); + break; + case 8904004403756:update_price(36); + break; } - +code=0; +} +} +void update_price(int p) +{ + items++; + price+=p; + printf("No. of items=%d\tPrice=Rs.%d\n",items,price); + } void keyboard_task(void const *) { USBHostKeyboard keyboard;