title: Processing/Bluetooth to Arduino
body: <p>I want to light up a LED wirelessly through processing. </p>
  
  <p>what I have so far.</p>
  
  <ol>
  <li>I can (wirelessly) turn on my LED using a serial terminal called "Bluterm". </li>
  <li>I can turn on my LED by pressing 1 or 0 to switch LED on and off in processing.</li>
  </ol>
  
  <p>How can I leave Bluterm out of my equation and use processing to send the 1 and 0 through bluetooth. </p>
  
  <p>Here is my code for processing: </p>
  
  <pre><code>import processing.serial.*;
  
  Serial port;
  
  
  String string;
  void setup(){
      String portName = Serial.list()[2]; //change the 0 to a 1 or 2 etc. to match your port
      port = new Serial(this, portName, 9600);
      port.bufferUntil('\n');
  }
  
  void draw() {
  
    printArray(string); 
  }
  
  void keyPressed() { 
    if (key =='1'){port.write('1');}
      if (key=='0') {port.write('0');}
      }
  
      void serialEvent(Serial port) {
        string = port.readStringUntil('\n');}
  
  </code></pre>
  
  <p>and the Arduino code </p>
  
  <pre><code>
  char data;
  int led = 13;
  
  void setup() { 
    pinMode(led, OUTPUT);
    Serial.begin(9600); 
  
  }
  
  void loop() { 
    if (Serial.available()&gt;0){
      data = Serial.read(); 
    }
  
  
    if (data=='1'){
      Serial.println("HELLO");
      digitalWrite(led, HIGH);
  
  
      }
  
      else if (data=='0'){
        digitalWrite(led, LOW);
        Serial.println("BYE");}
      }
  
  </code></pre>
  
  <p>I'm kind of lost, can processing talk to bluetooth or do I always need a terminal? </p>
  
  <p>If something isn't clear pls don't hesitate to ask,</p>
  
  <p>Thank you for your time, </p>
  
  <p>Juriaan</p>