they both communicate using I2C .. my sensor is taking reading but oled is not working within loop () pls help ...
#include <Wire.h>
#include <U8x8lib.h>
#include <Adafruit_AS7341.h>
Adafruit_AS7341 as7341;
// Define the OLED display
U8X8_SSD1306_128X64_NONAME_SW_I2C u8x8(/* clock=/ A5, / data=/ A4, / reset=*/ U8X8_PIN_NONE);
void setup() {
Serial.begin(9600);
// Initialize the OLED display
u8x8.begin();
u8x8.setFont(u8x8_font_chroma48medium8_r);
u8x8.print("F1 ");
if (!as7341.begin()){
Serial.println("Could not find AS7341");
while (1) { delay(10); }
}
as7341.setATIME(100);
as7341.setASTEP(999);
as7341.setGain(AS7341_GAIN_256X);
}
void loop() {
uint16_t readings[12];
float counts[12];
if (!as7341.readAllChannels(readings)){
Serial.println("Error reading all channels!");
return;
}
for(uint8_t i = 0; i < 12; i++) {
if(i == 4 || i == 5) continue;
counts[i] = as7341.toBasicCounts(readings[i]);
}
// Print to Serial Monitor
Serial.print("F1 415nm : ");
Serial.println(counts[0]);
u8x8.clear();
u8x8.setCursor(0, 0);
u8x8.print("F1 415nm: ");
u8x8.print(counts[0]);
Serial.print("F2 515nm : ");
Serial.println(counts[1]);
u8x8.setCursor(0, 2);
u8x8.print("F2 515nm: ");
u8x8.print(counts[1]);
Serial.println();
// Display on OLED
delay(500);
}