SIXAXIS?

사용자 삽입 이미지

사용 센서 : Freescale MMA7260 – 제품 UST-SNR-ACCEL (구입처)

아두이노에 업로드용

int gSel1 = 6; // 6번핀 G SELECT1
int gSel2 = 7; // 7번핀 G SELECT2
int sleep = 3; // 3번핀 /SLEEP
int x = 0;       // A0 X축
int y = 1;       // A1 Y축
int z = 2;       // A2 Z축


void setup(){

  pinMode(gSel1, OUTPUT);
  pinMode(gSel2, OUTPUT);
  pinMode(sleep, OUTPUT);

  Serial.begin(9600);

// g-Range & Sensitivity
  digitalWrite(gSel1, LOW);   // LL 1.5g 800 HL 2g 600 LH 4g 300 HH 6g 200
  digitalWrite(gSel2, LOW);

  digitalWrite(sleep, HIGH);  // SLEEP 해제 HIGH

}

void loop(){
  Serial.print(analogRead(x));
  Serial.print(",");
  Serial.print(analogRead(y));
  Serial.print(",");
  Serial.println(analogRead(z));
  delay(10);
}

프로세싱용

import processing.serial.*;     // import the Processing serial library

int linefeed = 10;              // Linefeed in ASCII
Serial myPort;                  // The serial port
int graphPosition;
int[] lineXYZ = new int[3];

void setup() {


  size(630,480);
  background(0);

  println(Serial.list());

  myPort = new Serial(this, Serial.list()[1], 9600); // [1]은 리스트를 보고 자기가 쓰는 아두이노용 COM포트로 변경

  myPort.bufferUntil(linefeed);
}

void draw() {
  // 빨간색: X, 녹색: Y, 파란색: Z

  stroke(255,0,0);
  point(graphPosition,lineXYZ[0]);

  stroke(0,255,0);
  point(graphPosition,lineXYZ[1]);

  stroke(0,0,255);
  point(graphPosition,lineXYZ[2]);

  if (graphPosition >= width) {
    graphPosition = 0;
    background(0);
  }
  else{
    graphPosition ++;
  }

}


void serialEvent(Serial myPort) {
  // read the serial buffer:
  String myString = myPort.readStringUntil(linefeed);

  // if you got any bytes other than the linefeed:
  if (myString != null) {

    myString = trim(myString);

    int sensors[] = int(split(myString, ','));

    for (int sensorNum = 0; sensorNum < sensors.length; sensorNum++) {
      print("Senor" +  sensorNum + " : " + sensors[0] + "t");

   //센서 값(0~1023)을 대략 3으로 나누고(세로 해상도가 480) 근사값 정수만 취해서 각각의 그래프용 좌표에 대입
      lineXYZ[sensorNum] = ceil(sensors[sensorNum]/3);

    }
    println();
  }
}


000

댓글 남기기

이메일은 공개되지 않습니다. 필수 입력창은 * 로 표시되어 있습니다

이 사이트는 스팸을 줄이는 아키스밋을 사용합니다. 댓글이 어떻게 처리되는지 알아보십시오.