Hi everyone
This is my first post here and require so help with a programming issue I'm having I am trying to send three values from processing to Arduino so they are stored in different variables. When printing the processing program works accordingly to check if my values were being sent to the Arduino I connected a LED to see if the brightness would change when moving one of the sliders however nothing happens. I thing the issue is trying to convert from byte format to int or the values are stored as ASCII values.
Processing Code:
import controlP5.*;
import processing.serial.*;
Serial port;
ControlP5 cp5;
PFont font;
color currentcolor;
void setup(){
** size(1000, 450);**
** port = new Serial(this, "COM2", 9600);//Choose correct COM number which is your Arduino board connected to:**
** cp5 = new ControlP5(this);**
** font = createFont("Calibri", 30);**
** cp5.addSlider("Scale")**
** .setPosition(150, 200)**
** .setSize(500,70)**
** .setRange(0,100)**
** .setValue(0)**
** .setFont(font)**
** .setColorValue(color(0,0,255))**
** .setColorBackground(color(100, 100, 255))**
** ;**
** cp5.addSlider("Octave")**
** .setPosition(150, 300)**
** .setSize(500,70)**
** .setRange(0,100)**
** .setValue(102)**
** .setFont(font)**
** .setColorValue(color(0,0,255))**
** .setColorBackground(color(100, 100, 255))**
** ; **
** cp5.addSlider("Transposition")**
** .setPosition(150, 100)**
** .setSize(500,70)**
** .setRange(0,100)**
** .setValue(102)**
** .setFont(font)**
** .setColorValue(color(0,0,255))**
** .setColorBackground(color(100, 100, 255))**
** ; **
}
void draw(){
** background(50, 0 ,100);**
** fill(200, 200,255);**
** text("LED Control",350, 50);**
** textSize(30);**
** int octave = int(cp5.getController("Octave").getValue());**
** int scale = int(cp5.getController("Scale").getValue());**
** int transposition = int(cp5.getController("Transposition").getValue());**
** byte out[] =new byte[3];**
** out[0]=byte(octave);**
** out[1]=byte(scale);**
** out[2]=byte(transposition);**
** println(out);**
** port.write(out);**
}
Arduino Code:
int currentValue = 0;
#define LED 11
int values[] = {0,0,0};
int Oct;
int Sca;
int Tran;
void setup() {
** Serial.begin(9600);**
** pinMode(LED,OUTPUT);**
**} **
void loop() { **
** if(Serial.available()){
** int incomingValue = Serial.read();**
** values[currentValue] = incomingValue;**
** if(currentValue<1){**
** Oct=values[currentValue];**
** currentValue++; **
** analogWrite(LED,Oct); **
** }**
** if(currentValue<2&& currentValue>0){**
** Sca=values[currentValue];**
** currentValue++;**
** }**
** if(currentValue<3&& currentValue>1){**
** Tran=values[currentValue];**
** currentValue++;**
** }**
** }**
}
Any help would be greatly appreciated.
Thanks
Goose