Pages: [1]   Go Down
Author Topic: RGB code with Touchosc  (Read 1502 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 26
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Im using touchosc to control the level on the RGB LED, I have the touchosc layout on my ipod and its changing the processing on my computer. It changes the colour of the LED but not to red, green or blue.

Is this due to the Resistor, LED, or the code ?

Thanks

Code:
import cc.arduino.*;
import processing.serial.*;
import oscP5.*;
import netP5.*;

Arduino arduino;

OscP5 oscP5;

float redAmount = 0.0f;
float greenAmount = 0.0f;
float blueAmount = 0.0f;


void setup () {
  size(320, 480);
  background(0);
  oscP5 = new OscP5(this,8000);
  arduino = new Arduino(this, Arduino.list()[1],57600);
 
}


void draw (){
  background(redAmount, greenAmount, blueAmount);
 
  fill(0);
  //red rect
  stroke(255, 0, 0);
  rect(34,39,67,255);
  fill(50,40,40);
  rect(34,39+255,67,-redAmount);
 
  //green rect
  fill(0);
  stroke(0,255,0);
  rect(124,39,67,255);
  fill(40,50,40);
  rect(124,39+255,67,-greenAmount);
 
  //blue rect
  fill(0);
  stroke(0,0,255);
  rect(216,39,67,255);
  fill(40,40,50);
  rect(216,39+255,67,-blueAmount);
 
  //write to arduino
  arduino.analogWrite(11, int(redAmount));
  arduino.analogWrite(10, int(greenAmount));
  arduino.analogWrite(9, int(blueAmount));
 
 
 
 
}

void oscEvent(OscMessage theOscMessage){
  String addr = theOscMessage.addrPattern();
  float val = theOscMessage.get(0).floatValue();
  String iPadIP = "192.168.1.3"; // change this to the address of your iPad / iPhone
  println(addr);  // uncomment for debug print of all recieved messages
  if(addr.equals("/1/red")){ redAmount = val;}
  if(addr.equals("/1/green")){ greenAmount = val;}
  if(addr.equals("/1/blue")){ blueAmount = val;}




}
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 238
Posts: 24298
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
It changes the colour of the LED but not to red, green or blu
Are you saying you see colours, but never pure primaries?

What does your debug output tell you is going on?
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Offline Offline
Newbie
*
Karma: 0
Posts: 26
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Yeah, when I move the faders up and down there are some colours but not the primaries and the output im getting /1/red, /1/green and /1/blue?? Is this what you mean?
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 238
Posts: 24298
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

No, I'm asking what values is your Processing writing for the individual channels of red, green and blue.
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Offline Offline
Newbie
*
Karma: 0
Posts: 26
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Sorry, but i'm a new to this where am I looking for these values ? In the code? all the code is above ?
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 26
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi I have touchosc working with the arduino controlling the colour of the LEDs. But for some reason the RGB LEDs are constantly on, with all the colours been on at the same time I emit the primary colour I want eg Red.

I want to know how to have the LED off until I have an input?

Many thanks
« Last Edit: April 20, 2012, 08:34:24 am by barry1234 » Logged

New Zealand
Offline Offline
Full Member
***
Karma: 1
Posts: 105
Just this guy you know.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

What does the code look like?
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 26
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

This is in processing, going to the arduino.

Code:
import cc.arduino.*;
import processing.serial.*;
import oscP5.*;
import netP5.*;

Arduino arduino;

OscP5 oscP5;

float redAmount = 0.0f;
float greenAmount = 0.0f;
float blueAmount = 0.0f;


void setup () {
  size(320, 480);
  background(0);
  oscP5 = new OscP5(this,8000);
  arduino = new Arduino(this, Arduino.list()[1],57600);
 
}


void draw (){
  background(redAmount, greenAmount, blueAmount);
 
  fill(0);
  //red rect
  stroke(255, 0, 0);
  rect(34,39,67,255);
  fill(50,40,40);
  rect(34,39+255,67,-redAmount);
 
  //green rect
  fill(0);
  stroke(0,255,0);
  rect(124,39,67,255);
  fill(40,50,40);
  rect(124,39+255,67,-greenAmount);
 
  //blue rect
  fill(0);
  stroke(0,0,255);
  rect(216,39,67,255);
  fill(40,40,50);
  rect(216,39+255,67,-blueAmount);
 
  //write to arduino
  arduino.analogWrite(11, int(redAmount));
  arduino.analogWrite(10, int(greenAmount));
  arduino.analogWrite(9, int(blueAmount));
 
 
 
 
}

void oscEvent(OscMessage theOscMessage){
  String addr = theOscMessage.addrPattern();
  float val = theOscMessage.get(0).floatValue();
  String iPadIP = "192.168.1.3"; // change this to the address of your iPad / iPhone
  println(addr);  // uncomment for debug print of all recieved messages
  if(addr.equals("/1/red")){ redAmount = val;}
  if(addr.equals("/1/green")){ greenAmount = val;}
  if(addr.equals("/1/blue")){ blueAmount = val;}




}
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 238
Posts: 24298
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I really do hope I don't have to merge another of your cross posted threads.
Please consider this a final warning.
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Offline Offline
Newbie
*
Karma: 0
Posts: 26
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Some asked for the code, on the LED. I didn't intently put the code on because I knew you would say this. But if someone asks then I have to give it them. 
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 238
Posts: 24298
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

No, you didn't have to post the code again - you could have referred them to your other thread on the same subject.
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 547
Posts: 45982
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
No, you didn't have to post the code again - you could have referred them to your other thread on the same subject.
Even better, make up your mind where you want to ask the question, and ask it there. Quit running all over the place with the same problem. We do get tired of that, and will start ignoring you.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 26
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

My apologises.
Logged

New Zealand
Offline Offline
Full Member
***
Karma: 1
Posts: 105
Just this guy you know.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

In the setup put the line:
  Serial.begin(9600);  // serial debugging port
Unless your serial is already being used by
   arduino = new Arduino(this, Arduino.list()[1],57600);

Code:
  //write to arduino
  arduino.analogWrite(11, int(redAmount));
  arduino.analogWrite(10, int(greenAmount));
  arduino.analogWrite(9, int(blueAmount));

  Serial.print(int(redAmount));
  Serial.println(" redAmount");
  Serial.print(int(greenAmount));
  Serial.println(" greenAmount");
  Serial.print(int(blueAmount));
  Serial.println(" blueAmount"); 
}
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 505
Posts: 31343
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

barry1234

You are not helping  yourself by not saying what your setup actually is.
I assume you are using firmata on the arduino, but you haven't said. You also haven't said what sort of arduino you have because  firmata is not fully implemented on all arduinos, the mega in particular  does not implement all the calls.
You have not said how you have wired up the LEDs, current sourcing, current sinking what resistors you have used. I notice you say:-
Quote
Is this due to the Resistor,
There should be three resistors in your circuit not one.

To see the values you are sending from processing then add this line in the place after you do the arduino write:-
Code:
//write to arduino
  arduino.analogWrite(11, int(redAmount));
  arduino.analogWrite(10, int(greenAmount));
  arduino.analogWrite(9, int(blueAmount));
println("RGB value " + redAmount + " " + greenAmount + " " + blueAmount);
The values will be seen at the bottom of the processing window.
Logged

Pages: [1]   Go Up
Jump to: