Skip to content

20161123 01:25 문제해결완료 #13

Description

@GeekTree0101

[브릿지 Serial 처리 해결]


    while(1){
        
         if(Serial1.available()){
                
                Serial1.flush();
                String str = Serial1.readStringUntil('*');
                str = Serial1.readStringUntil('/');
                function_state = str.toInt();
                str = Serial1.readStringUntil('/');
                X = str.toInt();
                str = Serial1.readStringUntil('/');
                Y = str.toInt();
                str = Serial1.readStringUntil('*');
                Serial_control_flag = true;   
                break;
         }
      }
                                

보내는 데이터를 * / [기능] / [X좌표] / [Y좌표] / *

  • 모양으로 스타트 비트, 종료 비트 설정

[에어포인트 기능 해결]

  1. 각각 버튼 기능별로 if문 처리된것을 if-else if 로 엮음으로 문제해결

        if(digitalRead(Click_button) == LOW && lock == 0){              //Click Function

            packet = packet + "*";
            packet = packet  + DATA_PASSPAGE; 
            packet = packet + "/";
            packet = packet + X ;
            packet = packet + "/";
            packet = packet + Y;
            packet = packet + "/";
            packet = packet + "*";
            Serial1.println(packet); 
            
            lock_check = true;
            lock++;
        }
        else if(digitalRead(Drawing_button) == LOW  && lock == 0){

            packet = packet + "*";
            packet = packet  + DATA_DRAWING ; 
            packet = packet + "/";
            packet = packet + X ;
            packet = packet + "/";
            packet = packet + Y;
            packet = packet + "/";
            packet = packet + "*";
            Serial1.println(packet); 
            
            lock++;
            drawing_flag = ~drawing_flag + 2;
            lock_check = true;
        }
        else if(digitalRead(ZoomIn_button) == LOW  && lock == 0){             //ZoomIn Function
            packet = packet + "*";
            packet = packet  + DATA_ZOOMIN; 
            packet = packet + "/";
            packet = packet + X ;
            packet = packet + "/";
            packet = packet + Y;
            packet = packet + "/";
            packet = packet + "*";
            Serial1.println(packet); 
            
            lock++;
            zoomin_flag = ~zoomin_flag + 2;
            lock_check = true;
        }
        else if(digitalRead(Motion_button) == LOW){              //Motion Control

            packet = packet + "*";
            packet = packet  + DATA_MOTION; 
            packet = packet + "/";
            packet = packet + X ;
            packet = packet + "/";
            packet = packet + Y;
            packet = packet + "/";
            packet = packet + "*";
            Serial1.println(packet); 
        }
        else{
       
            if( drawing_flag == true || zoomin_flag == true ){

            packet = packet + "*";
            packet = packet  + DATA_DEFAULT; 
            packet = packet + "/";
            packet = packet + X ;
            packet = packet + "/";
            packet = packet + Y;
            packet = packet + "/";
            packet = packet + "*";
            Serial1.println(packet); 

            }
        
        }
  1. locker 프로그램적인 카운터로 이용한 내부 딜레이 생성
    delay API 보다 훨씬 안정적

-> 기능을 수행할때마다 기능수행에 따른 딜레이가 있는데 이에 맞춰서 lock 기능을 이용하여 해결

전역변수부분 48 line



//Program Locker
unsigned int lock = 0;
boolean lock_check  = false;

lock 카운터 부분 76 line


        /*
         * Locker : 카운트 레지스터를 이용한 프로그래밍 적인 딜레이 연출
         * No delay() API
        */
        if(lock_check == true){
              
              lock++;
              
              if(lock > 400){
                lock = 0;
                lock_check = false;
              }      
        }

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions