Hi,
So apparently I didn't upload my code correctly last time (my apologies) so here I am posting it again..
I am trying to code my toggle switch so that it only records when it switches from high to low to avoid getting all the data of reporting constantly on or off. I am trying to set up the millis() function such that after a certain amount of time has passed (debounceDelay) the code will enter the loop that will record the change of status... however it is not working. My code is attached below, any help is welcome!
unsigned long debounceDelay = 50;
unsigned long TogglelastDebounceTime = 0;
int actualtoggleState;
const int togglePin = 8;
int toggleState;
void setup() {
pinMode(togglePin, INPUT);
Serial.begin(9600);
void loop() {
int toggleState = digitalRead(togglePin);
if (toggleState != actualtoggleState) {
actualtoggleState = toggleState;
Serial.print(actualtoggleState);
}
if (actualtoggleState == HIGH) {
TogglelastDebounceTime = millis();
if (millis() - TogglelastDebounceTime) == debounceDelay) {
Serial.print("UP");
BluetoothSerial.print("LightStatus: OFF");
BluetoothSerial.print("\r\n");
Serial.print(actualtoggleState);
}}
if (actualtoggleState == LOW){
TogglelastDebounceTime = millis();
if millis() - TogglelastDebounceTime) == debounceDelay) {
Serial.print("DOWN");
BluetoothSerial.print("LightStatus: OFF");
BluetoothSerial.print("\r\n");
Serial.print(actualtoggleState);
}
}}