2016 :: 아두이노 기초

프로젝트:: 무작정 프로세싱 (3)

실시간 레이더 그리기

 

void drawLine(){
  pushMatrix();
  translate(width/2, height);
  strokeWeight(4);
  stroke(98, 245, 31);
  line(0, 0, width/2*cos(radians(angle)), -width/2*sin(radians(angle)));
  popMatrix();
}

 

void drawObject(){
  pushMatrix();
  translate(width/2, height);
  strokeWeight(4);
  stroke(255, 10, 10); // red color
  float d = (width/2.0/30.0)*(float)distance;
  
  if( d < width/2)
    line(d*cos(radians(angle)), -d*sin(radians(angle)), width/2*cos(radians(angle)), -width/2*sin(radians(angle)));
  popMatrix();
}

 

중간코드

import processing.serial.*;

Serial myPort;
String myString = null;
int angle;
int distance;

void setup(){
  size(1200, 700);
  background(0);
  myPort = new Serial(this, "COM14", 9600);
}

void draw(){
  noStroke();
  fill(0, 7);
  rect(0, 0, width, height);
  
  //drawLine();
  drawObject();
}

void serialEvent(Serial p){
    try{
      myString = p.readStringUntil('.');
      if(myString != null){
        String[] list = split(myString, ',');
        angle = int(list[0]);
        distance = int(list[1].replace(".",""));
        
        print("Angle : "+angle);
        println(" Distance : "+distance + "cm");
      }
    }catch(Exception e){
    }
}

void drawLine(){
  pushMatrix();
  translate(width/2, height);
  strokeWeight(4);
  stroke(98, 245, 31);
  line(0, 0, width/2*cos(radians(angle)), -width/2*sin(radians(angle)));
  popMatrix();
}

void drawObject(){
  pushMatrix();
  translate(width/2, height);
  strokeWeight(4);
  stroke(255, 10, 10); // red color
  float d = (width/2.0/30.0)*(float)distance;
  
  if( d < width/2)
    line(d*cos(radians(angle)), -d*sin(radians(angle)), width/2*cos(radians(angle)), -width/2*sin(radians(angle)));
  popMatrix();
}

 

댓글

댓글 본문
  1. 네! dydwo92@snu.ac.kr로 보내주세요~:)
    대화보기
    • 김영우
      개인적으로 e-mail로 물어볼 수 있을까요 ?
      processing과 아두이노를 처음 접하는데 서로 통신으로 주고받는 부분이 이해가 안됩니다.
    • JustStudy
      고맙습니다
    버전 관리
    YJ
    현재 버전
    선택 버전
    graphittie 자세히 보기