How can I incorporate user defined input into code

Here's a better explanation. I'm looking to make a program that would allow the user to enter the parameters he'd like to have run. But, I'm a beginner and would like to be directed in the right direction. I'm basically looking for command names to allow me to search for and how I would assign a value to that input to allow the code to process that command.

Example:

How many rings before picking up a call:
(Then the user would be prompted to enter ring amounts.)

Enter ring amount: 12
(Then the user enters the amount, which in this case is 12. Now, that 12 is used in the program as a value.)


Serial Input Basics

SOSA74:
Here’s a better explanation. I’m looking to make a program that would allow the user to enter the parameters he’d like to have run. But, I’m a beginner and would like to be directed in the right direction. I’m basically looking for command names to allow me to search for and how I would assign a value to that input to allow the code to process that command.

Example:

How many rings before picking up a call:
(Then the user would be prompted to enter ring amounts.)

Enter ring amount: 12
(Then the user enters the amount, which in this case is 12. Now, that 12 is used in the program as a value.)

I don’t get what you’re asking.

Do you want some sort of MENU that gives a user choices that they pick, or do you want to know how to save already-input choices for future use?

What “media” will the user interact with? A serial display (i.e. a screen of text) or an LCD type of display and buttons?

This may help you… it’s a function that will read a line of data from the serial port into a buffer. The sketch is a complete demo, just rip out the readline function and do with it what you will.

To input numbers, have the user enter the number (like “123”) which will be TEXT, then use atoi() or atof() to convert it to a numeric variable.

// read a line from user into buffer, return char count
int readline (char *buf, int limit)
{
    int x;
    int ptr = 0;
    *buf = 0;

    while (1) {
        if (Serial.available()) {
            x = Serial.read();

            if (x == 0x0D) { // cr == end of line
                buf[ptr] = 0; // flag end of line
                return ptr; // return char count
            }

            if (x == 0x08) { // backspace
                if (ptr > 0) {
                    ptr--;
                    buf[ptr] = 0;
                    Serial.print ("\b \b"); // erase bs'd char
                }

            } else {
                if (ptr < (limit - 1)) {
                    Serial.print ((char) x); // echo char
                    buf[ptr] = x; // store in buffer
                    ptr++;
                }
            }
        }
    }
}

void setup (void)
{
    Serial.begin (115200);
}

void loop (void)
{
    int len;
    char buffer[32];
    Serial.print ("\r\nPlease type something: ");
    len = readline (buffer, 32);
    Serial.print ("\r\nYou typed: \"");
    Serial.print (buffer);
    Serial.print ("\" which contains ");
    Serial.print ((int) len);
    Serial.print (" characters.\r\n");
}

Hope this helps…

Adding to aarg's reply, also have a look at the eeprom library if you need to remember settings after a power cycle.

There is simple user input in Planning and Implementing a Program. It should give you a starting point.

...R

Okay, I’m trying to make a Growroom Controller that uses the Users predetermined settings to make certain functions happen based on input entered.

For example: I want my temperature to stay within 50 and 75 degrees. So I would make a option for the user to enter those perimeters like "Enter Temp Low: " and "Enter Temp High: " which would be used to enter the 50 for the low and 75 for the high. These values would determine if an air conditioner needs to be turned on once the temp passes 75 or if a heater needs to be turned on once the temp drops lower than 50.

I am using the following parts:

3.95 MCUfriend TFT LCD Touchscreen
Arduino Uno R3
DHT11 Sensor
Automated Direct Solid State Contactors

Krupski:
I don’t get what you’re asking.

Do you want some sort of MENU that gives a user choices that they pick, or do you want to know how to save already-input choices for future use?

What “media” will the user interact with? A serial display (i.e. a screen of text) or an LCD type of display and buttons?

This may help you… it’s a function that will read a line of data from the serial port into a buffer. The sketch is a complete demo, just rip out the readline function and do with it what you will.

