#include #include // Define the structure for receiving data typedef struct struct_message { int value; } struct_message; // Create a struct_message called myData struct_message myData; #include // How many leds in your strip? #define NUM_LEDS1 56 #define NUM_LEDS2 50 // For led chips like Neopixels, which have a data line, ground, and power, you just // need to define DATA_PIN. For led chipsets that are SPI based (four wires - data, clock, // ground, and power), like the LPD8806, define both DATA_PIN and CLOCK_PIN #define DATA_PIN1 D10 #define DATA_PIN2 D2 #define HALL_SENSOR D0 int BPM = 70; // Define the array of leds CRGB leds1[NUM_LEDS1]; CRGB leds2[NUM_LEDS2]; void setup() { Serial.begin(115200); Serial.println("resetting"); FastLED.addLeds(leds1, NUM_LEDS1); FastLED.addLeds(leds2, NUM_LEDS2); FastLED.setBrightness(84); pinMode(HALL_SENSOR, INPUT_PULLUP); WiFi.mode(WIFI_STA); // Init ESP-NOW if (esp_now_init() != ESP_OK) { Serial.println("Error initializing ESP-NOW"); return; } // Register for a callback function to receive data esp_now_register_recv_cb(OnDataRecv); } void fadeall1() { for (int i = 0; i < NUM_LEDS1; i++) { leds1[i].nscale8(230); } } void fadeall2() { for (int i = 0; i < NUM_LEDS2; i++) { leds2[i].nscale8(230); } } void loop() { // Pulse rate: 60 pulses per minute (1 pulse per second) float delayTimeR = (((60.0/BPM)*1000.0) / (NUM_LEDS1)); // Delay time in milliseconds for each LED; float delayTimeL = (((60.0/BPM)*1000.0) / (NUM_LEDS2)); // Delay time in milliseconds for each LED; Serial.println(BPM); Serial.println(BPM); // First slide the LED in one direction for blue LEDs for (int i = 0; i < NUM_LEDS1; i++) { if (digitalRead(HALL_SENSOR) && i>11) { leds1[i] = CRGB::Purple; } else{ leds1[i] = CRGB::Blue; } FastLED.show(); fadeall1(); fadeall2(); delay(delayTimeR); } //delay(500); //First slide the LED in one direction for red LEDs for (int i = 0; i < NUM_LEDS2; i++) { leds2[i] = CRGB::Red; FastLED.show(); fadeall2(); fadeall1(); delay(delayTimeL); } } void OnDataRecv(const esp_now_recv_info *info, const uint8_t *incomingData, int len) { memcpy(&myData, incomingData, sizeof(myData)); Serial.print("Bytes received: "); Serial.println(len); Serial.print("Received value: "); BPM = myData.value; Serial.println(BPM); }