hello guys am trying to read barcodes using a CCD camera module, and diplay the product details, the code is working so far but I am not able to get the total amount to display since the database uses an array of strings and not integers.
[#include <LiquidCrystal.h>
#include <PS2Keyboard.h>
const int DataPin = 2;
const int IRQpin = 3;
LiquidCrystal lcd(12, 11, 7, 6, 5, 4);
PS2Keyboard barCodeScanner;
//creating database
const int NUMBER_OF_PRODUCTS = 10;
const int MAX_SCANNED_PRODUCTS = 15;
String ERROR_MSG = "Invalid barcode";
String productNames[NUMBER_OF_PRODUCTS] = {"Product_1","Product_2","Product_3","Product_4","Product_5","Product_6","Product_7","Product_8","Product_9","Product_10"};
String productBarCodes[NUMBER_OF_PRODUCTS] ={"61600997","5011501040520","6003001005610","6161101530743","ssdfsdgsdfgsdf","ssdfsdgsdfgsdf","ssdfsdgsdfgsdf","ssdfsdgsdfgsdf","ssdfsdgsdfgsdf","ssdfsdgsdfgsdf"};
String productPrices[NUMBER_OF_PRODUCTS] ={"120","200","250","900","60","300","200","ssdfsdgsdfgsdf","ssdfsdgsdfgsdf","ssdfsdgsdfgsdf"};
String scannedProducts[MAX_SCANNED_PRODUCTS] = {"xxx","xxx","xxx","xxx","xxx","xxx","xxx","xxx","xxx","xxx","xxx","xxx","xxx","xxx","xxx"};
String addProductPrices="";
int numScannedProducts = 0;
String newProductPrices="" ;
String newProductBarCode = "";
String newProductName = "";
bool shoppingListSent = false;
int productIndex(String scannedBarcode) {
for (int i=0; i<NUMBER_OF_PRODUCTS; i++) {
if (scannedBarcode == productBarCodes[i]) {
return i;
}
}
return -1;
}
void addNewProduct(String newProductName){
scannedProducts[numScannedProducts++] = newProductName;//adds the number of products
}
void setup() {
Serial.begin(9600);
barCodeScanner.begin(DataPin, IRQpin);
}
void loop() {
if (barCodeScanner.available() /*&& (buttonState != HIGH)*/ && (!shoppingListSent) && (numScannedProducts < MAX_SCANNED_PRODUCTS)){
// read the next key
char c = barCodeScanner.read();
// check for some of the special keys
if (c == PS2_ENTER) {
newProductName = productNames[productIndex(newProductBarCode)]; //displays the product names
newProductPrices = productPrices[productIndex(newProductBarCode)]; //displays the product price
lcd.clear();
addNewProduct(newProductName);
// addNewProduct(int newProductPrices);
//lcd.print("Pr.#" + String(numScannedProducts) + ": " + newProductName);
Serial.println("NoP=" + String(numScannedProducts) + ": " + newProductName );
Serial.println("sh= " + newProductPrices );
Serial.println("Total= " );
newProductBarCode = "";
} else {
newProductBarCode.concat(c);
Serial.print(c);
}
}
}]
edited.ino (2.45 KB)