2012-12-11 5 views
1

내 프로젝트는 두 센서의 값에 따라 개폐되는 동시에 두 개의 센서가있는 로봇 Arduino 꽃을 만드는 것입니다. 해당 값에 따라 처리를 통해 비디오를.Arduino 빛 센서 값을 사용하여 비디오를 처리하기

저는 Arduino의 아날로그 센서 값을 처리하는 데 너무 어려움을 겪었습니다. 이것은 내가 지금까지 무엇을 가지고 :

아두 이노

#include <Servo.h> 

Servo myservo; 
int pressure = 0; 
int light = 1; 
int pre; 
int val; 

void setup() 
{ 
    Serial.begin(9600); 
    myservo.attach(2); 
} 

void loop() { 
    pre = analogRead(pressure); 
    pre = map(pre, 918, 1023, 255, 0); 

    val = analogRead(light); 
    val = map(val, 0, 255, 0, 127); 
    Serial.print(val, DEC); 
    /*if (val>50) { 
     Serial.print(1); 
    } 
    else { 
     Serial.print(0); 
    }*/ 

    myservo.write(val); 
} 

처리

난 그냥 광 센서에 반응을 비디오를 만들기 위해 노력하고있어,하지만하지 않은 지금
import processing.video.*; 
import processing.serial.*; //arduino 
Serial myPort; // Create object from Serial class 
int val; 


Movie movie; 

void setup() { 
    String portName = Serial.list()[0]; 
    myPort = new Serial(this, portName, 9600); 
    size(640, 360); 
    background(0); 
    movie = new Movie(this, "transit.mov"); 
    movie.loop(); 

} 

void movieEvent(Movie m) { 
    m.read(); 
} 

void draw() { 
    val = myPort.read(); 
    println(val); 
    //if (movie.available() == true) { 
    // movie.read(); 
    //} 
    image(movie, 0, 0, width, height); 
    if (val==49) { 
    movie.jump(1); 
    } 
} 

할 수 있는. Processing reading에서 얻은 것은 48입니다. 모터는 센서에 잘 반응합니다.

답변

0

간단한 출력에서 ​​어떤 결과를 얻을 수 있습니까? 이처럼 스케치를 처리 하시겠습니까? 어떤 출력을 기대합니까? 또한

import processing.serial.*; 

Serial myPort; // The serial port 

void setup() { 
    // List all the available serial ports 
    println(Serial.list()); 
    // Open the port you are using at the rate you want: 
    myPort = new Serial(this, Serial.list()[0], 9600); 
} 

void draw() { 
    while (myPort.available() > 0) { 
    int inByte = myPort.read(); 
    println(inByte); 
    } 
} 

, 왜 아두 이노 코드 pre = map(pre, 918, 1023, 255, 0);의지도 기능은 하한 250과 0을 사용하고 상단에 각각 결합? 그것은 거꾸로 보인다. pre = map(pre, 918, 1023, 0, 255);을 읽어야합니까?

관련 문제