Go Down

Topic: RGB code with Touchosc (Read 1 time) previous topic - next topic

barry1234

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: [Select]

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;}




}

AWOL

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?
"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.

barry1234

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?

AWOL

No, I'm asking what values is your Processing writing for the individual channels of red, green and blue.
"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.

barry1234

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

barry1234

#5
Apr 20, 2012, 03:32 pm Last Edit: Apr 20, 2012, 03:34 pm by barry1234 Reason: 1
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

hellonearthis


barry1234

This is in processing, going to the arduino.

Code: [Select]

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;}




}

AWOL

I really do hope I don't have to merge another of your cross posted threads.
Please consider this a final warning.
"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.

barry1234

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. 

AWOL

No, you didn't have to post the code again - you could have referred them to your other thread on the same subject.
"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.

PaulS

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.


hellonearthis

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: [Select]

  //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"); 
}

Grumpy_Mike

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: [Select]
//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.

Go Up