Help recording only when toggle switch changes from high to low

Hi,

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

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

You should use greater than instead of equals here. If the code just happens to run such that it's over by 1ms when it gets to this line then you're stuck forever. Or at least for 49 days until millis rolls over.

Please read the forum stickies and learn how to post code properly. Right now you're breaking the rules. You know, the difference between good programmers and those who simply will never be able to cut it is most often the tendency to read the directions first.

Double posted now over on Programming Questions.