Hello,
My name is Phil and I am a total newbie, and am seeking help from anyone.
I am hoping to build a working photographic darkroom enlarger lightmeter. I found an Arduino sketch for a meter that uses a BH1750 light sensor and a SSD1306 LCD display.
I have installed the Arduino IDE v2.3.10 and the required libraries.
Being absolutely new to Arduino I don't have any knowledge of the programming. This is where I am asking for some help.
So, I pasted the code that I found on the web into the IDE and tred to verify it. This came up with errors that I do not understand.
As a new user I am not allowed to add an attachment, so here is the code copied from the IDE:-
void loop() {
// put your main code here, to run repeatedly:
#include <Wire.h>
#include <hp_BH1750.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define OLED_RESET -1
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
hp_BH1750 lightMeter;
// Calibration variables
const int buttonPin = 2;
float referenceLux = 1.0; // Default baseline
float referenceTime = 10.0; // Your standard base exposure time (e.g., 10 seconds)
bool isCalibrated = false;
void setup() {
pinMode(buttonPin, INPUT_PULLUP);
Wire.begin();
// Initialize OLED Display
if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
for(;;); // Halt if screen fails
}
display.clearDisplay();
display.setTextColor(SSD1306_WHITE); // Use red acrylic overlay if display isn't natively red
// Initialize BH1750 Light Sensor
// One-time high res mode allows maximum sensitivity in low darkroom light
lightMeter.begin(hp_BH1750::ONE_TIME_HIGH_RES_MODE);
}
void loop() {
// Read current light value on the easel
float currentLux = lightMeter.readLightLevel();
// Check if Calibration Button is pressed (Active LOW)
if (digitalRead(buttonPin) == LOW) {
if (currentLux > 0.01) { // Prevent dividing by zero in pitch black
referenceLux = currentLux;
isCalibrated = true;
display.clearDisplay();
display.setTextSize(1);
display.setCursor(0,0);
display.print("CALIBRATED!");
display.setCursor(0,20);
display.print("Ref Lux: "); display.print(referenceLux);
display.display();
delay(1500); // Debounce and message confirmation
}
}
// Calculate new target exposure time based on the light delta
float calculatedTime = referenceTime \* (referenceLux / currentLux);
// Update Darkroom Display
display.clearDisplay();
display.setTextSize(1);
display.setCursor(0, 0);
display.print("CURRENT LUX: "); display.print(currentLux, 2);
display.setCursor(0, 20);
if (isCalibrated) {
display.setTextSize(2);
display.print("TIME: ");
display.print(calculatedTime, 1);
display.print("s");
} else {
display.print("Uncalibrated");
display.setCursor(0, 45);
display.setTextSize(1);
display.print("Press button to set baseline");
}
display.display();
// Re-trigger sensor configuration for the next reading loop
lightMeter.configure(hp_BH1750::ONE_TIME_HIGH_RES_MODE);
delay(200);
}
}
This is the error message:-
C:\Users\phill\Documents\Arduino\Shetches\sketch_lightmeter_3\sketch_lightmeter_3.ino: In function 'void loop()':
C:\Users\phill\Documents\Arduino\Shetches\sketch_lightmeter_3\sketch_lightmeter_3.ino:21:14: error: a function-definition is not allowed here before '{' token
void setup() {
^
C:\Users\phill\Documents\Arduino\Shetches\sketch_lightmeter_3\sketch_lightmeter_3.ino:37:13: error: a function-definition is not allowed here before '{' token
void loop() {
^
exit status 1
Compilation error: a function-definition is not allowed here before '{' token
Could you possibly help please?


