ws2812-achterbahn/achterbahnconfig/backup_achterbahnconfig.pde

84 lines
1.7 KiB
Plaintext
Raw Normal View History

2018-05-06 16:14:11 +00:00
import controlP5.*;
import processing.serial.*;
ControlP5 cp5;
Serial myPort; // Create object from Serial class
int val; // Data received from the serial port
float links;
float rechts;
float both;
Slider slLinks;
Slider slRechts;
Slider slBoth;
void setup() {
size(450, 300);
frameRate(100);
background(0);
cp5 = new ControlP5(this);
/*
slLinks = cp5.addSlider("links")
.setRange((float)-1, (float)1)
.setValue(0)
.setPosition(10,10)
.setSize(400,20)
;
slRechts = cp5.addSlider("rechts")
.setRange((float)-1,(float)1)
.setValue(0)
.setPosition(10,40)
.setSize(400,20);
*/
slBoth = cp5.addSlider("both")
.setRange((float)-1,(float)1)
.setValue(0)
.setPosition(10,20)
.setSize(400,20);
cp5.addButton("stop")
.setPosition(10, 80)
.setSize(150, 150);
myPort = new Serial(this, "/dev/ttyUSB0", 115200);
}
void stop() {
/*slLinks.setValue(0);
slRechts.setValue(0);*/
slBoth.setValue(0);
}
void draw() {
//int bits = Float.floatToIntBits(rechts);
int bits = Float.floatToIntBits(both);
byte[] bytes = new byte[8];
bytes[0] = (byte)(bits & 0xff);
bytes[1] = (byte)((bits >> 8) & 0xff);
bytes[2] = (byte)((bits >> 16) & 0xff);
bytes[3] = (byte)((bits >> 24) & 0xff);
//bits = Float.floatToIntBits(links);
bits = Float.floatToIntBits(both);
bytes[4] = (byte)(bits & 0xff);
bytes[5] = (byte)((bits >> 8) & 0xff);
bytes[6] = (byte)((bits >> 16) & 0xff);
bytes[7] = (byte)((bits >> 24) & 0xff);
myPort.write(bytes); // send an H to indicate mouse is over square
String inBuffer = myPort.readString();
if (inBuffer != null) {
println(inBuffer);
}
}