Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Light Dependent Resistor to control screen status #168

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added PrinterMonitor_LDR.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 4 additions & 1 deletion printermonitor/Settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,17 @@ boolean DISPLAYCLOCK = true; // true = Show Clock when not printing / false =
// Display Settings
const int I2C_DISPLAY_ADDRESS = 0x3c; // I2C Address of your Display (usually 0x3c or 0x3d)
const int SDA_PIN = D2;
const int SCL_PIN = D5; // original code D5 -- Monitor Easy Board use D1
const int SCL_PIN = D3; // original code D5 -- Monitor Easy Board use D1
boolean INVERT_DISPLAY = false; // true = pins at top | false = pins at the bottom
//#define DISPLAY_SH1106 // Uncomment this line to use the SH1106 display -- SSD1306 is used by default and is most common

// LED Settings
const int externalLight = LED_BUILTIN; // LED will always flash on bootup or Wifi Errors
boolean USE_FLASH = true; // true = System LED will Flash on Service Calls; false = disabled LED flashing

//Light Dependant Resistor (LDR) Port
const int ldrPin = A0;

// PSU Control
boolean HAS_PSU = false; // Set to true if https://github.com/kantlivelong/OctoPrint-PSUControl/ in use

Expand Down
19 changes: 18 additions & 1 deletion printermonitor/printermonitor.ino
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ String lastSecond = "xx";
String lastReportStatus = "";
boolean displayOn = true;

//LDR Status
int ldrStatus =0;

// Printer Client
#if defined(USE_REPETIER_CLIENT)
RepetierClient printerClient(PrinterApiKey, PrinterServer, PrinterPort, PrinterAuthUser, PrinterAuthPass, HAS_PSU);
Expand Down Expand Up @@ -394,7 +397,7 @@ void loop() {
}

checkDisplay(); // Check to see if the printer is on or offline and change display.

lightOn(); //Check if the lights are on
ui.update();

if (WEBSERVER_ENABLED) {
Expand All @@ -405,6 +408,20 @@ void loop() {
}
}

void lightOn() { //Check LDR status
ldrStatus = analogRead(ldrPin);
if(ldrStatus>=250){ //Change this value to change the sensitivity of the LDR
Serial.print("LDR value will turn on screen");
DISPLAYCLOCK = true;
//enableDisplay(true);
}
else{
Serial.print("LDR will NOT turn on screen");
DISPLAYCLOCK = false;
// enableDisplay(false);
}
}

void getUpdateTime() {
ledOnOff(true); // turn on the LED
Serial.println();
Expand Down