Hi I am developing a light meter using a BH1750 light sensor.
My code is as follows:
#include <LCD5110_Graph.h>
#include <Wire.h>
#include <BH1750.h>
LCD5110 lcd(3,4,5,6,7);
extern unsigned char BigNumbers[];
extern uint8_t nuline[];
extern uint8_t ui[];
extern uint8_t splash[];
BH1750 lightSensor;
String light;
void setup() {
lightSensor.begin();
lcd.InitLCD();
lcd.setFont(BigNumbers);
lcd.clrScr();
lcd.drawBitmap(0, 0, nuline, 84, 48);
lcd.update();
delay(5000);
lcd.clrScr();
lcd.drawBitmap(0, 0, splash, 84, 48);
lcd.update();
delay(2000);
}
void loop() {
int stringLength=0;
uint16_t lux = lightSensor.readLightLevel()*10;
light = String(lux);
stringLength = light.length();
lcd.clrScr();
lcd.drawBitmap(0, 0, ui, 84, 48);
printLight(stringLength);
lcd.update();
delay(150);
}
void printLight(int length)
{
switch(length)
{
case 1: lcd.print(light,68,22); break;
case 2: lcd.print(light,54,22); break;
case 3: lcd.print(light,40,22); break;
case 4: lcd.print(light,26,22); break;
case 5: lcd.print(light,12,22); break;
default: lcd.print(light,0,22); break;
}
}
I would now like to add a button which when pressed will hold the reading on the sensor.
For e.g. i shine a light on the sensor and it displays 1500 lux for example. Now when i turn it off the reading goeas back to 500 or whatever the general room brightness is.
What i am looking to achieve is once i press the button while the light is being shined. the display should stay on 1500 lux even after i turn off my light.
On pressing the button again, the sensor would go back to displaying real-time brightness as usual.
Any kind of help is appreciated. I am a newbie and I've managed to come up with this code after copious amount of reading and experimenting. Unfortunately the deadline for this is looming closer and I'm stuck with this challenge.
P.S. Using an Arduino UNO and a Nokia display