Help recording only when toggle switch changes from high to low

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);
    }
  }}

Double posted here: http://forum.arduino.cc/index.php?topic=488993.msg3336719#msg3336719

You could have just edited your post and fixed it.

In addition to the smaller issue I posted about on your other thread you have a logic problem here.

TogglelastDebounceTime = millis();
     if (millis() - TogglelastDebounceTime) == debounceDelay)

So any time it gets to that millis check the TogglelastDebounceTime was just set equal to millis on the previous line of code. What do you think are the chances that 50ms will pass between those two lines of code running? I don't think you want the part checking the debounce time inside the same if that detects the high state and starts the debounce time.

Also you should never use a test for equality with millis() to detect a calculated time because it can increment by two rather than one occasionally. Thus you can miss a match.