Arduino的(处理)图书馆Netbeans和控制 [英] Arduino (processing) Library in Netbeans and control

查看:286
本文介绍了Arduino的(处理)图书馆Netbeans和控制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图控制4个LED和4个触点获得模拟输入。该方案是用Java编写的,因此要获得存取权限的Arduino的功能,如AnalogRead(),并设置一个LED为高或低,会导入处理库让程序使用这些功能呢?

I am trying to control 4 LEDs and getting analog input from 4 contacts. The program is written in java, so to gain acces to the functions of arduino, such as AnalogRead() and setting an LED to high or low, would importing the processing library let the program use those functions?

我也想知道,如果程序,将被转移到Arduino它自我,或Java程序会从内部上拉的数据?

I was also wondering, if the program, will be transferred to the arduino it self, or the java program will just pull the data from the pins?

推荐答案

更新:我的建议是首先尝试都由你自己与处理通信的Arduino的。这是我在下面说明。如果您想直接跳到直接与加工控制Arduino的,由二进制书呆子提供的链接是让你开始你的最佳选择。

Update: My suggestion is to first try communicating the Arduino with Processing by youself. This is what I describe below. If you want to jump straight to controlling the Arduino directly with Processing, the link provided by Binary Nerd is your best choice to get you started.

更新2 :尝试此链接,以及: Netbeans和处理

Update 2: Try this link as well: Netbeans and Processing

Arduino的code Arduino上运行,并处理code在计算机上运行。如果你想通过控制处理您的Arduino,你很可能会使用串行端口,并创建两个项目。一,Arduino上,可能会收到命令和执行操作(打开LED或关闭),或发送回的答案。另外,在加工,可以发送Arduino的必要的命令和处理它的答案,以某种方式。

Arduino code runs on the Arduino, and Processing code runs on your computer. If you want to control your Arduino through Processing, you will most likely use the serial port, and create two programs. One, on the Arduino, might receive commands and perform actions (turn LEDs on or off), or send back answers. The other, in Processing, might send the Arduino the necessary commands and process it's answers in some way.

下面是我的一个LED和一个模拟输入制作一个简单的例子。这是未经测试code。按照步骤。一旦这个工作,你可以尝试使用直接处理与Arduino的Netbeans中。

Here is a quick example I made for one LED and one analog input. This is untested code. Follow the steps. Once this has worked, you could try using Processing directly with the Arduino in Netbeans.

第1步的Arduino


  1. 买​​一个Arduino板。

  2. 下载Arduino的IDE(http://www.arduino.cc)

  3. Arduino的连接到您的计算机。

  4. Arduino的code(下)复制到Aruino IDE。

  5. 上传到Arduino。

步骤2。处理


  1. 下载处理IDE。

  2. 的处理code(下)复制到处理IDE。

  3. 确保在code中的COM端口是一个Arduino的连接。

  4. 运行处理code。

Arduino的code:

Arduino code:

int ledPin = 13;
int analogPin = 0;
char c = 0;

void setup()
{
    pinMode( ledPin, OUTPUT );
    Serial.begin( 9600 );
}

void loop()
{
    // Wait for a character to arrive at the serial port.
    if( Serial.available() > 0 )
    {
        // Read one byte (character).
        c = Serial.read();
        switch( c )
        {
            case '1':
                // Turn LED on.
                digitalWrite( ledPin, HIGH );
                break;
            case '0':
                // Turn LED off.
                digitalWrite( ledPin, LOW );
                break;
            case 'q':
            case 'Q':
                // Send the reading from the analog pin throught the serial port.
                Serial.println( analogRead( analogPin ) );
                break;
        }
    }
}

处理code(您的计算机上运行)。

Processing code (runs on your computer).

import processing.serial.*;

Serial serial;
String str;

void setup()
{
    size(400, 400);
    serial = new Serial(this, "COM1", 9600);    // Use the serial port connected
                                                // to your Arduino.
    while( true )
    {
        serial.write( '1' );        // Turn LED on.
        delay( 1000 );              // Wait one second
        serial.write( '0' );        // Turn LED off.
        delay( 1000 );
        serial.write( 'Q' );        // Get analog reading
        serial.bufferUntil( 10 );   // Wait for the data from the Arduino.
                                    // This captures characters until a newline
                                    // is received, the runs serialEvent()...
    }
}

void draw()
{
    background(0);
}

void serialEvent(Serial s)
{
    println( s.readString() );
}

这篇关于Arduino的(处理)图书馆Netbeans和控制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