Processing+Arduino(Bluetooth)
- Войдите на сайт для отправки комментариев
Вс, 12/11/2017 - 22:39
Ребятки, прошу помощи, возникла проблема, что крашится Java при запуске приложения.
В наличии:
Processing
Arduino IDE
Arduino Uno
windows 10
AMD 6470
Код ниже:
import processing.serial.*;
Serial btPort;
String btVal="hum35";
int temp1 = 15;
int temp2 = 40;
boolean valW = true;
boolean valD = true;
boolean valG = true;
int R1 = 104;
int G1 = 99;
int B1 = 99;
int R2 = 26;
int G2 = 24;
int B2 = 24;
int R3 = 40;
int G3 = 50;
int B3 = 50;
int R4 = 17;
int G4 = 34;
int B4 = 110;
int R5 = 105;
int G5 = 2;
int B5 = 2;
int Xmouse;
int X1mouse;
int tr1;
int tr2=325;
int tr3;
int tr4=350;
int tr5;
int tr6=350;
int tl1;
int tl2=400;
int tl3;
int tl4=425;
int tl5;
int tl6=425;
int indLed;
int tempVal;
int humVal;
int valHC;
void setup() {
size(1600,900);
String portName = Serial.list()[11];//*****************************************************************
btPort = new Serial(this, portName, 9600);
}
void draw() {
background(R3,G3,B3);
textSize(60);
fill(R1,G1,B1);
text('%',315,210);
textSize(60);
text('C', 315,270);
strokeWeight(2);
stroke(R1,G1,B1);
fill(R3,G3,B3);
ellipse(310,230,15,15);
stroke(R1,G1,B1);
strokeWeight(5);
line(100,100,100,800);
line(100,100,1200,100);
line(1200,100,1200,800);
line(100,800,1200,800);
line(450,100,450,450);
line(100,450,450,450);
line(200,800,200,550);
line(200,550,350,550);
line(350,550,350,800);
line(800,150,1100,150);
line(1100,150,1100,350);
line(800,150,800,350);
line(800,350,1100,350);
line(650,800,650,550);
line(650,550,1100,550);
line(1100,550,1100,800);
strokeWeight(3);
line(150,400,400,400);
line(150,325,400,325);
fill(R1,G1,B1);
ellipse(150,400,5,5);
ellipse(233,400,5,5);
ellipse(316,400,5,5);
ellipse(400,400,5,5);
ellipse(150,325,2,2);
ellipse(160,325,2,2);
ellipse(170,325,2,2);
ellipse(180,325,2,2);
ellipse(190,325,2,2);
ellipse(200,325,2,2);
ellipse(210,325,2,2);
ellipse(220,325,2,2);
ellipse(230,325,2,2);
ellipse(240,325,2,2);
ellipse(250,325,2,2);
ellipse(260,325,2,2);
ellipse(270,325,2,2);
ellipse(280,325,2,2);
ellipse(290,325,2,2);
ellipse(300,325,2,2);
ellipse(310,325,2,2);
ellipse(320,325,2,2);
ellipse(330,325,2,2);
ellipse(340,325,2,2);
ellipse(350,325,2,2);
ellipse(360,325,2,2);
ellipse(370,325,2,2);
ellipse(380,325,2,2);
ellipse(390,325,2,2);
ellipse(400,325,2,2);
textSize(20);
text(temp1,135,320);
text(temp2,390,320);
textSize(60);
text('-',105,343);
textSize(50);
text('+',410,340);
textSize(40);
text("push",905,300);
text("to close",875,340);
text("push",827,750);
text("to close",800,790);
text("push",229,710);
text("to",257,750);
text("close",225,790);
if(valHC==1){
stroke(R5,G5,B5);
fill(R5,G5,B5);
strokeWeight(7);
line(155,125,155,175);
ellipse(155,175,12,12);
strokeWeight(3);
line(145,132,165,132);
line(150,142,160,142);
line(145,152,165,152);
line(150,162,160,162);
}
if(valHC==2){
stroke(R4,G4,B4);
fill(R4,G4,B4);
strokeWeight(7);
line(155,125,155,175);
ellipse(155,175,12,12);
strokeWeight(3);
line(145,132,165,132);
line(150,142,160,142);
line(145,152,165,152);
line(150,162,160,162);
}
if (valD == true){
stroke(R1,G1,B1);
fill(R1,G1,B1);
rect(200,550,150,250);
stroke(R2,G2,B2);
strokeWeight(5);
line(200,800,200,550);
line(200,550,350,550);
line(350,550,350,800);
textSize(40);
fill(R3,G3,B3);
text("push",229,710);
text("to",257,750);
text("open",227,790);
}
//**********animation window
if (valW == true){
stroke(R1,G1,B1);
fill(R1,G1,B1);
rect(800,150,300,200);
stroke(R2,G2,B2);
strokeWeight(5);
line(800,150,1100,150);
line(1100,150,1100,350);
line(800,150,800,350);
line(800,350,1100,350);
textSize(40);
fill(R3,G3,B3);
text("push",905,300);
text("to open",877,340);
}
//**********animation garage
if (valG == true){
stroke(R1,G1,B1);
fill(R1,G1,B1);
rect(650,550,450,250);
stroke(R2,G2,B2);
strokeWeight(5);
line(650,800,650,550);
line(650,550,1100,550);
line(1100,550,1100,800);
textSize(40);
fill(R3,G3,B3);
text("push",827,750);
text("to open",802,790);
}
//**********animation regulator temperature
if (mouseX >= 145 && mouseX <=405 && mouseY >=300 && mouseY <=350){
if (mousePressed){
Xmouse = mouseX;
//Ymouse = mouseY;
stroke(R2,G2,B2);
fill(R2,G2,B2);
strokeWeight(0);
if(Xmouse>=145 && Xmouse<155){
tr1 = 150;
tr3 = 140;
tr5 = 160;
}
if(Xmouse>=155 && Xmouse<165){
tr1 = 160;
tr3 = 150;
tr5 = 170;
}
if(Xmouse>=165 && Xmouse<175){
tr1 = 170;
tr3 = 160;
tr5 = 180;
}
if(Xmouse>=175 && Xmouse<185){
tr1 = 180;
tr3 = 170;
tr5 = 190;
}
if(Xmouse>=185 && Xmouse<195){
tr1 = 190;
tr3 = 180;
tr5 = 200;
}
if(Xmouse>=195 && Xmouse<205){
tr1 = 200;
tr3 = 190;
tr5 = 210;
}
if(Xmouse>=205 && Xmouse<215){
tr1 = 210;
tr3 = 200;
tr5 = 220;
}
if(Xmouse>=215 && Xmouse<225){
tr1 = 220;
tr3 = 210;
tr5 = 230;
}
if(Xmouse>=225 && Xmouse<235){
tr1 = 230;
tr3 = 220;
tr5 = 240;
}
if(Xmouse>=235 && Xmouse<245){
tr1 = 240;
tr3 = 230;
tr5 = 250;
}
if(Xmouse>=245 && Xmouse<255){
tr1 = 250;
tr3 = 240;
tr5 = 260;
}
if(Xmouse>=255 && Xmouse<265){
tr1 = 260;
tr3 = 250;
tr5 = 270;
}
if(Xmouse>=265 && Xmouse<275){
tr1 = 270;
tr3 = 260;
tr5 = 280;
}
if(Xmouse>=275 && Xmouse<285){
tr1 = 280;
tr3 = 270;
tr5 = 290;
}
if(Xmouse>=285 && Xmouse<295){
tr1 = 290;
tr3 = 280;
tr5 = 300;
}
if(Xmouse>=295 && Xmouse<305){
tr1 = 300;
tr3 = 290;
tr5 = 310;
}
if(Xmouse>=305 && Xmouse<315){
tr1 = 310;
tr3 = 300;
tr5 = 320;
}
if(Xmouse>=315 && Xmouse<325){
tr1 = 320;
tr3 = 310;
tr5 = 330;
}
if(Xmouse>=325 && Xmouse<335){
tr1 = 330;
tr3 = 320;
tr5 = 340;
}
if(Xmouse>=335 && Xmouse<345){
tr1 = 340;
tr3 = 330;
tr5 = 350;
}
if(Xmouse>=345 && Xmouse<355){
tr1 = 350;
tr3 = 340;
tr5 = 360;
}
if(Xmouse>=355 && Xmouse<365){
tr1 = 360;
tr3 = 350;
tr5 = 370;
}
if(Xmouse>=365 && Xmouse<375){
tr1 = 370;
tr3 = 360;
tr5 = 380;
}
if(Xmouse>=375 && Xmouse<385){
tr1 = 380;
tr3 = 370;
tr5 = 390;
}
if(Xmouse>=385 && Xmouse<395){
tr1 = 390;
tr3 = 380;
tr5 = 400;
}
if(Xmouse>=395 && Xmouse<405){
tr1 = 400;
tr3 = 390;
tr5 = 410;
}
}
}
//**********animation regulator Led
if (mouseX >= 145 && mouseX <=405 && mouseY >=375 && mouseY <=425){
if (mousePressed){
X1mouse = mouseX;
stroke(R2,G2,B2);
fill(R2,G2,B2);
strokeWeight(0);
if(X1mouse>=145 && X1mouse<192){
tl1 = 150;
tl3 = 140;
tl5 = 160;
indLed = 0;
}
if(X1mouse>=192 && X1mouse<275){
tl1 = 233;
tl3 = 223;
tl5 = 243;
indLed = 1;
}
if(X1mouse>=275 && X1mouse<358){
tl1 = 316;
tl3 = 306;
tl5 = 326;
indLed = 2;
}
if(X1mouse>=358 && X1mouse<405){
tl1 = 400;
tl3 = 390;
tl5 = 410;
indLed = 3;
}
}
}
stroke(R2,G2,B2);
fill(R2,G2,B2);
strokeWeight(0);
triangle(tl1,tl2,tl3,tl4,tl5,tl6);
switch (tr1){
case 150:
fill(R1,G1,B1);
textSize(60);
//text(15,210,300);
break;
case 160:
fill(R1,G1,B1);
textSize(60);
//text(16,210,300);
break;
case 170:
fill(R1,G1,B1);
textSize(25);
text(17,260,315);
break;
case 180:
fill(R1,G1,B1);
textSize(25);
text(18,260,315);
break;
case 190:
fill(R1,G1,B1);
textSize(25);
text(19,260,315);
break;
case 200:
fill(R1,G1,B1);
textSize(25);
text(20,260,315);
break;
case 210:
fill(R1,G1,B1);
textSize(25);
text(21,260,315);
break;
case 220:
fill(R1,G1,B1);
textSize(25);
text(22,260,315);
break;
case 230:
fill(R1,G1,B1);
textSize(25);
text(23,260,315);
break;
case 240:
fill(R1,G1,B1);
textSize(25);
text(24,260,315);
break;
case 250:
fill(R1,G1,B1);
textSize(25);
text(25,260,315);
break;
case 260:
fill(R1,G1,B1);
textSize(25);
text(26,260,315);
break;
case 270:
fill(R1,G1,B1);
textSize(25);
text(27,260,315);
break;
case 280:
fill(R1,G1,B1);
textSize(25);
text(28,260,315);
break;
case 290:
fill(R1,G1,B1);
textSize(25);
text(29,260,315);
break;
case 300:
fill(R1,G1,B1);
textSize(25);
text(30,260,315);
break;
case 310:
fill(R1,G1,B1);
textSize(25);
text(31,260,315);
break;
case 320:
fill(R1,G1,B1);
textSize(25);
text(32,260,315);
break;
case 330:
fill(R1,G1,B1);
textSize(25);
text(33,260,315);
break;
case 340:
fill(R1,G1,B1);
textSize(25);
text(34,260,315);
break;
case 350:
fill(R1,G1,B1);
textSize(25);
text(35,260,315);
break;
case 360:
fill(R1,G1,B1);
textSize(25);
text(36,260,315);
break;
case 370:
fill(R1,G1,B1);
textSize(25);
text(37,260,315);
break;
case 380:
fill(R1,G1,B1);
textSize(25);
text(38,260,315);
break;
case 390:
fill(R1,G1,B1);
textSize(60);
//text(39,210,300);
break;
case 400:
fill(R1,G1,B1);
textSize(60);
//text(40,210,300);
break;
}
switch(indLed){
case 0:
stroke(R1,G1,B1);
strokeWeight(2);
fill(R3,G3,B3);
ellipse(275,370,50,50);
btPort.write('0');
break;
case 1:
noStroke();
fill(R1,G1,B1);
arc(275, 370, 50, 50, PI+HALF_PI, TWO_PI+PI/6, PIE);
btPort.write('1');
break;
case 2:
noStroke();
fill(R1,G1,B1);
arc(275, 370, 50, 50, PI+HALF_PI, TWO_PI+PI-PI/6, PIE);
btPort.write('2');
break;
case 3:
noStroke();
fill(R1,G1,B1);
ellipse(275,370,50,50);
btPort.write('3');
break;
}
stroke(R2,G2,B2);
fill(R2,G2,B2);
strokeWeight(0);
triangle(tr1,tr2,tr3,tr4,tr5,tr6);
//*************************************************************************************************************
//if ( btPort.available() > 0) { // If data is available,
// btVal = btPort.readString(); // read it and store it in val
//}
switch(btVal){
case "tem15":
tempVal = 15;
break;
case "tem16":
tempVal = 16;
break;
case "tem17":
tempVal = 17;
break;
case "tem18":
tempVal = 18;
break;
case "tem19":
tempVal = 19;
break;
case "tem20":
tempVal = 20;
break;
case "tem21":
tempVal = 21;
break;
case "tem22":
tempVal = 22;
break;
case "tem23":
tempVal = 23;
break;
case "tem24":
tempVal = 24;
break;
case "tem25":
tempVal = 25;
break;
case "tem26":
tempVal = 26;
break;
case "tem27":
tempVal = 27;
break;
case "tem28":
tempVal = 28;
break;
case "tem29":
tempVal = 29;
break;
case "tem30":
tempVal = 30;
break;
case "tem31":
tempVal = 31;
break;
case "tem32":
tempVal = 32;
break;
case "tem33":
tempVal = 33;
break;
case "tem34":
tempVal = 34;
break;
case "tem35":
tempVal = 35;
break;
case "tem36":
tempVal = 36;
break;
case "tem37":
tempVal = 37;
break;
case "tem38":
tempVal = 38;
break;
case "tem39":
tempVal = 39;
break;
case "tem40":
tempVal = 40;
break;
case "hum20":
humVal = 20;
break;
case "hum21":
humVal = 21;
break;
case "hum22":
humVal = 22;
break;
case "hum23":
humVal = 23;
break;
case "hum24":
humVal = 24;
break;
case "hum25":
humVal = 25;
break;
case "hum26":
humVal = 26;
break;
case "hum27":
humVal = 27;
break;
case "hum28":
humVal = 28;
break;
case "hum29":
humVal = 29;
break;
case "hum30":
humVal = 30;
break;
case "hum31":
humVal = 31;
break;
case "hum32":
humVal = 32;
break;
case "hum33":
humVal = 33;
break;
case "hum34":
humVal = 34;
break;
case "hum35":
humVal = 35;
break;
case "hum36":
humVal = 36;
break;
case "hum37":
humVal = 37;
break;
case "hum38":
humVal = 38;
break;
case "hum39":
humVal = 39;
break;
case "hum40":
humVal = 40;
break;
case "hum41":
humVal = 41;
break;
case "hum42":
humVal = 42;
break;
case "hum43":
humVal = 43;
break;
case "hum44":
humVal = 44;
break;
case "hum45":
humVal = 45;
break;
case "hum46":
humVal = 46;
break;
case "hum47":
humVal = 47;
break;
case "hum48":
humVal = 48;
break;
case "hum49":
humVal = 49;
break;
case "hum50":
humVal = 50;
break;
case "hum51":
humVal = 51;
break;
case "hum52":
humVal = 52;
break;
case "hum53":
humVal = 53;
break;
case "hum54":
humVal = 54;
break;
case "hum55":
humVal = 55;
break;
case "hum56":
humVal = 56;
break;
case "hum57":
humVal = 57;
break;
case "hum58":
humVal = 58;
break;
case "hum59":
humVal = 59;
break;
case "hum60":
humVal = 60;
break;
case "hum61":
humVal = 61;
break;
case "hum62":
humVal = 62;
break;
case "hum63":
humVal = 63;
break;
case "hum64":
humVal = 64;
break;
case "hum65":
humVal = 65;
break;
case "hum66":
humVal = 66;
break;
case "hum67":
humVal = 67;
break;
case "hum68":
humVal = 68;
break;
case "hum69":
humVal = 69;
break;
case "hum70":
humVal = 70;
break;
case "hum71":
humVal = 71;
break;
case "hum72":
humVal = 72;
break;
case "hum73":
humVal = 73;
break;
case "hum74":
humVal = 74;
break;
case "hum75":
humVal = 75;
break;
case "hum76":
humVal = 76;
break;
case "hum77":
humVal = 77;
break;
case "hum78":
humVal = 78;
break;
case "hum79":
humVal = 79;
break;
case "hum80":
humVal = 80;
break;
default:
humVal = 0;
tempVal = 0;
break;
}
fill(R1,G1,B1);
textSize(55);
text(tempVal,225,270);
fill(R1,G1,B1);
textSize(55);
text(humVal,225,210);
if ((tr1/10)<tempVal){
btPort.write('4');
btPort.write('7');
valHC = 1;
}
if ((tr1/10)>tempVal){
btPort.write('5');
btPort.write('6');
valHC = 2;
}
if ((tr1/10)==tempVal){
btPort.write('5');
btPort.write('7');
valHC = 3;
}
}
void mouseClicked() {
if (mouseX >= 200 && mouseX <= 350 && mouseY >= 550 && mouseY <= 800){
if (valD == true) {
btPort.write('q');
valD = false;
}
else {
btPort.write('w');
valD = true;
}
}
if (mouseX >= 800 && mouseX <= 1100 && mouseY >= 150 && mouseY <= 350){
if (valW == true) {
btPort.write('a');
valW = false;
}
else {
btPort.write('a');
valW = true;
}
}
if (mouseX >= 650 && mouseX <= 1100 && mouseY >= 550 && mouseY <= 800){
if (valG == true) {
btPort.write('z');
valG = false;
}
else {
btPort.write('x');
valG = true;
}
}
if (mouseX >= 100 && mouseX <= 150 && mouseY >= 300 && mouseY <= 350){
if(mousePressed==true){
tr1 =tr1+10;
mousePressed = false;
}
// }
//if(mouseX >= 100 && mouseX <= 150 && mouseY >= 300 && mouseY <= 350){
// Xmouse = Xmouse-10;
//}
//if(mouseX >= 400 && mouseX <= 450 && mouseY >= 300 && mouseY <= 350){
// Xmouse = Xmouse+10;
//}
}
//void plus(){
// if (mouseX >= 100 && mouseX <= 150 && mouseY >= 300 && mouseY <= 350){
// if(mousePressed==true){
// Xmouse = Xmouse-10;
// mousePressed = false;
// }
// }
//}
//void minus(){
// if (mouseX >= 400 && mouseX <= 450 && mouseY >= 300 && mouseY <= 350){
// if(mousePressed==true){
// Xmouse = Xmouse+10;
// mousePressed = false;
// }
// }
}
Сколько сом портов у вас в системе? в строке 50 вам точно нужен 12ый по очерёдности порт из списка?
Спасибо за ответ, думал форум умер) При подключении HC-05 пишет, что порт 10. Пробовал ставить разные. Если ставлю любой из занятых чем-либо портов - крашится Java, а если ставлю пустой порт, то все работает, но естевственно без связи с блютуз
Тогда напишите в 50той строке String portName = "COM10"; и закройте Arduino IDE и другие программы работающие с этим портом.
Если не поможет, то закомментируйте сначала код где выводится в порт и далее поблоково, пока не локализуете, где копать.
Спасибо, завтра буду пробовать, как получу хоть что-то отпишусь)