Good evenening,
Firts of all I want to say that this is my first topic on this forum, I've read the guidelines and other information but if something is not according with the rules please let me know.
I am new to programming so every kind of support is welcome
I'am making a automated system for my aquarium and a part of this system is adjusting the brightness of the lights and making it possible to dim completely. I am using 5 meanwell ldd drivers on a PCB board which require a PWM value from 0-255 each.
Ive tested the dimming with a potmeter and mapped the value from 1023 to 255 and wrote it to the PWM output pin for the driver using analogwrite and that worked!
Now I made a Nextion file with sliders to send the PWM value to the drivers but there is a problem. The lighting is not dimming its just going on at a value of around 134 with full brightness and of when the slider is below that. Ive checked the values the slider puts out and those are values from 0-255 just like I want. Its just not working...
I found a tutorial on the internet which I copied to check if it was my coding and this had the same problem.
link tutorial: https://www.instructables.com/Display-Nextion-With-Arduino-Uno/
video of me running the tutorial: from the tutorial - YouTube
Here a video of me trying my own code:
Kind regards Hugo
The code I use is the following NOTE! The slider that im taling about is h0, this is the first void you see.
<#include <Nextion.h>;
const int CoolWhite = 8; // LED drive
const int WarmWhite = 9; // LED drive
const int RoyalBlue = 10; // LED drive
const int DeepRed = 11; // LED drive
const int Moonlight = 12; // LED drive
int licht1;
NexButton b1 = NexButton(1, 13, "b1"); // Button added
NexButton b0 = NexButton(0, 3, "b0"); // Button added
NexSlider h0 = NexSlider(1, 3, "h0"); // Slider added
NexSlider h1 = NexSlider(1, 4, "h1");
NexSlider h2 = NexSlider(1, 5, "h2");
NexSlider h3 = NexSlider(1, 6, "h3");
NexSlider h4 = NexSlider(1, 7, "h4");
NexText t0 = NexText(2, 8, "t0"); // Text box added, so we can read it
NexText t1 = NexText(2, 9, "t1"); // Text box added, so we can read it
NexText t2 = NexText(2, 10, "t2"); // Text box added, so we can read it
NexText t3 = NexText(2, 11, "t3");
NexText t4 = NexText(2, 12, "t4");
NexNumber n0 = NexNumber(2, 14, "n0");
NexNumber n1 = NexNumber(2, 15, "n1");
NexNumber n2 = NexNumber(2, 16, "n2");
NexNumber n3 = NexNumber(2, 17, "n3");
NexNumber n4 = NexNumber(2, 18, "n4");
NexPage page0 = NexPage(0, 0, "page0"); // Page added as a touch event
NexPage page1 = NexPage(1, 0, "page1"); // Page added as a touch event
NexTouch *nex_listen_list[] =
{
&b1, // Button added
&b0, // Button added
&h0, // slider added
&h1, // slider added
&h2, // slider added
&h3, // slider added
&h4, // slider added
&page0, // Page added as a touch event
&page1, // Page added as a touch event
NULL // String terminated
}; // End of touch event list
char buffer[100] = {0};
//Declare your Nextion objects , pageid, component id., comLedponent name
void h0PopCallback(void *ptr) // Release event for slider
{
uint32_t number2 = 0; // Create variable to store value of slider
h0.getValue(&number2); // Read the value of the slider
licht1 = map(number2, 0,100,0,255);
analogWrite(CoolWhite, licht1);
Serial.print(licht1);
Serial.write(0xff);
Serial.write(0xff);
Serial.write(0xff);
}
void h1PopCallback(void *ptr) // Release event for slider
{
uint32_t number3= 0; // Create variable to store value of slider
h1.getValue(&number3); // Read the value of the slider
analogWrite(9, number3);
}
void h2PopCallback(void *ptr) // Release event for slider
{
uint32_t number4= 0; // Create variable to store value of slider
h2.getValue(&number4); // Read the value of the slider
analogWrite(10, number4);
}
void h3PopCallback(void *ptr) // Release event for slider
{
uint32_t number5= 0; // Create variable to store value of slider
h3.getValue(&number5); // Read the value of the slider
analogWrite(11, number5);
}
void h4PopCallback(void *ptr) // Release event for slider
{
uint32_t number6= 0; // Create variable to store value of slider
h4.getValue(&number6); // Read the value of the slider
analogWrite(12, number6);
}
void setup() {
// put your setup code here, to run once:
Serial.begin(9600); // Start serial comunication at baud=9600
pinMode(CoolWhite, OUTPUT);
pinMode(WarmWhite, OUTPUT);
pinMode(RoyalBlue, OUTPUT);
pinMode(DeepRed, OUTPUT);
pinMode(Moonlight, OUTPUT);
//b0.attachPush(b0PushCallback); // Button press
//b1.attachPop(b1PopCallback); // Button release
h0.attachPop(h0PopCallback); // Slider release
h1.attachPop(h1PopCallback); // Slider release
h2.attachPop(h2PopCallback); // Slider release
h3.attachPop(h3PopCallback); // Slider release
h4.attachPop(h4PopCallback); // Slider release
}
void loop() {
// put your main code here, to run repeatedly:
nexLoop(nex_listen_list); // Check for any touch event
}>