Im trying to split a String from a accelerometer and gyro which I get in by the serial port
The problem I have is that I can't split it in a good way so I can use it !
The Original String looks like this when I get it in to processing
Ax: -2408
Ay: 9108
Az: 13028
Gx: 554
Gy: -127
Gz: -445
this is the code in processing
- import processing.serial.*;
- Serial myPort; // Create object from Serial class
- String band;
- void setup()
- {
- size(100, 100);
- myPort = new Serial(this, "/dev/cu.usbmodem641", 115200);
- }
- void draw() {
- if(myPort.available() > 0) {
- band = myPort.readString();
- band = band.replace("\n", "\t");
- String[] arrband = band.split("\t");
- println(arrband);
- }
- }
this what I get when it´s printed out
- [8] ""
- [9] "Ax: -2408"
- [10] "Ay: 9268"
- [11] "Az: 13144"
- [12] "Gx: 570"
- [13] "Gy: -66"
- [14] "Gz: -453
- "
- [15] ""
- [16] "Ax: -2368"
- [17] "Ay: 9160"
- [18] "Az: 13108"
- [19] "Gx: 553"
- [20] "Gy: -80"
- [21] "Gz: -432
- "
- [22] ""
- [23] "Ax: -2424"
- [24] "Ay: 9176"
- [25] "Az: 13084"
- [26] "Gx: 577"
- [27] "Gy: -84"
- [28] "Gz: -426
- "
- [29] ""
- [30] "Ax: -2420"
- [31] "Ay: 9168"
- [32] "Az: 12976"
- [33] "Gx: 578"
- [0] ""
- [1] "Gy: -99"
- [2] "Gz: -442
- "
- [3] ""
- [4] "Ax: -2328"
- [5] "Ay: 9260"
- [6] "Az: 12976"
- [7] "Gx: 552"
- [8] "Gy: -60"
- [9] "Gz: -437
- "
- [10] ""
- [11] "Ax: -2368"
- [12] "Ay: 9168"
- [13] "Az: 13028"
- [14] "Gx: 580"
- [15] "Gy: -92"
- [16] "Gz: -426
- "
- [17] ""
- [18] "Ax: -2392"
- [19] "Ay: 9304"
- [20] "Az: 13196"
Is there a better way to do this ?
1