A tricky one. selecting a text name with rotary encoder?

Hi Im designing a project where I need to select a location with a rotary encoder, and then when required the unit will send an \sms which will include its named location.

so the encoder will scroll through names which are displayed on the lcd... and then push to select.
I understand that this name will need to be stored .. as it will be used for reference.

where do i start?

cheers

Are all the names known when you write the sketch or will you need to add names in the field?

What is your display device?

Have you gotten your rotary encoder to count up and down? If not, try some of the many rotary encoder tutorials.

where do i start?

Start by reading the sensor and getting it to print out the number of pulses you have detected.
Then use that number to index an array containing the names you wantand print them out.
Then transfer that to the display you want to use.

the names will all be held in sketch..

Basically

Im designing a monitoring FM radio for use on our FM transmission sites.. each hilltop has 4 FM radio services..

using Arduino Uno, GSM sheild, & Si4703


You will switch unit on, and select transmiter hilltop site name.. via rotary encoder. or 2 switches..up - down

the radio will then tune to the 4 preset frequencies for that site, pausing on each one for a miniute or two.. the PI RDS text will be read, also carrier level. If any of this info fails, then an SMS message is sent, indicating which preset(station) is shutdown, including site location.

I have the GSM unit working well(thanks for the help) .

The radio is on order. so work in progress. (I know this will be the fun bit)

I'm looking to grasp how to hold the transmitter site list in the sketch and select it. then use that selected name.

I trust this makes some sense.

Thanks for any help, sorry to be asked to be spoon fed :wink: but need to start somewhere

Thanks

David

The simple version, if you have the SRAM for it, is:

char * Names[] = {"Name One", "Name Two", /* . . . */ "Name Fifty-three","Name Fifty-four"};
const int NAME_COUNT = sizeof Names / sizeof Names[0];
int NameIndex = 0;

On UP: NameIndex = (NameIndex+1)%NAME_COUNT; // Wrap around

On DOWN: NameIndex = (NameIndex-1)%NAME_COUNT; // Wrap around

Display Names[NameIndex]

Kudos to johnwasser for summing up the solution elegantly and concisely. Really nice answer, John. I just wanted to add that if you want to show a multi-line display, with several rows of names, all you have to do is display names[index] on the first line, then go to the second line and display names[index+1] and so on. You will need to think how to handle the case where they wrap around. Do you want to roll around to the beginning? If so, you can use the modulo trick that John suggested, outputting names[(index + 0..num_lines-1) % NAME_COUNT]. I believe that this should basically create an infinitely looping name list.

If you don't want to roll around to the beginning, then just stop increasing index when index = NAME_COUNT - num_lines (where num_lines is the number of lines in your LCD).

Many thanks for your excellent answer..nearlly got it to work..

Im getting a zero with name change?
Is "NameIndex" the variable I need to display on the LCd.
Im using "if", what do i need for the else?

here is my code

// libraries
#include <GSM.h>
#include <LiquidCrystal.h>

// PIN Number
#define PINNUMBER ""

// initialize the library instance
GSM gsmAccess;     // include a 'true' parameter to enable debugging
GSM_SMS sms;
GSMScanner scannerNetworks;
GSMModem modemTest;


// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 9, 8);

// This section descibes button connection.
const int buttonPin = A0; 
const int upbuttPin = A1; 
const int downbuttPin = A2; 
const int ledPin =  A5;
// variables will change:
int buttonState = 0;         // variable for reading the pushbutton status
int upbuttState = 0;         // variable for reading the pushbutton status
int downbuttState = 0;         // variable for reading the pushbutton status


// Save data variables
String IMEI = "";

// serial monitor result messages
String errortext = "ERROR";


/// NAME INDEX
char * Names[] = {
  "One", "Two", "Three","Four"};
const int NAME_COUNT = sizeof Names / sizeof Names[0];
int NameIndex = 0;

