Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import processing.serial.*;
- Serial myPort; // Create object from Serial class
- String val; // Data received from the serial port
- int rectWidth;
- void setup()
- {
- // I know that the first port in the serial list on my mac
- // is Serial.list()[0].
- // On Windows machines, this generally opens COM1.
- // Open whatever port is the one you're using.
- printArray(Serial.list());
- String portName = Serial.list()[1]; //change the 0 to a 1 or 2 etc. to match your port
- myPort = new Serial(this, "COM10", 9600);
- myPort.bufferUntil('\n');
- // myPort = new Serial(this, portName, 9600);
- size(300,300);
- noStroke();
- background(150);
- rectWidth = width/4;
- }
- void serialEvent (Serial myPort){ // Checks for available data in the Serial Port
- val = myPort.readStringUntil('\n'); //Reads the data sent from the Arduino (the String "LED: OFF/ON) and it puts into the "ledStatus" variable
- }
- void draw(){
- textSize(32);
- }
- void keyPressed(){
- if (key == '8'){ myPort.write('8'); background(150); text("Maju",width/2, 135);}
- if (key == '5'){ myPort.write('5'); background(200); text("Berhenti",width/2, 135);}
- if (key == '6'){ myPort.write('6'); background(230); text("Speed+",width/2, 135);}
- if (key == '4'){ myPort.write('4'); background(100); text("Speed-",width/2, 135);}
- if (key == '2'){ myPort.write('2'); background(80); text("Mundur",width/2, 135);}
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement