Hi. I'm going on a trip soon and I was planning on using my laptop to virtually connect to my desktop to do work some work while I'm away since my desktop has much better specs. Just in case the desktop turns off, I made an actuator that would press the power button on my pc. I made this little actuator using a servo that moves a certain amount of degrees if a button is pressed using code generated by ChatGPT since I'm not that good at code yet. I tested the code out with a physical button and an ESP8266 V1.0 and it worked great. However, I planned on using this device through the cloud, and that's why I chose Arduino Iot Cloud to control this device. My only problem is that I thought that the Iot cloud simply took in regular IDE code, however this is not the case. Is there anyone out that can help me adjust the IDE code so that it works with IoT cloud??? Thank's in advance!!
This is my schematic that I was using (keep in mind this is with the physical button)
This is my original, IDE Code made by ChatGPT.
#include <Servo.h>
// Pin assignments
const int servoPin = 13; // Servo signal pin
const int buttonPin = 4; // Button pin
// Servo parameters
const int initialPosition = 100; // Initial position of the servo
const int targetPosition = 85; // Target position (35 degrees from initial position)
// Time parameters
const unsigned long delayTime = 4000; // Delay time in milliseconds
Servo myServo;
bool buttonState = false;
bool servoActivated = false;
unsigned long startTime = 0;
void setup() {
// Initialize the servo and button
myServo.attach(servoPin, 500, 2500); // Servo control pin and pulse width limits
pinMode(buttonPin, INPUT_PULLUP);
// Set initial servo position
myServo.write(initialPosition);
}
void loop() {
// Read button state
buttonState = digitalRead(buttonPin);
// Check if the button is pressed and the servo is not activated
if (buttonState == LOW && !servoActivated) {
servoActivated = true; // Set servo activation flag
myServo.write(targetPosition); // Move servo to the target position
startTime = millis(); // Record the start time
}
// Check if the servo is activated and the delay time has passed
if (servoActivated && (millis() - startTime >= delayTime)) {
myServo.write(initialPosition); // Move servo back to the initial position
servoActivated = false; // Reset servo activation flag
}
}