// Pin to output the square wave
// Durations of the high and low levels in milliseconds
unsigned long highDuration = 200; // 1 second
unsigned long lowDuration = 1000; // 1 second
// Variables to track the current state and timing
unsigned long previousMillis = 0;
int highState = 3;
int lowState = 0;
int currentState;
void setup() {
Serial.begin(115200); // Initialize the output pin
}
void loop() {
// Get the current time
unsigned long currentMillis = millis();
// Check if it's time to change the state
if (currentState == highState && currentMillis - previousMillis >= highDuration){
previousMillis = currentMillis;
currentState = lowState;
}
else if (currentState == -lowState && currentMillis - previousMillis >= lowDuration){
previousMillis = currentMillis;
currentState = highState;
}
Serial.println(currentState);
}