Dear All,
I have some trouble with my (barcode scanner - USB host shield - Arduino Uno) composition.
I have done everything according this topic: Manipulating data from a USB Barcode Scanner does not work - Programming Questions - Arduino Forum
and I could read the string the same way as you written there.
My project is to use this string as a variable to control leds. More clearly the process should be like this:
When i scan a barcode i have to attach this string some LEDs (outputs)
When i scan an othe code i have to attach this string some other LEDs.
and so on until 7 barcodes.
And when a read back one of these barcodes, the attached LEDs should be light up.
I have used some adressable led strips and serial monitor to try the mechanism like this code:
#include <FastLED.h>
#include "colorutils.h"
#include "colorpalettes.h"
#include <LiquidCrystal.h>
const int rs = 7, en = 6, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
#define NUM_LEDS 24 // adjust this to the number of LEDs you have: 16 or more
#define LED_TYPE WS2812B // adjust this to the type of LEDS. This is for Neopixels
#define DATA_PIN 14 // adjust this to the pin you've connected your LEDs to
#define BRIGHTNESS 64 // 255 is full brightness, 128 is half
#define SATURATION 255 // 0-255, 0 is pure white, 255 is fully saturated color
#define COLOUR 5 // 0-255 HUE chart
#define COLOR_ORDER GRB
#define NUM_MODES 2
#define UPDATES_PER_SECOND 100
CRGB leds [NUM_LEDS];
int ledMode = 0;
CRGBPalette16 currentPalette;
String barcodeOne;
String barcodeTwo;
String barcodeThree;
void setup() {
// put your setup code here, to run once:
delay( 2000 ); // power-up safety delay
FastLED.addLeds<LED_TYPE, DATA_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
FastLED.setBrightness( BRIGHTNESS );
allDark ();
lcd.begin(16, 2); // set up the LCD's number of columns and rows:
Serial.begin (9600);
}
void loop() {
// put your main code here, to run repeatedly:
writeOne:
Serial.println("Enter barcode1! ");
lcd.print ("Enter barcode1! ");
while (Serial.available()==0); //waiting for input
barcodeOne = Serial.readString(); // read srting
sectorOne();
Serial.print("the barcode1 is: ");
Serial.print(barcodeOne);
lcd.clear();
lcd.print ("the barcode1 is: ");
lcd.setCursor (0, 1);
lcd.print (barcodeOne );
Serial.println("Enter barcode2! ");
lcd.clear();
lcd.print ("Enter barcode2! ");
ceck:
while (Serial.available()==0); //waiting for input
barcodeTwo = Serial.readString(); // read srting
if (barcodeTwo == barcodeOne){
Serial.print ("Enter new code");
lcd.print ("Enter new code");
goto ceck;
}
sectorTwo();
Serial.print("the barcode2 is: ");
Serial.print(barcodeTwo);
lcd.clear();
lcd.print ("the barcode2 is: ");
lcd.setCursor (0, 1);
lcd.print (barcodeTwo );
Serial.println("Enter barcode3! ");
lcd.clear();
lcd.print ("Enter barcode3! ");
ceckTwo:
while (Serial.available()==0) { //waiting for input
}
barcodeThree = Serial.readString(); // read srting
if (barcodeThree == barcodeTwo||
barcodeThree == barcodeOne)
{Serial.print ("Enter new code" );
lcd.print ("Enter new code");
goto ceckTwo;
}
sectorThree();
Serial.print("the barcode3 is: ");
Serial.print(barcodeThree);
lcd.clear();
lcd.print ("the barcode2 is: ");
lcd.setCursor (0, 1);
lcd.print (barcodeThree );
Serial.println("Enter a barcode! ");
lcd.clear();
lcd.print ("Enter a barcode! ");
while (Serial.available()==0) { //waiting for input
}
String readBarcodeOne = Serial.readString();
lcd.clear();
if (readBarcodeOne == barcodeOne)
{sectorOne();
goto readOne;}
if (readBarcodeOne == barcodeTwo)
{sectorTwo();
goto readOne;}
if (readBarcodeOne == barcodeThree);
{sectorThree();
goto readOne;}
readOne:
Serial.println("Enter a barcode! ");
lcd.print ("Enter a barcode! ");
while (Serial.available()==0) { //waiting for input
}
String readBarcodeTwo = Serial.readString();
lcd.clear();
if (readBarcodeTwo == readBarcodeOne)
{Serial.println ("SZLAMB, EZ MÁR VOLT! Please enter a barcode! ");
lcd.print ("SZLAMB!");
lcd.setCursor (0, 1);
lcd.print ("Enter a barcode!");
goto readOne;}
if (readBarcodeTwo == barcodeOne)
{sectorOne();
goto readTwo;}
if (readBarcodeTwo == barcodeTwo)
{sectorTwo();
goto readTwo;}
if (readBarcodeTwo == barcodeThree);
{sectorThree();
goto readTwo;}
readTwo:
Serial.println("Enter a barcode! ");
lcd.print ("Enter a barcode! ");
while (Serial.available()==0) { //waiting for input
}
String readBarcodeThree = Serial.readString();
lcd.clear();
if (readBarcodeThree == readBarcodeOne ||
readBarcodeThree == readBarcodeTwo)
{Serial.println ("SZLAMB, EZ MÁR VOLT! Please enter a barcode! ");
lcd.print ("SZLAMB!");
lcd.setCursor (0, 1);
lcd.print ("Enter a barcode!");
goto readTwo;}
if (readBarcodeThree == barcodeOne)
{sectorOne();
goto writeOne;}
if (readBarcodeThree == barcodeTwo)
{sectorTwo();
goto writeOne;}
if (readBarcodeThree == barcodeThree);
{sectorThree();
goto writeOne;}
}
void sectorOne () {
fill_solid( leds, NUM_LEDS, CRGB(0,0,0));
leds[0]= CHSV (COLOUR,SATURATION,BRIGHTNESS); //HUE chart
leds[1]= CHSV (COLOUR,SATURATION,BRIGHTNESS);
leds[10]= CHSV (COLOUR,SATURATION,BRIGHTNESS);
leds[11]= CHSV (COLOUR,SATURATION,BRIGHTNESS);
leds[12]= CHSV (COLOUR,SATURATION,BRIGHTNESS);
leds[13]= CHSV (COLOUR,SATURATION,BRIGHTNESS);
leds[22]= CHSV (COLOUR,SATURATION,BRIGHTNESS);
leds[23]= CHSV (COLOUR,SATURATION,BRIGHTNESS);
FastLED.show();
delay (100);
}
void sectorTwo () {
fill_solid( leds, NUM_LEDS, CRGB(0,0,0));
leds[2]= CHSV (COLOUR,SATURATION,BRIGHTNESS);
leds[3]= CHSV (COLOUR,SATURATION,BRIGHTNESS);
leds[8]= CHSV (COLOUR,SATURATION,BRIGHTNESS);
leds[9]= CHSV (COLOUR,SATURATION,BRIGHTNESS);
leds[14]= CHSV (COLOUR,SATURATION,BRIGHTNESS);
leds[15]= CHSV (COLOUR,SATURATION,BRIGHTNESS);
leds[20]= CHSV (COLOUR,SATURATION,BRIGHTNESS);
leds[21]= CHSV (COLOUR,SATURATION,BRIGHTNESS);
FastLED.show();
delay (100);
}
void sectorThree () {
fill_solid( leds, NUM_LEDS, CRGB(0,0,0));
leds[4]= CHSV (COLOUR,SATURATION,BRIGHTNESS);
leds[5]= CHSV (COLOUR,SATURATION,BRIGHTNESS);
leds[6]= CHSV (COLOUR,SATURATION,BRIGHTNESS);
leds[7]= CHSV (COLOUR,SATURATION,BRIGHTNESS);
leds[16]= CHSV (COLOUR,SATURATION,BRIGHTNESS);
leds[17]= CHSV (COLOUR,SATURATION,BRIGHTNESS);
leds[18]= CHSV (COLOUR,SATURATION,BRIGHTNESS);
leds[19]= CHSV (COLOUR,SATURATION,BRIGHTNESS);
FastLED.show();
delay (100);
}
void allDark () {
fill_solid( leds, NUM_LEDS, CRGB(0,0,0));
FastLED.show();
delay (100);
}
The next code is in the next post...