2016-06-28 3 views
0

좋아, Windows 10 PC에서 Arduino Uno와 Processing 3을 사용하고 있습니다. Arduino 웹 사이트의 지침을 따르려고합니다. PC 화면을 가로 질러 움직여서 LED의 밝기를 제어합니다. (여기에 내가 말하고있는 프로젝트에 대한 링크가 있습니다 : https://www.arduino.cc/en/Tutorial/Dimmer) 너무 단순 해 보이지만 아직 효과가 없습니다. LED가 켜지지 만 마우스의 X 위치에 따라 밝기가 달라지지 않으며 발광이 깜박입니다. 오류 코드가 없습니다.Arduino & Processing 3 : "Dimmer"내장 예제

회로에 관해서는, LED가 PWM 핀 9에 연결되어 있고 접지에 200 옴 저항이 있습니다. 나는 LED의 극성이 올바르게 설정되었는지 확신합니다. 이 웹 사이트에서는 Arduino 소프트웨어가 어떻게 처리되는지 정확히 처리하는 방법이 무엇인지 명확하지 않습니다. (가능한 경우 이에 대한 설명을 크게 부탁드립니다.) Arduino & 처리 코드는 다음과 같습니다. 내가 뭘 잘못하고 있는지 이해가 안돼?

const int ledPin = 9;  // the pin that the LED is attached to 

void setup() { 
    // initialize the serial communication: 
    Serial.begin(9600); 
    // initialize the ledPin as an output: 
    pinMode(ledPin, OUTPUT); 
} 

void loop() { 
    byte brightness; 

    // check if data has been sent from the computer: 
    if (Serial.available()) { 
    // read the most recent byte (which will be from 0 to 255): 
    brightness = Serial.read(); 
    // set the brightness of the LED: 
    analogWrite(ledPin, brightness); 
    } 
} 

가 여기 내 처리 코드입니다 : 여기

내 아두 이노 코드

: 알고 싶은 분들을 위해

import processing.serial.*; 

import cc.arduino.*; 

Arduino arduino; 

void setup() { 
    size(256, 150); 

    arduino = new Arduino(this, "COM3", 9600); 

} 

void draw() { 
    background(constrain(mouseX, 0, 255)); 

    arduino.analogWrite(9, constrain(mouseX, 0, 255)); // 

} 
+0

이 작성되어있어 지금 [arduino.se]에 더 적합 할 것이다. –

+0

문제의 범위를 좁히려면 도움을받을 수 있습니다. 하드 코딩 된 번호 만 보내도록 처리 코드를 단순화하십시오. 그게 효과가 있니? Arduino로 보내기보다는 마우스 값을 표시하는 별도의 처리 스케치를 만드시겠습니까? 그게 효과가 있니? 당신이 예상했던대로 작동하지 않는 몇 줄에 이르기까지 그 과정을 계속하십시오. –

+0

주로 처리 코드가 포함되어 있습니다. 마지막 라인은 Arduino에 직접 쓰려고했으나 Arduino 소프트웨어는이를 수행해야했습니다. –

답변

1

, 여기 내 기능 코드 Arduino 부분 :

const int ledPin = 9;  // the pin that the LED is attached to 

void setup() { 
    // initialize the serial communication: 
    Serial.begin(9600); 
    // initialize the ledPin as an output: 
    pinMode(ledPin, OUTPUT); 
} 

void loop() { 
    int brightness; 

    // check if data has been sent from the computer: 
    if (Serial.available()) { 
    // read the most recent byte (which will be from 0 to 255): 
    brightness = Serial.read(); 
    // set the brightness of the LED: 
    analogWrite(9, brightness); 
    } 

    delay(10); 
} 
(처리 3)

처리부는 :

import processing.serial.*; 

import cc.arduino.*; 

Serial arduino; 

void setup() { 
    size(256, 150); 

    arduino = new Serial(this, "COM3", 9600); 

} 

void draw() { 
    background(constrain(mouseX, 0, 255)); 

    arduino.write(constrain(mouseX, 0, 255)); // 
} 
+0

이것을 허용으로 표시 할 수 있습니다. –