progress bar

Hello

Im very new to Arduino and coding,
I have a problem with the progress bar, is it possible to change the max and min values of the bar? I have only been able to get it to work from 0 to 100. I would like to have for example the value 500 represent the 100% of the bar.

Which progress bar are you talking about?

Sorry I forgot, Im using a Nextion 3,5" lcd.
So I would like to have the progress bar in the Nextion editor to start at for example the value 200 = 0% and stop at value 500 = 100%.

How about posting some code ?

Still not very clear. Do you have any code to show us? (Use code tag)

In this example i can set the how manny times a led shall blink and start the blinking sequence, this works fine, now i would like to have the x amount of blinks being displayed in the progress bar.

#include "Nextion.h"



NexText textNumber = NexText(1, 1, "textNumber");

NexButton buttonPlus = NexButton(1, 2, "buttonPlus");

NexButton buttonMinus = NexButton(1, 3, "buttonMinus");

NexButton start = NexButton(1, 4,     "start");
NexProgressBar j0  = NexProgressBar(0, 3, "j0");         // progress bar

int ledPin = 8;
int number = 15;
char buffer[10] = {0};

NexTouch *nex_listen_list[] =
{
 &textNumber,
 &buttonPlus,
 &buttonMinus,
 &start,                                                       // progress bar
 
 NULL
};

void buttonPlusPushCallback(void *ptr)
{
 dbSerialPrintln("buttonPlusPushCallback");

 if (number < 60) number += 1;

 memset(buffer, 0, sizeof(buffer)); // clear buffer
 itoa(number, buffer, 10);
 textNumber.setText(buffer);
}


void buttonMinusPushCallback(void *ptr)
{
 dbSerialPrintln("buttonMinusPushCallback");

 if (number > 1) number -= 1;
 
 memset(buffer, 0, sizeof(buffer));  // clear buffer
 itoa(number, buffer, 10);
 textNumber.setText(buffer);
}


void StartPopCallback(void *ptr)
{   
 dbSerialPrintln("StartPopCallback");
 
   NexButton *btn = (NexButton *)ptr;
   memset(buffer, 0, sizeof(buffer));
   btn->getText(buffer, sizeof(buffer));
   if (strcmp(buffer,"start"))
   {    
    
for(int x=1; x<=number; x=x+1)  // the number X i would like to have displayed in the progress bar                                                                                           
                                                 
{   dbSerialPrintln(x);
   digitalWrite( ledPin, HIGH);
   delay(1000);
   digitalWrite( ledPin,  LOW);
   delay(1000);}

   
   uint32_t x = number;               // progress bar
  
   j0.getValue(x);

   if (x == x);
   
     
     else 
   j0.setValue(x);
   }
}
   










void setup(void)
{
 
 nexInit();
 
 Serial.begin(9600);
 pinMode( ledPin , OUTPUT);
 
 buttonPlus.attachPush(buttonPlusPushCallback);                      
 start.attachPush(StartPopCallback);
 buttonMinus.attachPush(buttonMinusPushCallback);

 dbSerialPrintln("Setup done");
}

void loop(void)
{ 
 nexLoop(nex_listen_list);
}

Slider_test_v2_1.ino (1.75 KB)

Hi,
Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Thanks... Tom.. :slight_smile:

   if (x == x);

Three problems here. First, it's beyond stupid to create a local variable in the body of the for loop with the same name as the index variable. Second, this statement will always evaluate to true, since is is not comparing the local variable to the index variable. Third, if statements rarely end with semicolons.

YOU need to do the mapping between the range of values that you want to be reflected in the progress bar and the range (0 to 100) that the bar can show. The map() function is trivial to use.