const unsigned long frequency = 250; // Interval in milliseconds
unsigned long previousMillis = 0; // Store the last time a bit was output
uint8_t byteValue = 0b10001010; // Example byte value
int currentBitIndex = 0; // Index of the current bit being processed
int x;
void setup() {
Serial.begin(9600);
}
void loop() {
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= frequency) {
previousMillis = currentMillis;
// Extract and print the current bit
int bitValue = (byteValue >> (7 - currentBitIndex)) & 0x01;
x = bitValue;
// Move to the next bit
currentBitIndex++;
// If all bits are processed, reset the index
if (currentBitIndex >= 8) {
currentBitIndex = 0;
// Here you can reset or change the byteValue if needed
// byteValue = 0b01010101; // Example of changing the byte value
}
}
Serial.println(x);
// Other non-blocking code can go here
}