Skip to content

Instantly share code, notes, and snippets.

@sidwarkd
Created December 1, 2016 08:33
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sidwarkd/b994c7585fd8fc72afe3864613a6015d to your computer and use it in GitHub Desktop.
Save sidwarkd/b994c7585fd8fc72afe3864613a6015d to your computer and use it in GitHub Desktop.
Arduino Sketch for Fridgeye App on Nextion Display
// 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