Hey Lads,
I am running a processing sketch that sends serial inputs (1,2,3,4,5,6) to Arduino. (serial : 9600)
now I'm using Arduino to receive the serials and use them to control a led matrix.
Here are the codes:
Arduino:
#include <FastLED.h>
#define LED_PIN 13
#define NUM_LEDS 36
CRGB leds[NUM_LEDS];
void setup()
{
FastLED.addLeds<WS2812, LED_PIN, GRB>(leds, NUM_LEDS);
Serial.begin(9600);
FastLED.clear();
FastLED.show();
}
void loop()
{
if (Serial.available() > 0)
{
int incomingByte = Serial.read();
if (incomingByte > '0' && incomingByte < '7')
{
FastLED.clear(); // <-----<<<< USE clear
}
if (incomingByte == '1')
{
leds[0] = CRGB(255, 0, 0);
leds[6] = CRGB(255, 0, 0);
leds[12] = CRGB(255, 0, 0);
leds[18] = CRGB(255, 0, 0);
leds[24] = CRGB(255, 0, 0);
leds[30] = CRGB(255, 0, 0);
}
else if (incomingByte == '2')
{
leds[1] = CRGB(255, 0, 0);
leds[7] = CRGB(255, 0, 0);
leds[13] = CRGB(255, 0, 0);
leds[19] = CRGB(255, 0, 0);
leds[25] = CRGB(255, 0, 0);
leds[31] = CRGB(255, 0, 0);
}
else if (incomingByte == '3')
{
leds[2] = CRGB(255, 0, 0);
leds[8] = CRGB(255, 0, 0);
leds[14] = CRGB(255, 0, 0);
leds[20] = CRGB(255, 0, 0);
leds[26] = CRGB(255, 0, 0);
leds[32] = CRGB(255, 0, 0);
}
else if (incomingByte == '4')
{
leds[3] = CRGB(255, 0, 0);
leds[9] = CRGB(255, 0, 0);
leds[15] = CRGB(255, 0, 0);
leds[21] = CRGB(255, 0, 0);
leds[27] = CRGB(255, 0, 0);
leds[33] = CRGB(255, 0, 0);
}
else if (incomingByte == '5')
{
leds[4] = CRGB(255, 0, 0);
leds[10] = CRGB(255, 0, 0);
leds[16] = CRGB(255, 0, 0);
leds[22] = CRGB(255, 0, 0);
leds[28] = CRGB(255, 0, 0);
leds[34] = CRGB(255, 0, 0);
}
else if (incomingByte == '6')
{
leds[5] = CRGB(255, 0, 0);
leds[11] = CRGB(255, 0, 0);
leds[17] = CRGB(255, 0, 0);
leds[23] = CRGB(255, 0, 0);
leds[29] = CRGB(255, 0, 0);
leds[35] = CRGB(255, 0, 0);
}
FastLED.show();
}
}
and Processing
float x = 100;
float y = 50;
float w = 150;
float h = 80;
import org.openkinect.freenect.*;
import org.openkinect.processing.*;
import processing.serial.*;
// The kinect stuff is happening in another class
KinectTracker tracker;
Kinect kinect;
Serial myPort;
void setup() {
size(512, 424);
kinect = new Kinect(this);
tracker = new KinectTracker();
String portName = Serial.list()[3]; //change the 0 to a 1 or 2 etc. to match your port
myPort = new Serial(this, portName, 9600);
}
void draw() {
tracker.track();
tracker.display();
PVector v1 = tracker.getPos();
fill(50, 100, 250, 200);
noStroke();
ellipse(v1.x, v1.y, 50, 50);
//1
if (v1.x > 0 && v1.x < 50 ){
println('1');
//rect(0,200,200,200);
myPort.write('1'); }
//println('0'); }
//2
if (v1.x > 50 && v1.x < 100){
println('2');
myPort.write('2'); }
//3
if (v1.x > 100 && v1.x < 150 ){
println('3');
myPort.write('3'); }
//4
if (v1.x > 150 && v1.x < 200 ){
println('4');
myPort.write('4'); }
//5
if (v1.x > 200 && v1.x < 250 ){
println('5');
myPort.write('5'); }
//6
if (v1.x > 250 && v1.x < 300 ){
println('6');
myPort.write('6'); }
}
Now the problem is running this sketch being connected to pc works. Processing sends to Arduino.
But using a HC05 Bluetooth module the code's don't run anymore.
(it is connected to my computer, and port on the Arduino is also fine)
I can run the processing sketch fine. Respectivly I can also run the Arduino sketch fine. But they don't work together. It says the device is busy.
Anyone have any tips? What am I doing wrong here?