Go Down

Topic: Changing int numbers with external means (Read 1 time) previous topic - next topic

jokefox

The IDE's editor ( or indeed any half decent editor) has a search-and-replace feature.
are you even reading my questions?


cattledog

Quote
what i want is to change all the times below with buttons instead of going into
the ide, changing them and then re compiling the code, does that make sense?
Yes, you want take all the #defines, type them as integers, and re design the program to have a user interface for changing those variables. I think you said you want to use buttons on a tft display?  Designing a touch screen graphical user interface (GUI) is not trivial and you will not get a quick and easy answer here. 

Start with a Google search "tft user interface for Aduino" will probably get you started.

If you have some other user interface in mind like a smart phone, physical buttons, a laptop or other pc Google can get you going there as well.

AWOL

are you even reading my questions?


Yes, but they look like they're written by someone who isn't sure what they want to do, or even how to explain themselves, so I'm just assuming the worst case, but falling some way short, it seems.

jokefox

#18
Apr 15, 2018, 11:12 pm Last Edit: Apr 15, 2018, 11:14 pm by jokefox
1. dont worry about the tft display worry about my question,  i got my gui built and everything ready, but kinda pointless when
i cant tell the buttons what to do, right?

2. i dont know wtf im trying to ask , so i wrote this code to try to explain what i want, maybe i got it right?

i know i need to redo it for every int i have, so like ( timeon1hour, timeoff1hour, and etc)

but is this correct? will "number" be seen by the number i button myself to

Code: [Select]

int number = 0;
int timeonlights = number;


void setup() {
  // put your setup code here, to run once:
Serial.begin(9600);
pinMode(5, INPUT);
pinMode(6, INPUT);


}

void loop() {



if(5 == HIGH)
{
 number = number +1;
 Serial.print("number plus one");
 Serial.println(number);
}
 if(6 == HIGH)
{
  number = number -1;
   Serial.println("number minus one");
   Serial.println(number);
}

  // because rtc3231 uses 0 as a number, 0 = 1 and 23 = 24

if (number > 23)
{
  number = 0;
}

}

AWOL

Code: [Select]
if(5 == HIGH)Does five equal one?
Not in my experience, ever.

UKHeliBob

Take a look at the StateChangeDetection example in the IDE
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

cattledog

Quote
but is this correct?
No, the code you posted not correct in several ways.
1) You need to digitalRead() the input pins instead of using conditional tests on the pin numbers. The numbers 5 and 6 will always be HIGH.
2) You need to register state changes(went HIGH or went LOW) rather than state(HIGH or LOW) when working with button inputs and counting.

I'm sure these principles apply to tft "buttons" as well as physical ones.

If you can get a button to successfully change a number, the changed number an be used by the program.

cattledog

#22
Apr 16, 2018, 12:01 am Last Edit: Apr 16, 2018, 12:02 am by cattledog
r
Quote
I have a nextion display where i can have all the buttons in the world.
There are several library examples shown which increment numbers with buttons here. Have you looked at them?

https://github.com/itead/ITEADLIB_Arduino_Nextion/tree/master/examples

jokefox

Code: [Select]
if(5 == HIGH)Does five equal one?
Not in my experience, ever.
Like 5 as in pin five

Take a look at the StateChangeDetection example in the IDE
Thank you. Someone actually being usefull.

Cattledog. I dont need a tft working yet. I need buttons to make sure it all works first. Read all the posts before you comment please

BulldogLowell


jokefox

Ok i see where i went wrong this should get me in the right direction.
Thanks guys :)

Now my last question.

Where i have it at the top

Int number = 0;
Int lightson1time = number;


Is that part right?

So when i change it to 12 with button pushes it will be stored as 12 and not change untell i change it again?

jokefox

did it

Code: [Select]


const int  button1 = 2;
const int button2 = 3;

int light1ontime = 0;
int buttonstate1 = 0;
int buttonstate2 = 0;
int lastButton1 = 0;
int lastButton2 = 0;
void setup() {

  pinMode(button1, INPUT);
  pinMode(button2, INPUT);
  Serial.begin(9600);
}


void loop() {


  // add

  buttonstate1 = digitalRead(button1);
  if (buttonstate1 != lastButton1) {
    if (buttonstate1 == HIGH) {
      light1ontime++;
    }
  }

  lastButton1 = buttonstate1;
  if (light1ontime >= 25)
  {
    light1ontime = 0;
  }


  //subtract

  buttonstate2 = digitalRead(button2);
  if (buttonstate2 != lastButton2) {
    if (buttonstate2 == HIGH) {
      light1ontime--;
    }
  }

  lastButton2 = buttonstate2;
  if (light1ontime <= -1)
  {
    light1ontime = 24;
  }


  Serial.println(light1ontime);
}



Go Up