Connect RGB led on arduino to mouseclick on processing.

edited November 2017 in Arduino

Hello,

Im working on a project with arduino and processing. On my UNO board I have an RGB led. On my processing screen I have the colors Red Green and Blue by a mouseclick. So when I click the screen it goes from red to green and when I click again it goes to blue etc. The processing part works, thanks to @GoToLoop. For the connection from processing to arduino I used an example from processing called arduino_output. So I have both parts, seperately, but now I have to put them together. First I just put both completely together and that kinda worked but not good. I hope someone with a sharp eye can point out to me what to do. Btw, for arduino code I use the Standardfirmata code. Also, in the example arduino_output you have to click once to turn the led on and once to turn it off. In my program I just want that when I click it lights up and when I click again it just changes to the next color.

Processing code combined with arduino_output program :

import processing.serial.*;
import cc.arduino.*;

Arduino arduino;

static final color[] KLEUREN = { #FF0000, #008000, #0000FF };
int kleurindex;
int[] values = { Arduino.LOW, Arduino.LOW, Arduino.LOW };

void setup() {
  size(300, 200);
  noLoop();
  colorMode(RGB);
  println(Arduino.list());
  arduino = new Arduino(this, Arduino.list()[0], 57600);
  for (int i = 0; i<=13; i++)
      arduino.pinMode(i, Arduino.OUTPUT);
}

void draw() {
  final color c = KLEUREN[kleurindex];
  background(c);
  /*for (int i = 0; i <= 13; i++) {
    if (values[i] == Arduino.HIGH)
      fill(on);
    else
       fill(off); }*/

}

void mousePressed() {
  kleurindex = (kleurindex + 1) % KLEUREN.length;
  redraw();
  int pin = (450 - mouseX) / 30;        //this is still of the part where you have to click in a box to change color. don't know how to change that part.
   if (values[pin] == Arduino.LOW) {
    arduino.digitalWrite(pin, Arduino.HIGH);
    values[pin] = Arduino.HIGH;
  } else {
    arduino.digitalWrite(pin, Arduino.LOW);
    values[pin] = Arduino.LOW;
  }

}

ps. where you read 'kleuren' or something with 'kleur' it means color.

Tagged:

Answers

  • Answer ✓

    It has been solved by a classmate of mine, so dont bother. And I'll just keep it on here since I've been told not to delete my posts. So I won't

  • But if someone could write a comment then I can at least mark this disccusion answered.

Sign In or Register to comment.