Created
December 1, 2016 08:33
-
-
Save sidwarkd/b994c7585fd8fc72afe3864613a6015d to your computer and use it in GitHub Desktop.
Arduino Sketch for Fridgeye App on Nextion Display
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Include the Nextion Arduino library | |
#include "Nextion.h" | |
long lastUpdate; | |
int SENSOR = A0; // Alias A0 as SENSOR | |
// t0 element from the Nextion GUI Editor was on | |
// page 0 with an id of 2. | |
NexText t0 = NexText(0, 2, "t0"); | |
// Function to read the value of the photoresistor | |
// and map the value from 0-1024 to the range 0-100 | |
// and display it on the screen in the t0 element | |
void checkSensor() | |
{ | |
int val = map(analogRead(SENSOR), 0, 1024, 0, 100); | |
String displayText = String(val) + "%"; | |
t0.setText(displayText.c_str()); | |
} | |
void setup(void) | |
{ | |
lastUpdate = millis(); | |
pinMode(SENSOR, INPUT); | |
nexInit(); | |
} | |
void loop(void) | |
{ | |
nexLoop(NULL); // Service the Nextion display | |
// Check the light level every 100ms | |
if (millis() - lastUpdate > 100) | |
{ | |
checkSensor(); | |
lastUpdate = millis(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment