질문게시판 > lcd,바코드,서보모터, 아두이노 질문 드립니다. ㅠㅠ

TODAY849 TOTAL3,072,943
사이트 이용안내
Login▼/회원가입
최신글보기 질문게시판 기술자료 동영상강좌

아두이노 센서 ATMEGA128 PWM LED 초음파 AVR 블루투스 LCD UART 모터 적외선


BASIC4MCU | 질문게시판 | lcd,바코드,서보모터, 아두이노 질문 드립니다. ㅠㅠ

페이지 정보

작성자 아두이노개발자 작성일2023-09-26 11:24 조회735회 댓글1건

본문

	

바코드 인식을 LCD로 하는 과정에서 문제가 있어 질문 드립니다.

 

#include <usbhid.h>

#include <usbhub.h>

#include <hiduniversal.h>

#include <hidboot.h>

#include <SPI.h>

 

class MyParser : public HIDReportParser {

  public:

    MyParser();

    void Parse(USBHID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf);

  protected:

    uint8_t KeyToAscii(bool upper, uint8_t mod, uint8_t key);

    virtual void OnKeyScanned(bool upper, uint8_t mod, uint8_t key);

    virtual void OnScanFinished();

};

 

MyParser::MyParser() {}

 

void MyParser::Parse(USBHID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf) {

  // If error or empty, return

  if (buf[2] == 1 || buf[2] == 0) return;

 

  for (uint8_t i = 7; i >= 2; i--) {

    // If empty, skip

    if (buf[i] == 0) continue;

 

    // If enter signal emitted, scan finished

    if (buf[i] == UHS_HID_BOOT_KEY_ENTER) {

      OnScanFinished();

    }

 

    // If not, continue normally

    else {

      // If bit position not in 2, it's uppercase words

      OnKeyScanned(i > 2, buf, buf[i]);

    }

 

    return;

  }

}

 

uint8_t MyParser::KeyToAscii(bool upper, uint8_t mod, uint8_t key) {

  // Letters

  if (VALUE_WITHIN(key, 0x04, 0x1d)) {

    if (upper) return (key - 4 + 'A');

    else return (key - 4 + 'a');

  }

 

  // Numbers

  else if (VALUE_WITHIN(key, 0x1e, 0x27)) {

    return ((key == UHS_HID_BOOT_KEY_ZERO) ? '0' : key - 0x1e + '1');

  }

 

  return 0;

}

 

void MyParser::OnKeyScanned(bool upper, uint8_t mod, uint8_t key) {

  uint8_t ascii = KeyToAscii(upper, mod, key);

  Serial.print((char)ascii);

}

 

void MyParser::OnScanFinished() {

  

}

 

USB          Usb;

USBHub       Hub(&Usb);

HIDUniversal Hid(&Usb);

MyParser     Parser;

 

void setup() {

  Serial.begin( 115200 );

  

  if (Usb.Init() == -1) {

    Serial.println("OSC did not start.");

  }

 

  delay( 200 );

 

  Hid.SetReportParser(0, &Parser);

}

 

void loop() {

  Usb.Task();

}

 

------------------------------------------------------------------------------------------------------------------------------------------------------------------------

 

#include <Servo.h>

#include <LiquidCrystal_I2C.h>

#include <Wire.h>

 

LiquidCrystal_I2C lcd(0x27, 16, 2);

Servo servo1;

Servo servo2;

int Trig1 = 10;

int Echo1 = 11;

int Trig2 = 8;

int Echo2 = 9;

int ultrasonic_1 = 2;

int ultrasonic_2 = 3;

 

int ultrasonic_num_1 = 0;

int ultrasonic_num_2 = 0;

 

unsigned long current_time;

unsigned long code1_time[5];

unsigned long code2_time[5];

 

int code1_count = 0;

int code2_count = 0;

 

int code1_count2 = 0;

int code2_count2 = 0;

 

int code1_num_1 = 0;

int code2_num_1 = 0;

 

int code1_num_2 = 0;

int code2_num_2 = 0;

 

char recieved_data;

int recieved_data_num;

 

void setup() {

  Serial.begin(115200);

 

  lcd.init();

  lcd.backlight();

  pinMode(Trig1, OUTPUT);

  pinMode(Echo1, INPUT);

  pinMode(Trig2, OUTPUT);

  pinMode(Echo2, INPUT);

  pinMode(ultrasonic_1, OUTPUT);

  pinMode(ultrasonic_2, OUTPUT);

  

  servo1.attach(6);

  servo2.attach(5);

 

  servo1.write(0);

  servo2.write(0);

}

 

void loop() {

  current_time = millis();

  

  if(Serial.available()) {

    recieved_data = Serial.read();

    Serial.println(recieved_data);

    }

    

  lcd.setCursor(0,0);

  lcd.print("Black_  RED_    ");

 

  if(recieved_data == '1') {

    code1_time[code1_count] = current_time + 3400; //3초 후

    code1_num_1 = 1;

    code1_count++;

    code1_count2++;

    }

  lcd.setCursor(0,1);

  lcd.print("IN:");

  lcd.setCursor(3,1);

  lcd.print(code1_count2);

  for(int i = 0; i < 5; i++) {

    if((code1_num_1 == 1) && (code1_time[i] < current_time) && (current_time < code1_time[i] + 250)) {

      code1_num_2 = 1;

      }

    }

  if(code1_num_2 == 1) {

    servo1.write(40);

    code1_num_2 = 0;

    }

    else if(code1_num_2 == 0) {

      servo1.write(0);

      }

  

  if(recieved_data == '2') {

    code2_time[code2_count] = current_time + 5500; //5초 후

    code2_num_1 = 1;

    code2_count++;

    code2_count2++;

    }

  lcd.setCursor(8,1);

  lcd.print("IN:");

  lcd.setCursor(11,1);

  lcd.print(code2_count2);

  for(int i = 0; i < 5; i++) {

    if((code2_num_1 == 1) && (code2_time[i] < current_time) && (current_time < code2_time[i] + 250)) {

      code2_num_2 = 1;

      }

    }

  if(code2_num_2 == 1) {

    servo2.write(40);

    code2_num_2 = 0;

    }

    else if(code2_num_2 == 0) {

      servo2.write(0);

      }

 

  digitalWrite(Trig1, LOW);

  digitalWrite(Echo1, LOW);

  delayMicroseconds(2);

  digitalWrite(Trig1, HIGH);

  delayMicroseconds(10);

  digitalWrite(Trig1, LOW);

 

  unsigned long duration1= pulseIn(Echo1, HIGH);

  float distance1 = ((float)(340 * duration1) / 10000) / 2;

 

  digitalWrite(Trig2, LOW);

  digitalWrite(Echo2, LOW);

  delayMicroseconds(2);

  digitalWrite(Trig2, HIGH);

  delayMicroseconds(10);

  digitalWrite(Trig2, LOW);

 

  unsigned long duration2= pulseIn(Echo2, HIGH);

  float distance2 = ((float)(340 * duration2) / 10000) / 2;

 

  for(int i = 0; i < 5; i++) {

    if((code1_num_1 == 1) && (distance1 < 4) && (code1_time[i] - 1000 < current_time) && (current_time < code1_time[i] + 1000)) {

      ultrasonic_num_1 = 1;

      }

    }

  if(ultrasonic_num_1 == 1) {

    digitalWrite(ultrasonic_1, HIGH);

    } else {

      digitalWrite(ultrasonic_1, LOW);

      }

      

  for(int i = 0; i < 5; i++) {

    if((code2_num_1 == 1) && (distance2 < 4) && (code2_time[i] - 1000 < current_time) && (current_time < code2_time[i] + 1000)) {

      ultrasonic_num_2 = 1;

      }

    }

  if(ultrasonic_num_2 == 1) {

    digitalWrite(ultrasonic_2, HIGH);

    } else {

      digitalWrite(ultrasonic_2, LOW);

      }

  

  recieved_data = 0;

  if(code1_count == 4) {

    code1_count = 0;

    }

  if(code2_count == 4) {

    code2_count = 0;

    }

  ultrasonic_num_1 = 0;

  ultrasonic_num_2 = 0;

 

  delay(200);

  lcd.clear();

}

  • BASIC4MCU 작성글 SNS에 공유하기
  • 페이스북으로 보내기
  • 트위터로 보내기
  • 구글플러스로 보내기

댓글 1

조회수 735

master님의 댓글

master 작성일

동일한 회로를 가지고 있고
회로 연결도 동일하게 했을 경우에만
동일한 증상을 겪을 수 있습니다.
불가능하겠죠?

설명을 많이 하셔야 할 것 같습니다.

