SHARE
TWEET

NetBeans

a guest May 21st, 2019 62 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. int pin[7];
  2. int x= 0;
  3. unsigned long blinkRate = 1000;
  4. const int echoPin = 9;
  5. const int trigPin = 10;
  6. long duration;
  7. int distance;
  8.  
  9. void setup() {
  10.   pinMode(trigPin,OUTPUT);
  11.   pinMode(echoPin,INPUT);
  12.  
  13.   for(int i=0;i<7;i++){
  14.     pin[i]=i+2;
  15.     pinMode(pin[i], OUTPUT);
  16.   }
  17. Serial.begin(9600);
  18. Serial.println("Enter the blink delay length in milliseconds (try 100)");
  19. }
  20.  
  21. void loop() {
  22.  
  23.   digitalWrite(trigPin, LOW);
  24.   delayMicroseconds(2);
  25.   digitalWrite(trigPin, HIGH);
  26.   delayMicroseconds(10);
  27.   digitalWrite(trigPin, LOW);
  28.  
  29.   duration = pulseIn(echoPin, HIGH);
  30.   distance = duration*0.034/2;
  31.   Serial.println(distance);
  32.  
  33.   if (Serial.available() > 0){
  34.     blinkRate = Serial.parseInt();
  35.     Serial.println(blinkRate);
  36.   }
  37.   for(int i=0;i<7;i++){
  38.     if(i==x){
  39.       digitalWrite(pin[i], HIGH);
  40.     }
  41.     else{
  42.       digitalWrite(pin[i], LOW);
  43.     }
  44.   }
  45.   x++;
  46.   if(x>6)x=0;
  47.   delay(blinkRate);
  48. }
  49.  
  50.  
  51.  
  52. //NetBeans
  53.  
  54.  
  55. package aplikasi;
  56. import javax.swing.JFrame;
  57. import javax.swing.JPanel;
  58. import javax.swing.JLabel;
  59. import javax.swing.JTextField;
  60. import javax.swing.JButton;
  61. import java.awt.event.ActionEvent;
  62. import java.awt.event.ActionListener;
  63.  
  64. import net.miginfocom.swing.MigLayout;
  65. import com.fazecast.jSerialComm.*;
  66. import java.util.Scanner;
  67.  
  68. public class Aplikasi extends JFrame{
  69.     JPanel utama = new JPanel(new MigLayout());
  70.     JLabel lInput = new JLabel("Instruksi : ");
  71.     JTextField lText = new JTextField(20);
  72.     JButton kirim = new JButton("Kirim");
  73.     JLabel lHasil = new JLabel("Hasil ");
  74.  
  75. public Aplikasi(){
  76.     super("Program Kontrol Arduino");
  77.     setSize(500,400);
  78.     setResizable(true);
  79.     setDefaultCloseOperation(EXIT_ON_CLOSE);
  80.     utama.add(lInput);
  81.     utama.add(lText);
  82.     utama.add(kirim,"wrap");
  83.     utama.add(lHasil);
  84.     add(utama);
  85.     SerialPort ports[] = SerialPort.getCommPorts();
  86.     SerialPort port = ports[0];
  87.     port.openPort();
  88.         port.setComPortTimeouts(SerialPort.TIMEOUT_SCANNER, 0, 0);
  89.     ActionListener ProsesAction = new ActionListener(){
  90.            
  91. public void actionPerformed(ActionEvent e){
  92.     String nilai = lText.getText();
  93.     lHasil.setText(nilai);
  94.     port.writeBytes(nilai.getBytes(),2);            }
  95.     };
  96.     kirim.addActionListener(ProsesAction);
  97.     setVisible(true);
  98.                
  99.        
  100.         Scanner data = new Scanner(port.getInputStream());
  101.         int counter=0;
  102.        
  103.         while(data.hasNextLine()){
  104.             try{
  105.                 System.out.println(data.nextLine());
  106.             }catch(Exception e){
  107.                 System.out.println("ERROR");}
  108.             }
  109.         }
  110.     public static void main(String [] a )
  111.     {
  112.         new Aplikasi();
  113.     }
  114. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top