I have connected the data streamer from arduino to excel, and i have declared a variable "Scanned_data", the scanned data should be given through the data out column of the excel and it is working properly,the data is getting fetched but there is another variable declared "Current_Comp", the issue is that whenever the scanned_data is getting updated the Current_comp is not getting updated. Plese if anyone know a solution let me know
#include <Wire.h>
#include <Adafruit_VL6180X.h>
#include <Adafruit_NeoPixel.h>
#define TCAADDR 0x70
#define LED_PIN 4
#define PIN1 8 // Choose a digital pin for the WS2812B LED
Adafruit_VL6180X vl1 = Adafruit_VL6180X(); // VL6180X #1
Adafruit_VL6180X vl2 = Adafruit_VL6180X(); // VL6180X #2
Adafruit_VL6180X vl3 = Adafruit_VL6180X(); // VL6180X #3
Adafruit_NeoPixel strip = Adafruit_NeoPixel(8, LED_PIN, NEO_GRB + NEO_KHZ800);
int scanned_data = 0; // Declare scanned_data variable
void tcaselect(uint8_t channel)
{
if (channel > 7)
return;
Wire.beginTransmission(TCAADDR);
Wire.write(1 << channel);
Wire.endTransmission();
}
int update_comp = 90;
int no_of_comp = 5;
int current_comp = 0;
void light(int scanned_data, int current_comp, int no_of_comp)
{
uint32_t color = 0;
if (scanned_data != current_comp)
{
color = strip.Color(255, 255, 255); // White color for all LEDs
digitalWrite(PIN1, HIGH);
}
else {
digitalWrite(PIN1, LOW);
if (current_comp == 0)
{
color = strip.Color(255, 0, 0); // Red color for all LEDs
}
else if (no_of_comp == current_comp)
{
color = strip.Color(0, 255, 0); // Green color for all LEDs
}
else if (no_of_comp - current_comp >= 2)
{
color = strip.Color(0, 0, 255); // Blue color for all LEDs
}
else if (no_of_comp - current_comp < 2)
{
color = strip.Color(255, 0, 255); // yellow color for all LEDs
}
}
strip.fill(color, 0, strip.numPixels()); // Set the color for all LEDs
strip.show();
}
// Example function to read data from Excel data streamer (replace with your actual implementation)
int readExcelData() {
if (Serial.available() > 0) {
return Serial.parseInt();
}
return 0;
}
void setup()
{
Serial.begin(115200);
while (!Serial)
;
Serial.println(F("test"));
Wire.begin();
tcaselect(0);
vl1.begin();
tcaselect(1);
vl2.begin();
tcaselect(2);
vl3.begin();
pinMode(LED_PIN, OUTPUT); // Set LED_PIN as OUTPUT
pinMode(PIN1, OUTPUT); // Set PIN1 as OUTPUT
// Initialize the NeoPixel strip
strip.begin();
strip.show(); // Initialize all pixels to 'off'
}
void loop()
{
// Read scanned_data from Excel data streamer, replace 0 with the appropriate channel
scanned_data = readExcelData();
tcaselect(1);
uint8_t range1 = vl2.readRange();
uint8_t status1 = vl2.readRangeStatus();
if (status1 == VL6180X_ERROR_NONE && range1 <= 85)
{
Serial.print("No_Of_Component: ");
Serial.println(current_comp);
Serial.print("range: ");
Serial.println(range1);
if (update_comp > range1 && update_comp - range1 >= 5)
{
update_comp = range1;
current_comp++;
}
digitalWrite(LED_PIN, HIGH); // Power up digital pin 4 (LED_PIN)
digitalWrite(PIN1, HIGH); // Power up digital pin 8 (PIN1)
Serial.print("Scanned:");
Serial.println(scanned_data);
// digitalWrite(PIN1, LOW);
// Call the light function outside the if statement
light(scanned_data, current_comp, no_of_comp);
}
else {current_comp = 0;
Serial.print("No_Of_Component: ");
Serial.println(current_comp);}
delay(1000);
}