How do you plan to solve it?
#include <SPI.h>
#define SS_PIN 10
#define BUTTON_PIN 2
bool ledState = false;
const uint8_t DEBOUNCE_DELAY = 50;
unsigned long lastDebounceTime = 0;
uint8_t lastStableState = HIGH;
uint8_t currentState = HIGH;
void setup() {
pinMode(SS_PIN, OUTPUT);
pinMode(BUTTON_PIN, INPUT_PULLUP);
SPI.begin();
digitalWrite(SS_PIN, HIGH);
}
void loop() {
if (debouncedPress()) {
ledState = !ledState;
digitalWrite(SS_PIN, LOW);
SPI.transfer(ledState ? 0x01 : 0x00);
digitalWrite(SS_PIN, HIGH);
}
}
bool debouncedPress() {
uint8_t reading = digitalRead(BUTTON_PIN);
if (reading != lastStableState) {
lastDebounceTime = millis();
lastStableState = reading;
}
if ((millis() - lastDebounceTime) > DEBOUNCE_DELAY && reading != currentState) {
currentState = reading;
return (currentState == LOW);
}
return false;
}
Add a video of the output (know more)
Add a photo of your hardware showing the output.