Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
349 views
in Technique[技术] by (71.8m points)

scanning the barcode and control led

I have a serial barcode scanner and Arduino Uno. I need to configuration..one Correct barcode scanning led on.

my code is

void setup ()
{
Serial.begin (9600);
 pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
   pinMode(5, OUTPUT);
}


void loop ()
{


if(Serial.available())
{
String command =Serial.readStringUntil('
');
Serial.println(command);
if(command =="1010007")
{
digitalWrite(3, HIGH);
digitalWrite(4,LOW);}
else
if(command !="1010007")
{digitalWrite(4,HIGH);
digitalWrite(5,HIGH);
digitalWrite(3,LOW);}


}}

im scanning barcode 1010007 it showing serial monitor g???? like this how to fix it

plz help

and i try another code it showing correctly barcode,,,,,i scan 1010007 serial monitor also same 1010007

but led not on...code is below,,,

#include <SoftwareSerial.h>

SoftwareSerial barcode = SoftwareSerial(2, 3, true); // RX, TX 
void setup()
{
 Serial.begin(9600);
 pinMode(3, OUTPUT);

 
 barcode.begin(9600);

 delay(1000);
}

void loop()
{
 if(barcode.available())
 {
   
  char data = barcode.read();
   Serial.write(data);
   
   if(data=="101007")
 {
 digitalWrite(3, HIGH);
 }
}}
    

   

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...