Advertisement
ZulRocky

Sistem Digital Line Follower (Processing Code)

May 3rd, 2020
420
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.39 KB | None | 0 0
  1. import processing.serial.*;
  2.  
  3. Serial myPort;  // Create object from Serial class
  4. String val;     // Data received from the serial port
  5.  
  6. int rectWidth;
  7.  
  8. void setup()
  9. {
  10.   // I know that the first port in the serial list on my mac
  11.   // is Serial.list()[0].
  12.   // On Windows machines, this generally opens COM1.
  13.   // Open whatever port is the one you're using.
  14.   printArray(Serial.list());
  15.   String portName = Serial.list()[1]; //change the 0 to a 1 or 2 etc. to match your port
  16.   myPort = new Serial(this, "COM10", 9600);
  17.   myPort.bufferUntil('\n');
  18. //  myPort = new Serial(this, portName, 9600);
  19.   size(300,300);
  20.   noStroke();
  21.   background(150);
  22.   rectWidth = width/4;
  23.  
  24. }
  25.  
  26. void serialEvent (Serial myPort){ // Checks for available data in the Serial Port
  27.   val = myPort.readStringUntil('\n'); //Reads the data sent from the Arduino (the String "LED: OFF/ON) and it puts into the "ledStatus" variable
  28. }
  29.  
  30. void draw(){
  31.   textSize(32);
  32. }
  33.  
  34. void keyPressed(){
  35.   if (key == '8'){ myPort.write('8'); background(150); text("Maju",width/2, 135);}
  36.     if (key == '5'){ myPort.write('5'); background(200); text("Berhenti",width/2, 135);}
  37.     if (key == '6'){ myPort.write('6'); background(230); text("Speed+",width/2, 135);}
  38.     if (key == '4'){ myPort.write('4'); background(100); text("Speed-",width/2, 135);}
  39.     if (key == '2'){ myPort.write('2'); background(80); text("Mundur",width/2, 135);}
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement