Pages: [1]   Go Down
Author Topic: Arduino output for Processing  (Read 826 times)
0 Members and 1 Guest are viewing this topic.
Basel, CH
Offline Offline
Jr. Member
**
Karma: 1
Posts: 87
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello guys, I gave a small update to the sketch for Processing arduino_output adding a few details and enhancements possible with all the comments. I wanted to make it public here for the magnitude of all those who wish to use or download from here: http://bit.ly/zGeRfb

Code:
/* Arduino OUTPUT
 * Updated 12 Marzo 2012
 * By Rei Kurti
 
 *  Program to check the status of the 13-pin of Arduino UNO by PC
    in this case used to control 13 LEDs. the program
    allows you to press 13 buttons each corresponding to an output
    blinking the corresponding LED. Via the serial
    you can view the status of the LEDs.                                                                             
 */

// Import the processing.serial.*, cc.arduino.* libraries
import processing.serial.*;
import cc.arduino.*;

Arduino arduino;
color stro = color (0, 0, 0);         // color of the contours of the buttons (stroke).
color back = color(222, 222, 222);    // Background color.
color off = color(131, 17, 17);       // Color of the button when you don't press it(fill on).
color on = color(255, 36, 36);        // Color of the button when you press it (fill off).

int[] values = { Arduino.LOW, Arduino.LOW, Arduino.LOW, Arduino.LOW,
 Arduino.LOW, Arduino.LOW, Arduino.LOW, Arduino.LOW, Arduino.LOW,
 Arduino.LOW, Arduino.LOW, Arduino.LOW, Arduino.LOW, Arduino.LOW };
//------------------------------------------------------------------------------------------------------------+
void setup() {
 
  size(470, 200);  // Dimensions of the box
 
  println(Arduino.list());                                    // VIEW ON THE SERIAL THE COM PORT CONNECTED ON PC
  arduino = new Arduino(this, Arduino.list()[1], 57600);      // Setting the COM port you are connected tO
 
  for (int i = 0; i <= 13; i++)
    arduino.pinMode(i, Arduino.OUTPUT);
 
  println(" ");                    // VIEW EMPTY SPACE ON THE SERIAL
  println(" START PROGRAM: ");     // VIEW THE WORDS "START PROGRAM" ON THE SERIAL
  println(" -------------- ");     // VIEW DASHES ON THE SERIAL
}
//-------------------------------------------------------------------------------------------------------------+
void draw() {
 
  background(back);    // Setting the background colour as back --> color(222, 222, 222).
  stroke(stro);        // Setting the contours colour as stro --> color (0, 0, 0).
 
  for (int i = 0; i <= 13; i++) {     // Var i=0,
    if (values[i] == Arduino.HIGH)    // If the value of i is equivalent to Arduino.HIGH ...
      fill(on);                       // then the button is lit ...
    else                              // if not  ...
      fill(off);                      // then the button is off.       
    rect(420 - i * 30, 30, 20, 20);   // draw buttons
  }
  textSize(15);                                               // text size
  fill(#09647C);                                              // text colour
  text("Programma controllo LED a comando :", 28, 20);        // Writes the text in brackets + coordinates (text, x, y)
}
//-------------------------------------------------------------------------------------------------------------+
void mousePressed() {
 
  int pin = (450 - mouseX) / 30;      // Set variable pin
 
  if (values[pin] == Arduino.LOW) {
    arduino.digitalWrite(pin, Arduino.HIGH);
    values[pin] = Arduino.HIGH;   
    println(" LED "+pin+ " ON ");     // VIEW ON THE SERIAL THAT IS LED ON WHEN PRESSED.
   
  } else {
   
    arduino.digitalWrite(pin, Arduino.LOW);
    values[pin] = Arduino.LOW;   
    println(" LED "+pin+ " OFF ");    // VIEW ON THE SERIAL LED OFF THAT IS WHEN PRESSED.
  }
}
//--------------------------------------------------------------------------------------------------------------+
Logged

Pages: [1]   Go Up
Jump to: