Hardware

Wiring board + 가속도 센서 시리얼 통신 테스트

maetel 2007. 1. 3. 05:09

Wiring

void setup() {
  Serial.begin(38400);
}

void loop() {
  if (Serial.real() == 65) {
    Serial.print((analogRead(0)/4));
    Serial.print((analogRead(1)/4));
    Serial.print((analogRead(2)/4));


Processing

import processing.serial.*;
Serial port;
float xpos;

void setup() {
  size(256,256);
  noStroke();
  println(Serial.list());
  port = new Serial(this, Serial.list()[2], 38400);
//  port.clear();
}
void draw(){
 
background(0);
while (port.available() > 0) {
  xpos = port.read();
}
rect(xpos,100,20,20);
}


Wiring

int ax = 0; //set the pin number
int ay = 1;
int az = 2;
int x = 0; //the value of acceleration on x-axis
int y = 0;
int z = 0;

void setup() {
  Serial.begin(38400);
}

void loop() {
  x = analogRead(ax); //read the value of analog pin 0
  y = analogRead(ay);
  z = analogRead(az);
  Serial.print(x/4);
  Serial.print(y/4);
  Serial.print(z/4); //write the scaled value to the serial port
}


 

된장... shielding... orz