我正在建造一个八角形的LED网格。它有 8 个边,由 Kinect 上某人的 X 轴触发。
它向Arduino发送8个序列号,以触发八边形一侧的LED。这些指示灯均为 (255,0,0( 红色。
我想这样做,这样我就可以在处理过程中在蓝色、绿色和红色之间切换。有人对如何做这样的事情有任何提示吗?
我正在考虑也许创建三个按钮(R,G,B(并使用鼠标按下在发送到Arduino的序列号之间变化
唯一的问题是我对处理有点陌生。 有人知道如何解决这个问题吗?
这是我的处理代码
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(640, 480);
kinect = new Kinect(this);
tracker = new KinectTracker();
String portName = Serial.list()[2]; //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 < 80 ){
println('8');
//rect(0,200,200,200);
myPort.write('8'); }
//println('0'); }
//2
if (v1.x > 80 && v1.x < 160){
println('7');
myPort.write('7'); }
//3
if (v1.x > 160 && v1.x < 240 ){
println('6');
myPort.write('6'); }
//4
if (v1.x > 240 && v1.x < 320 ){
println('5');
myPort.write('5'); }
//5
if (v1.x > 320 && v1.x < 400 ){
println('4');
myPort.write('4'); }
//6
if (v1.x > 400 && v1.x < 480 ){
println('3');
myPort.write('3'); }
//7
if (v1.x > 480 && v1.x < 560 ){
println('2');
myPort.write('2'); }
//8
if (v1.x > 560 && v1.x < 620 ){
println('1');
myPort.write('1'); }
}
这是Arduino代码:
#include <FastLED.h>
#define LED_PIN 6
#define NUM_LEDS 360
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 < '9')
{
FastLED.clear(); // <-----<<<< USE clear
}
if (incomingByte == '1')
for(int i = 0; i<=44; i++){
leds[i] = CRGB(255, 0, 0);
}
else if (incomingByte == '2')
for(int i = 45; i<=89; i++){
leds[i] = CRGB(255, 0, 0);
}
else if (incomingByte == '3')
for(int i = 90; i<=134; i++){
leds[i] = CRGB(255, 0, 0);
}
else if (incomingByte == '4')
for(int i = 135; i<=179; i++){
leds[i] = CRGB(255, 0, 0);
}
else if (incomingByte == '5')
for(int i = 180; i<=224; i++){
leds[i] = CRGB(255,0, 0);
}
else if (incomingByte == '6')
for(int i = 225; i<=269; i++){
leds[i] = CRGB(255, 0, 0);
}
else if (incomingByte == '7')
for(int i = 270; i<=314; i++){
leds[i] = CRGB(255, 0, 0);
}
else if (incomingByte == '8')
for(int i = 315; i<=359; i++){
leds[i] = CRGB(255, 0, 0);
}
FastLED.show();
}
}
谢谢大家!
如果您需要在处理中制作 GUI 的资源,我有幸使用 ControlP5。 有很多例子,这是一种非常时尚的美学。 您应该能够使用那里的示例来更改通过串行发送的值以选择颜色。