Differences between revisions 1 and 34 (spanning 33 versions)
Revision 1 as of 2008-10-07 11:58:29
Size: 2605
Editor: dyn177231
Comment:
Revision 34 as of 2013-07-09 11:02:45
Size: 375
Editor: 178-117-154-240
Comment:
Deletions are marked like this. Additions are marked like this.
Line 1: Line 1:
<<TableOfContents>>

== Arduino in Processing ==

These functions are in the Processing Arduino Library and communicate (from Processing) with a Arduino, upon which the Firmata sketch has been installed.

 Arduino.list():: returns a list of the available serial devices. If your Arduino board is connected to the computer when you call this function, its device will be in the list.
 Arduino(parent, name, rate):: create an Arduino object. Parent should be "this" (without the quotes); name is the name of the serial device (i.e. one of the names returned by Arduino.list()); rate is the speed of the connection (115200 for the v2 version of the firmware, 57600 for v1). Note that in the v2 library, the rate parameter is optional.
 pinMode(pin, mode):: set a digital pin to input or output mode (Arduino.INPUT or Arduino.OUTPUT).
 digitalRead(pin):: returns the value of a digital pin, either Arduino.LOW or Arduino.HIGH (the pin must be set as an input).
 digitalWrite(pin, value):: writes Arduino.LOW or Arduino.HIGH to a digital pin.
 analogRead(pin):: returns the value of an analog input (from 0 to 1023).
 analogWrite(pin, value):: writes an analog value (PWM wave) to a digital pin that supports it (pins 3, 5, 6, 9, 10, and 11); value should be from 0 (always off) to 255 (always on).

== Example ==

{{{#!java
import processing.serial.*;
import nl.tue.id.creapro.*;

Arduino arduino;
int ledPin = 13;

void setup()
{
  println(Arduino.list());
  arduino = new Arduino(this, "COM3"); // v2
  //arduino = new Arduino(this, Arduino.list()[0], 57600); // v1
  delay(2000);
  arduino.pinMode(ledPin, Arduino.OUTPUT);
  delay(50);
  arduino.pinMode(11, Arduino.INPUT);
  delay(50);
  arduino.analogEnable(0);
  delay(50);
  arduino.setAnalogStep(4);
  delay(50);
  arduino.setAnalogPullRate(500);
  delay(50);
  println("Starting...");
// arduino.clearCommandCount();
 (new Repeat()).start();
 delay(100);

  noLoop();
}

void draw()
{
}

void digitalAvailable11(int o, int n){
  println(n);
}

void analogAvailable0(int o, int n){
  println(n);
}

class Repeat extends Thread{
  public void run(){
    arduino.clearCommandCount();
      for (int i=0; i<8; i++){
  arduino.digitalWrite(ledPin, Arduino.HIGH);
  try{sleep(400);}catch(Exception e){}
  arduino.digitalWrite(ledPin, Arduino.LOW);
  try{sleep(400);}catch(Exception e){} }
  try{sleep(2000);}catch(Exception e){}
    arduino.reportCommandCount();
    arduino.reportCommandCount();
    arduino.reportCommandCount();
    arduino.reportCommandCount();
  }
  
}
}}}
My name is Rhys Arndt but everybody calls me Rhys. I'm from United States. I'm studying at the high school (final year) and I play the Dobro for 7 years. Usually I choose music from the famous films ;). <<BR>>
I have two sister. I love RC cars, watching movies and Juggling.<<BR>>
<<BR>>
My site ... [[http://www.printasy.com/beginnen-met-ecommerce/|Webwinkel beginnen]]

My name is Rhys Arndt but everybody calls me Rhys. I'm from United States. I'm studying at the high school (final year) and I play the Dobro for 7 years. Usually I choose music from the famous films ;).
I have two sister. I love RC cars, watching movies and Juggling.

My site ... Webwinkel beginnen

CreaPro: CreaproProcessingLibrary (last edited 2014-02-19 22:44:19 by JunHu)