질문게시판HOME > 질문게시판 목록

MCU, AVR, 아두이노 등 전자공학에 관련된 질문을 무료회원가입 후 작성해주시면 전문가가 답변해드립니다.
ATMEGA128PWMLED초음파
아두이노AVR블루투스LCD
UART모터적외선ATMEGA
전체 스위치 센서
질문게시판 목록
제목 작성자 작성일 조회
공지 MCU, AVR, 아두이노 등 전자공학에 관련된 질문은 질문게시판에서만 작성 가능합니다. 스태프 19-01-15 23059
공지 사이트 이용 안내댓글[30] master 17-10-29 36174
질문 ATmega128 to ATmega128로 USART 통신 질문 새글 alsdn 23-12-08 45
답변 답변글 답변 : ATmega128 to ATmega128로 USART 통신 질문 새글 master 23-12-08 50
질문 네오픽셀 Rainbow코드 LED주소 지정하는 법 문의 손문일 23-12-08 32
답변 답변글 답변 : 네오픽셀 Rainbow코드 LED주소 지정하는 법 문의댓글[2] master 23-12-08 48
질문 아두이노 L9110 DC모터 제어댓글[1] wdsdd 23-12-08 61
질문 Atmega128 CLCD와 블루투스 통신 문제댓글[1] fanfan 23-12-07 84
답변 답변글 답변 : Atmega128 CLCD와 블루투스 통신 문제댓글[3] master 23-12-07 80
질문 스마트팜 관련 질문댓글[1] 이미지첨부파일 생물공학도 23-12-07 43
질문 아두이노 자판기 질문입니다댓글[1] 한세월두세월 23-12-06 76
답변 답변글 답변 : 아두이노 자판기 질문입니다 master 23-12-07 38
질문 atmega128 질문있습니다댓글[1] 이미지첨부파일 아자자자자자 23-12-06 91
질문 스텝모터 제어 및 온도센서 값 동시 추출 질문드립니다.댓글[1] metanoia 23-12-06 37
질문 ATmega128에서 LCD와 블루투스 fanfan 23-12-05 130
답변 답변글 답변 : ATmega128에서 LCD와 블루투스댓글[1] master 23-12-05 164
질문 atmega128 압력센서 관해댓글[2] 메시기모찌 23-12-04 150
질문 안녕하세요 심장박동센서를 이용해 일정 심박수 이상이되면 부저 작동에 대해서 질문드립니다.댓글[8] 충전공 23-12-04 163
질문 atmega128 CLCD댓글[2] 릴를 23-12-03 258
질문 atmega128 블루투스 CLCD댓글[3] 릴를 23-12-03 230
질문 pwm을 이용한 led댓글[1] 이미지첨부파일 아자자자자자 23-12-02 99
질문 스텝모터, 컬러센서를 이용한 아두이노댓글[3] 초식동물 23-12-02 146
질문 조도 센서를 이용하여 pwm모드로 led밝기 조절 아자자자자자 23-12-02 85
답변 답변글 답변 : 조도 센서를 이용하여 pwm모드로 led밝기 조절댓글[2] master 23-12-02 59
질문 RFID를 이용한 자판기 질문입니다.댓글[1] 왕초보두이노 23-12-02 74
질문 ATMEGA 128 초음파 센서 거리에 따른 부저 작동 질문드립니다.댓글[7] 충전공 23-12-02 382
질문 atmega128a 외부인터럽트 두개와 7segment의 연결 우엉 23-12-02 117
답변 답변글 답변 : atmega128a 외부인터럽트 두개와 7segment의 연결 master 23-12-02 111
질문 atmega128 스위치 서보모터댓글[1] 메시기모찌 23-12-02 238
질문 atmega128 모터 질문입니다댓글[4] 이미지 릴를 23-12-01 215
게시물 검색

2022년 1월 2월 3월 4월 5월 6월 7월 8월 9월 10월 11월 12월
2021년 1월 2월 3월 4월 5월 6월 7월 8월 9월 10월 11월 12월
2020년 1월 2월 3월 4월 5월 6월 7월 8월 9월 10월 11월 12월
2019년 1월 2월 3월 4월 5월 6월 7월 8월 9월 10월 11월 12월
2018년 1월 2월 3월 4월 5월 6월 7월 8월 9월 10월 11월 12월
Privacy Policy
MCU BASIC ⓒ 2020
모바일버전으로보기