hello,
I don't have arduino or BT but without these, the code below
seems to work.
Remarks:
- it would be easier for us if you use English in the Code (var names, func names, comments)
- use ctrl-t to format your code (indent), better to read
- insetad of text("X =", 15, 280); text(x, 55, 280); you can write: text("X =" + x, 15, 280);
I also commented out these lines:
- BTser.write(PMbyte);
- delay(20);
- BTser.write(LMbyte);
- delay(20);
It's never wise to use
delay. Maybe you can work without it. Or if you need a pause, work with millis (see
here).
Greetings, Chrisir

- PFont pismo;
- // import knihoven
- // import processing.serial.*;
- // deklarace promennych - vypocty
- float x;
- float otaceni;
- float y;
- float plyn;
- // deklarace promennych - motory
- float LM;
- float PM;
- int LMbyte;
- int PMbyte;
- // deklarace promennych - posuvniky
- int Lposuvnik;
- int Pposuvnik;
- //Serial BTser;
- ////////////////////////////////////////////////////
- void setup()
- {
- size(400, 440);
- // background(102);
- // nacteni pisma
- pismo = createFont("Font.vlw", 14);
- textFont(pismo, 20);
- // background(102);
- // inicializace serioveho portu
- //BTser = new Serial(this, "COM19", 9600);
- }
- ////////////////////////////////////////////////////
- void souradnice_vypocet()
- {
- background(102);
- //prepocet souradnic
- x = mouseX-120;
- y = -mouseY+145;
- plyn = y/100;
- otaceni = x/100;
- }
- void souradnice_zobrazeni()
- {
- background(102);
- //Vypis souradnic
- text("X =", 15, 280);
- text(x, 55, 280);
- text("Y =", 15, 300);
- text(y, 65, 300);
- //Ctverec joysticku
- fill(255, 255, 255);
- text("Joystick", 80, 25);
- rectMode(CORNERS);
- rect(15, 40, 225, 250);
- line(120, 40, 120, 250);
- line(15, 145, 225, 145);
- //Kurzor
- ellipseMode(CENTER);
- fill(255, 0, 0);
- ellipse(x+120, -y+145, 10, 10);
- }
- ////////////////////////////////////////////////////
- void kvadranty()
- {
- // vypis kvadrantu + vypocet vykonu motoru
- fill(255, 255, 255);
- if (x > 0 && y > 0) // 1.kvadrant
- {
- text("1.kvadrant", 15, 325);
- LM = plyn;
- PM = plyn*(1-otaceni);
- }
- if (x < 0 && y > 0) // 2.kvadrant
- {
- text("2.kvadrant", 15, 325);
- PM = plyn;
- LM = plyn*(1+otaceni);
- }
- if (x < 0 && y < 0) // 3.kvadrant
- {
- text("3.kvadrant", 15, 325);
- PM = plyn;
- LM = plyn*(1+otaceni);
- }
- if (x > 0 && y < 0) // 4.kvadrant
- {
- text("4.kvadrant", 15, 325);
- LM = plyn;
- PM = plyn*(1-otaceni);
- }
- if (x == 0)
- {
- LM = plyn;
- PM = plyn;
- }
- }
- ////////////////////////////////////////////////////
- void indikace()
- {
- //Vypis plyn a otaceni
- text("Plyn", 15, 350);
- text(plyn, 105, 350);
- text("Otaceni", 15, 370);
- text(otaceni, 105, 370);
- //Vypis motoru
- text("L motor", 15, 395);
- text(LM, 105, 395);
- text("P motor", 15, 415);
- text(PM, 105, 415);
- // indikatory motoru
- // levy motor
- fill(255, 255, 255);
- text("LM", 265, 25);
- rectMode(CORNERS);
- rect(255, 40, 305, 250);
- fill(0);
- line(255, 145, 305, 145);
- //posuvnik levy motor
- Lposuvnik = 250 - (round(LM*100) + 105);
- fill(255, 0, 0);
- rectMode(CENTER);
- rect(280, Lposuvnik, 50, 10);
- //pravy motor
- fill(255, 255, 255);
- text("PM", 345, 25);
- rectMode(CORNERS);
- rect(335, 40, 385, 250);
- fill(0);
- line(335, 145, 385, 145);
- //posuvnik pravy motor
- Pposuvnik = 250 - (round(PM*100) + 105);
- fill(255, 0, 0);
- rectMode(CENTER);
- rect(360, Pposuvnik, 50, 10);
- }
- ////////////////////////////////////////////////////
- void prepocet_ST()
- {
- //prepocet na hodnotu 1-255
- fill(255, 255, 255);
- text("Hodnoty pro", 255, 280);
- text("Sabertooth:", 255, 300);
- // Levy motor
- if (LM < 0) {
- LMbyte = round((1+LM)*63);
- } // hodnota 1 - 63
- if (LM == 0) {
- LMbyte = 64;
- } // hodnota 64
- if (LM > 0) {
- LMbyte = round(LM*63 + 64);
- } // hodnota 65 - 127
- if (LMbyte == 0) {
- LMbyte = 1;
- } // hodnota 0 vypina oba motory
- text("L motor", 255, 325);
- text(LMbyte, 335, 325);
- // Pravy motor
- if (PM < 0) {
- PMbyte = round((1+PM)*63 + 128);
- } // hodnota 128 - 191
- if (PM == 0) {
- PMbyte = 192;
- } // hodnota 192
- if (PM > 0) {
- PMbyte = round(PM*63 + 192);
- } // hodnota 128-191
- text("P motor", 255, 345);
- text(PMbyte, 335, 345);
- }
- ////////////////////////////////////////////////////
- void odeslani()
- {
- //odeslani pres seriovy port
- /*
- BTser.write(PMbyte);
- delay(20);
- BTser.write(LMbyte);
- delay(20);
- */
- }
- void draw()
- {
- if (mousePressed && mouseX >= 20 && mouseX <= 220 && mouseY >= 45 && mouseY <= 245)
- {
- souradnice_vypocet();
- }
- souradnice_zobrazeni();
- kvadranty();
- indikace();
- prepocet_ST();
- odeslani();
- }