Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
GeekTree0101 opened this issue Nov 22, 2016 · 1 comment
Open

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

GeekTree0101 opened this issue Nov 22, 2016 · 1 comment

Comments

@GeekTree0101
Copy link
Owner

GeekTree0101 commented Nov 22, 2016

[브릿지 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;
              }      
        }
@GeekTree0101
Copy link
Owner Author

참고로 업데이트 된 소스는 arduino(src)에 위치해있습니다.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant