Recursion Recursion Recursion

This commit is contained in:
2023-09-17 19:41:03 -05:00
parent 44053f01f6
commit c375732331
21 changed files with 4538 additions and 0 deletions

View File

@@ -0,0 +1,48 @@
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
*/
package serialpogant;
import java.io.OutputStream;
import java.io.IOException;
import gnu.io.*;
/**
*
* @author caleb
*/
public class SerialPog2 {
public static void main(String[] args) {
// Define the serial port name (e.g., COM3 for Windows, /dev/ttyUSB0 for Linux)
String serialPortName = "/dev/ttyACM0"; // Replace with your Arduino's serial port
// Define the baud rate (must match the Arduino sketch)
int baudRate = 9600;
try {
// Open the serial port
CommPortIdentifier portIdentifier = CommPortIdentifier.getPortIdentifier(serialPortName);
SerialPort serialPort = (SerialPort) portIdentifier.open("", 2000);
// Configure the serial port
serialPort.setSerialPortParams(baudRate, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
// Get the output stream from the serial port
OutputStream outputStream = serialPort.getOutputStream();
// String to send to Arduino
String messageToSend = "Hello, Arduino!";
// Convert the string to bytes and write to the serial port
byte[] messageBytes = messageToSend.getBytes();
outputStream.write(messageBytes);
// Close the serial port when done
serialPort.close();
} catch (PortInUseException | NoSuchPortException | UnsupportedCommOperationException | IOException e) {
e.printStackTrace();
}
}
}