Arduino library (processing) in Netbeans and management

I am trying to control 4 LEDs and get an analog input from 4 pins. The program is written in java, so in order to access the arduino functions, for example AnalogRead () and set the high or low LED, imports the processing library so that the program uses these functions?

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

+4
source share
2 answers

Update . My suggestion is to first try to contact Arduino with the processing yourself. Here is what I describe below. If you want to go directly to managing Arduino directly with Processing, the link provided by Binary Nerd is your best bet to get you started.

Update 2 . Try also this link: Netbeans and Processing


Arduino code runs on 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, can receive commands and perform actions (turn LEDs on or off) or send responses. Another, in processing, can send the necessary commands to Arduino and process its responses in some way.

Here is a brief example that I made for one LED and one analog input. This is unverified code. Follow the steps. Once this works, you can try using Processing directly from Arduino in Netbeans.

Step 1. Arduino

  • Buy an Arduino board.
  • Download the Arduino IDE ( http://www.arduino.cc )
  • Connect your Arduino to your computer.
  • Copy the Arduino code (below) into the Aruino environment.
  • Download to Arduino.

Step 2. Processing

  • Download the processing IDE.
  • Copy the processing code (below) into the processing environment.
  • Make sure the COM port in the code is the one that the Arduino is connected to.
  • Run the processing 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; } } } 

Processing code (executed 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() ); } 
+3
source

The idea of ​​using a processing library is that you load the standard firmware into arduino and then use sequential messages to access arduino functions using java and processing.

This article should catch you: Arduino and handling

So, in your Java program, you can read the analog value from the input and change the value on the output output based on this reading.

0
source

Source: https://habr.com/ru/post/1307961/


All Articles