To input numbers, have the user enter the number (like “123”) which will be TEXT, then use atoi() or atof() to convert it to a numeric variable.

// read a line from user into buffer, return char count

int readline (char *buf, int limit)
{
   int x;
   int ptr = 0;
   *buf = 0;

for (x = 0; x < limit; x++) {
       buf = 0;
   }

while (1) {
       if (Serial.available()) {
           x = Serial.read();

if (x == 0x0D) { // cr == end of line
               buf[ptr] = 0; // flag end of line
               return ptr; // return char count
           }

if (x == 0x08) { // backspace
               if (ptr > 0) {
                   ptr–;
                   buf[ptr] = 0;
                   Serial.print ("\b \b"); // erase bs’d char
               }

} else {
               if (ptr < (limit - 1)) {
                   Serial.print ((char) x); // echo char
                   buf[ptr] = x; // store in buffer
                   ptr++;
               }
           }
       }
   }
}

void setup (void)
{
   Serial.begin (115200);
}

void loop (void)
{
   int len;
   char buffer[32];
   Serial.print ("\r\nPlease type something: “);
   len = readline (buffer, 32);
   Serial.print (”\r\nYou typed: “”);
   Serial.print (buffer);
   Serial.print ("" which contains “);
   Serial.print ((int) len);
   Serial.print (” characters.\r\n");
}




Hope this helps......

Krupski:
I don’t get what you’re asking.

Do you want some sort of MENU that gives a user choices that they pick, or do you want to know how to save already-input choices for future use?

What “media” will the user interact with? A serial display (i.e. a screen of text) or an LCD type of display and buttons?

This may help you… it’s a function that will read a line of data from the serial port into a buffer. The sketch is a complete demo, just rip out the readline function and do with it what you will.

To input numbers, have the user enter the number (like “123”) which will be TEXT, then use atoi() or atof() to convert it to a numeric variable.

// read a line from user into buffer, return char count

int readline (char *buf, int limit)
{
   int x;
   int ptr = 0;
   *buf = 0;

for (x = 0; x < limit; x++) {
       buf = 0;
   }

while (1) {
       if (Serial.available()) {
           x = Serial.read();

if (x == 0x0D) { // cr == end of line
               buf[ptr] = 0; // flag end of line
               return ptr; // return char count
           }

if (x == 0x08) { // backspace
               if (ptr > 0) {
                   ptr–;
                   buf[ptr] = 0;
                   Serial.print ("\b \b"); // erase bs’d char
               }

} else {
               if (ptr < (limit - 1)) {
                   Serial.print ((char) x); // echo char
                   buf[ptr] = x; // store in buffer
                   ptr++;
               }
           }
       }
   }
}

void setup (void)
{
   Serial.begin (115200);
}

void loop (void)
{
   int len;
   char buffer[32];
   Serial.print ("\r\nPlease type something: “);
   len = readline (buffer, 32);
   Serial.print (”\r\nYou typed: “”);
   Serial.print (buffer);
   Serial.print ("" which contains “);
   Serial.print ((int) len);
   Serial.print (” characters.\r\n");
}




Hope this helps......

So I would make a option for the user to enter those perimeters

Enter them how? Where? The Arduino does not have a keyboard or a mind-reader crystal.

Some clarification is in order. Having us make assumptions is NOT the way to get help.

In this thread, fellow member jurs provides great code for using an LCD module’s up and down buttons to scroll then hit select to accept.

I used it in my project to determine the value of “g” with a pendulum: user needs to provide the length of the pendulum.

PaulS:
Enter them how? Where? The Arduino does not have a keyboard or a mind-reader crystal.

And the mind-reading resonators just aren’t as accurate. :smiley:

Look into capacitive touch buttons if you want buttons with no moving parts. It will take some code but you won't need the debounce code that contact buttons and with some work you can make your own.

OTOH those bubble buttons are cheap and last longer than they have any right to and there are libraries for them, it's almost plug and play.