void setup()
{
  // initialize the pushbutton pin as an input:
  pinMode(buttonPin, INPUT);   
  pinMode(upbuttPin, INPUT); 
  pinMode(downbuttPin, INPUT); 
  pinMode(ledPin, OUTPUT);   

  // initialize serial communications and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }
  lcd.begin(16, 2);
  lcd.clear();
  lcd.setCursor(0, 1);
  lcd.print("GSM Connecting >");

  Serial.println("GSM networks scanner");
  scannerNetworks.begin();

  // connection state
  boolean notConnected = true;

  // Start GSM shield
  // If your SIM has PIN, pass it as a parameter of begin() in quotes
  while(notConnected)
  {
    if(gsmAccess.begin(PINNUMBER)==GSM_READY)
    { 
      notConnected = false;
      lcd.clear();
      lcd.setCursor(0, 1);
      lcd.print("Connected");
      delay(2000);
      lcd.clear();
    }

    else
    {
      Serial.println("Not connected");
      lcd.setCursor(0, 1);
      lcd.clear();
      lcd.print("NO GSM !");
      delay(1000);
    }
  }

  // get modem parameters
  // IMEI, modem unique identifier
  Serial.print("Modem IMEI: ");
  IMEI = modemTest.getIMEI();
  IMEI.replace("\n","");
  if(IMEI != NULL)
    Serial.println(IMEI);
}

void loop()
{
  ///////////////// SELECT SITE NAME //////////////////////
  // read the state of the pushbutton value:
  buttonState = digitalRead(upbuttPin);
  // if it is, the upbuttState is HIGH:
  if (upbuttState == HIGH) {     
    // increment name
    NameIndex = (NameIndex+1)%NAME_COUNT; } // Wrap around


  buttonState = digitalRead(downbuttPin);
  // if it is, the upbuttState is HIGH:
  if (downbuttState == HIGH) {     
    // increment name
    NameIndex = (NameIndex-1)%NAME_COUNT; } // Wrap around
lcd.setCursor(0, 0);
lcd.print(NameIndex);



  //////////////////DISPLAY GSM INFO ON LCD ///////////////
  // currently connected carrier
  Serial.print("Current carrier: ");
  Serial.println(scannerNetworks.getCurrentCarrier());

  //lcd.clear();
  lcd.setCursor(0, 1);
  // Print a message to the LCD.
  lcd.print(scannerNetworks.getCurrentCarrier());

  // returns strength and ber
  // signal strength in 0-31 scale. 31 means power > 51dBm
  // BER is the Bit Error Rate. 0-7 scale. 99=not detectable
  Serial.print("Signal Strength: ");
  Serial.print(scannerNetworks.getSignalStrength());
  Serial.println(" [0-31]");
  // set up the LCD's number of columns and rows: 
  lcd.setCursor(15, 1);
  lcd.print("%");
  lcd.setCursor(13, 1);
  lcd.print(scannerNetworks.getSignalStrength().toInt() * 100 / 32);

  ////////////////// ALARM & SEND SMS ////////////////////////
  // read the state of the pushbutton value:
  buttonState = digitalRead(buttonPin);
  // if it is, the buttonState is HIGH:
  if (buttonState == HIGH) {     
    // turn LED on:   
    digitalWrite(ledPin, HIGH); 

    sms.beginSMS("xxxxxxxxxphonenumber");
    lcd.clear();
    lcd.setCursor(0, 1);
    lcd.print("ALARM A0");
    delay(1000);
    lcd.clear();
    lcd.print("SMS SENDING");
    sms.print("arduino SD");
    sms.endSMS();  
    lcd.clear();
    lcd.setCursor(0, 1);
    lcd.print("SMS SENT OK");
    delay(10000);
    lcd.clear();
  } 
  else {
    digitalWrite(ledPin, LOW);

  }
}

really appreciate your help so far

Is "NameIndex" the variable I need to display on the LCd.

No
It's

Names[NameIndex]

You need to print out.

At the moment, you are printing "NameIndex", which is the numerical index into the array. You want to print "Names[NameIndex]", which is the element in the array that is at position NameIndex.