diff --git a/TangibleSketches/Arduino/Arduino_Sketch_copy_20240512144111/Arduino_Sketch_copy_20240512144111.ino b/TangibleSketches/Arduino/Arduino_Sketch_copy_20240512144111/Arduino_Sketch_copy_20240512144111.ino new file mode 100644 index 0000000..b488e4a --- /dev/null +++ b/TangibleSketches/Arduino/Arduino_Sketch_copy_20240512144111/Arduino_Sketch_copy_20240512144111.ino @@ -0,0 +1,44 @@ +#include <Servo.h> + +Servo myservo; +int neutralPos = 1520; // Neutral position in microseconds +String readString; // String to hold incoming data + +void setup() { + myservo.attach(7, 400, 2600); // Attach servo to pin 7 + Serial.begin(9600); // Start serial communication at 9600 baud rate + Serial.println("Servo control initialized."); + Serial.println("Awaiting commands."); + Serial.println("Type '1500x' to perform a 45-degree rotation."); +} + +void perform45DegreeTurn() { + int pulseSpeed = 1500; // Speed setting for 45-degree rotation + myservo.writeMicroseconds(pulseSpeed); + delay(2500); // Time for 45-degree turn + myservo.writeMicroseconds(neutralPos); // Stop the servo by resetting to neutral + Serial.println("45-degree turn executed and stopped."); + Serial.println("Ready"); // Send confirmation message to ESP32 +} + +void loop() { + while (Serial.available()) { + char c = Serial.read(); // Read incoming character + readString += c; // Append it to the readString + delay(2); // Allow time for next character to arrive in buffer + } + + if (readString.length() > 0) { + // Trim whitespace and control characters + readString.trim(); + + Serial.println("Received: " + readString); // Echo what was received + + if (readString == "1500x") { + perform45DegreeTurn(); // Perform the 45-degree turn + } else { + Serial.println("Invalid command. Please type '1500x' to execute a 45-degree turn."); + } + readString = ""; // Clear the string for new input + } +} diff --git a/TangibleSketches/ESP32/ESP32_sketch_copy_20240512144341/ESP32_sketch_copy_20240512144341.ino b/TangibleSketches/ESP32/ESP32_sketch_copy_20240512144341/ESP32_sketch_copy_20240512144341.ino new file mode 100644 index 0000000..bddbd2f --- /dev/null +++ b/TangibleSketches/ESP32/ESP32_sketch_copy_20240512144341/ESP32_sketch_copy_20240512144341.ino @@ -0,0 +1,20 @@ +void setup() { + Serial.begin(9600); // Start serial communication at 9600 baud rate + Serial1.begin(9600); // Start serial communication with Arduino + delay(1000); // Allow time for serial monitor to initialize + Serial.println("Ready to send commands to Arduino."); +} + +void loop() { + if (Serial.available()) { + String input = Serial.readStringUntil('\n'); // Read input from serial monitor + input.trim(); // Remove leading and trailing whitespace + + if (input == "1500x") { + Serial.println("Sending command to Arduino: " + input); + Serial1.println(input); // Send the command to Arduino via Serial1 + } else { + Serial.println("Invalid command. Please type '1500x' to send the command to Arduino."); + } + } +}