Read the i2c and blink (without delay)

I’m not sure what I’m doing wrong here…I’m reading the i2c line and waiting for a number to appear. When it does I want to blink pin 13 a few times. Instead of blinking, I get a toggle - sending a number down the i2c line turns the light on and it stays on. Send another number and the light turns off and stays off.

I googled around and know that you can’t use the delay function, but shouldn’t something like the code below work? I’ve tried setting a flag and moving the blinking into it’s own function but that didn’t do the trick either.

Here is the code.

//
// Credit to http://blog.oscarliang.net/raspberry-pi-arduino-connected-i2c/
//
#include <Wire.h>
 
#define SLAVE_ADDRESS 0x04

int number = 0;
int state = 0;
int blinkflag = 0;
long previousMillis = 0;
long interval = 1000;
int ledState = LOW;

void setup() {
    pinMode(13, OUTPUT);
    Serial.begin(9600);            // start serial for output
    Wire.begin(SLAVE_ADDRESS);     // initialize i2c as slave
    Wire.onReceive(receiveData);   // define callbacks for i2c communication
    //Wire.onRequest(sendData);
    Serial.println("Ready!");
}
 
void loop() {
    delay(100);
}
 
// callback for received data
void receiveData(int byteCount){ 
        number = Wire.read();
        Serial.print("data received: ");
        Serial.println(number);
        unsigned long currentMillis = millis();
        if((currentMillis - previousMillis) > interval) {
            // Serial.println(millis());
            Serial.println(currentMillis-previousMillis);  
             // Serial.println(interval); 
             previousMillis = currentMillis;
             if (ledState == LOW)
              ledState = HIGH;
             else
              ledState = LOW; 
             digitalWrite(13, ledState);
           // blinkflag = 1;
           // blinkster();
           }
}

After completing setup and sending out Ready!, I'm surprised it does anything once the delays start here:

void loop() { delay(100); }

You actually see this happening? Serial.print("data received: "); Serial.println(number);

This part certainly would make the output LED toggle: if (ledState == LOW){ ledState = HIGH; else ledState = LOW; digitalWrite(13, ledState); }

:~ Oh geez I'm not in a loop, no wonder its not working. Will fix this tonight.