User defined value?

Let’s say I want to make a heater or something and I want the user to set a desired temperature. How do I do that?

I can’t find any options for variables or even a regular number string. Only a constant number value but that can’t be changed?

The ‘buffer’ node is probably what you want for storing a value that can change. You will need additional code to control how it is changed. One alternative would be to use a potentiometer to select temperature. You would need to map the potentiometer range of 0-1 to the temperature range you wish to allow.

If you choose to use ‘buffer’ node, you will need some way for user to set it. This could be up/down buttons to increase/decrease temperature, or a single button to cycle through a range of temperatures.

Here is one coding option for a two-button solution:


The button on the left will increase selected temperature & the button on the right will decrease. You can change add/subtract to be values different than “1”. A cruise-control example would be that many cars will add 2 mph with accel button, but subtract 1 mph with coast button. You could also add/subtract fractional values (like 0.5) if you need to allow greater accuracy.

A down-side of the code above is it will always default to zero on boot/reset. You could change this by expanding select node to specify default value & have a boot node send a pulse to assign that value on startup. An alternate solution would be to put an ‘add’ node between the buffer and watch nodes to add your initial value to buffer output; this option is even more useful if you are using ‘count’ instead of buffer since it always resets to 0 and giving ‘count’ a different start value is very difficult.

There are many other options in XOD for achieving the same general functionality. There was another discussion not too long ago about allowing a button hold to allow continuous change (above example only allows one change per button press; you have to release & press button again for another change). If you are using a single button to rotate through a set range, the ‘count’ node might be a better option than ‘buffer’. Choosing the “best” solution would require knowing what hardware/code surrounds this little part of your program.

1 Like

Thank you!

I will be using a 3.5" touchscreen on an Arduino Mega with a simple GUI for the user to monitor and set certain values (such as temperature), then have the Arduino control a variety of devices via digital or analog pins depending on those set values. Default values would be a must!

I’m assuming there is a way for me to develop a GUI (perhaps devicedruid?), then port certain virtual buttons such as “tempUp” to my XOD program’s “tempUp” function?

I have quite a lot of experience programming aquarium controllers (Neptune Apex) and fully automating reef tanks (perhaps 20+ devices controlled by a variety of sensors) but very little experience with Arduino so there’s a bit of a leaning curve. I’m not trying to build an aquarium controller per se, but in function it is exactly what I want to build.

Libraries — XOD shows a couple libraries for touchscreen. Maybe one of them would be compatible with your hardware. Unfortunately, if these are not compatible, you will have a hard time using touchscreen in XOD. While XOD is extendable (as demonstrated by these libraries), it is not trivial, especially for beginners. There are built-in graphics nodes that might help you draw on your screen, but I didn’t see any to help pull in touchscreen data.

While I can help with general coding questions, I don’t have any experience with graphic displays, touchscreens, or serial communication, so I probably won’t be much help with those.

Unless you can find nodes to help with touchscreen, my recommendation would be to use hardware buttons, etc. to simulate touchscreen to develop your code, experiment with touchscreen as a separate project, then combine the two once you have a pretty good grasp on both. It will likely be very frustrating if you try to figure out both at the same time in the same program. That’s generally true of any non-trivial programming project. Get small parts working, then combine them to work together, then add the next part. Don’t try to write the entire program, then wonder what is wrong. Even the most advanced programmers will follow the same plan…they just have a higher level of what is non-trivial based on their experience.

1 Like

I’m extremely reluctant to part with the touchscreen. Thinking outside the box, perhaps I could use two arduino boards… Board 1 with touch screen and GIU to set user defined values and display current status, and the other with the XOD code to actually control the devices. Communication between the boards could perhaps be done with UART.

This gives the same final result and I can do the work of unifying the code into one board at a later point.