just a quicky

hi guys

if i wanted to make a project where i have a LCD screen with a value displayed and 4 buttons to edit and save this value would this be the best way to do it

i want to be able to ‘edit’ and save the number that is displayed if you print the value to the analog pin to the LCD screen if that makes sense?

int item 1
int item 2

(analog)pin 0 = analog read
(digital) pin 0 = edit button
pin 1 = increase value button
pin 2 = decrease value button
pin 3 = save

{
if analog read = 150
print item 1 to lcd

when (analog)pin 0 is high
if pin 1 is high +1 to item 1
if pin 2 is high - 1 from item 1
if pin 3 is high save item 1
}

{
if analog read = 150
print item 2 to lcd

when (analog)pin 0 is high
if pin 1 is high +1 to item 1
if pin 2 is high - 1 from item 1
if pin 3 is high save item 1
}

and so on and on and on ;D

please excuse noobishness above - to write that in C would take me a week ;D

but is that a decent basic structure of how to do this

my other idea is this which i have written (its a serial LCD hence the lack of lcd library)

const int analogPin = 0;    // the pin that the potentiometer is attached to
void setup()
{
  Serial.begin(9600);
  backlightOn();
}

void loop(){  
  int analogVal = analogRead(analogPin);
                              

  if (analogVal ==0){ 
    selectLineOne();
    delay(20);
    Serial.print("0000");  
  }  
    if (analogVal ==1){ 
    selectLineOne();
    delay(20);
    Serial.print("0001");  
  }
  if (analogVal ==2){ 
    selectLineOne();
    delay(20);
    Serial.print("0002");  
  }
    if (analogVal ==3){ 
    selectLineOne();
    delay(20);
    Serial.print("0003");  
  }
  if (analogVal ==4){ 
    selectLineOne();
    delay(20);
    Serial.print("0004");  
  }
  if (analogVal ==5){ 
    selectLineOne();
    delay(20);
    Serial.print("0005");  
  }
  if (analogVal ==6){ 
    selectLineOne();
    delay(20);
    Serial.print("0006");  
  }
  if (analogVal ==7){ 
    selectLineOne();
    delay(20);
    Serial.print("0007");  
  }
    if (analogVal ==8){ 
    selectLineOne();
    delay(20);
    Serial.print("0008");  
  }
    if (analogVal ==9){ 
    selectLineOne();
    delay(20);
    Serial.print("0009");  
  }
  if (analogVal ==10){ 
    selectLineOne();
    delay(20);
    Serial.print("00010");  
  }
  if (analogVal ==11){ 
    selectLineOne();
    delay(20);
    Serial.print("0011");  
  }

  selectLineTwo();   
  delay(100);
  Serial.print(analogRead(analogPin));
  Serial.print(" AT PIN ZERO");
  delay(100);
}

void selectLineOne(){  //puts the cursor at line 0 char 0.
  Serial.print(0xFE, BYTE);   //command flag
  Serial.print(128, BYTE);    //position
}
void selectLineTwo(){  //puts the cursor at line 0 char 0.
  Serial.print(0xFE, BYTE);   //command flag
  Serial.print(192, BYTE);    //position
}
void goTo(int position) { //position = line 1: 0-15, line 2: 16-31, 31+ defaults back to 0
  if (position<16){ 
    Serial.print(0xFE, BYTE);   //command flag
    Serial.print((position+128), BYTE);    //position
  }
  else if (position<32){
    Serial.print(0xFE, BYTE);   //command flag
    Serial.print((position+48+128), BYTE);    //position 
  } 
  else { 
    goTo(0); 
  }
}

void clearLCD(){
  Serial.print(0xFE, BYTE);   //command flag
  Serial.print(0x01, BYTE);   //clear command.
}
void backlightOn(){  //turns on the backlight
  Serial.print(0x7C, BYTE);   //command flag for backlight stuff
  Serial.print(157, BYTE);    //light level.
}
void backlightOff(){  //turns off the backlight
  Serial.print(0x7C, BYTE);   //command flag for backlight stuff
  Serial.print(128, BYTE);     //light level for off.
}
void serCommand(){   //a general function to call the command flag for issuing all other commands   
  Serial.print(0xFE, BYTE);

could i do what i want to do with the above or am i on the wrong track completely

thank you

am i on the wrong track completely

Yep. Whenever you find your self writing the same lines over and over then you are doing something wrong. That is what computer programs are good at. Look at the sections of code and try to parametrise them. analogue value can take on values from zero to 4095 are you going to have that many blocks of code? Take the number, turn it into a string, then look at each character in the string and output it in turn to your LCD. Don't forget the leading zeros or blanks.

Your section:-

when (analog)pin 0 is high if pin 1 is high +1 to item 1 if pin 2 is high - 1 from item 1 if pin 3 is high save item 1 }

Will not work. Think you are trying to do real time programming so that section of the code will be executed many times while you finger is held on the button, maybe several thousand times a second. Do you want that?

ok cool 8-)

do you know where i can find an example of strings?

and as for the programming i want it so you press the button once and it adds /subtracts a one if you get me

i will worry about the string first ;D

thank you

Look at this:- http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1250910244

i want it so you press the button once

So you have to look and see if the state of the button has changed from last time. If it has and is now pressed then increment. Then, what ever the result of the last statement (increment or not) set the "last time state" to the state it is now.

update

ive got to this point :slight_smile:

#include <avr/pgmspace.h>
prog_char string_0[] PROGMEM = "1";   // "String 0" etc are strings to store - change to suit.
prog_char string_1[] PROGMEM = "2";
prog_char string_2[] PROGMEM = "3";
prog_char string_3[] PROGMEM = "4";
prog_char string_4[] PROGMEM = "5";
prog_char string_5[] PROGMEM = "6";
prog_char string_6[] PROGMEM = "7";
prog_char string_7[] PROGMEM = "8";
prog_char string_8[] PROGMEM = "9";
prog_char string_9[] PROGMEM = "10";
prog_char string_10[] PROGMEM = "11";
prog_char string_11[] PROGMEM = "12";
prog_char string_12[] PROGMEM = "13";
prog_char string_13[] PROGMEM = "14";
prog_char string_14[] PROGMEM = "15";
prog_char string_15[] PROGMEM = "16";
prog_char string_16[] PROGMEM = "17";
prog_char string_17[] PROGMEM = "18";
prog_char string_18[] PROGMEM = "19";
prog_char string_19[] PROGMEM = "20";
prog_char string_20[] PROGMEM = "21";
prog_char string_21[] PROGMEM = "22";
prog_char string_22[] PROGMEM = "23";
prog_char string_23[] PROGMEM = "24";
prog_char string_24[] PROGMEM = "25";
prog_char string_25[] PROGMEM = "26";
prog_char string_26[] PROGMEM = "27";
prog_char string_27[] PROGMEM = "28";
prog_char string_28[] PROGMEM = "29";
prog_char string_29[] PROGMEM = "30";
prog_char string_30[] PROGMEM = "31";
prog_char string_31[] PROGMEM = "32";
prog_char string_32[] PROGMEM = "33";
prog_char string_33[] PROGMEM = "34";
prog_char string_34[] PROGMEM = "35";
prog_char string_35[] PROGMEM = "36";
prog_char string_36[] PROGMEM = "37";
prog_char string_37[] PROGMEM = "38";
prog_char string_38[] PROGMEM = "39";
prog_char string_39[] PROGMEM = "40";
prog_char string_40[] PROGMEM = "41";
prog_char string_41[] PROGMEM = "42";
prog_char string_42[] PROGMEM = "43";
prog_char string_43[] PROGMEM = "44";
prog_char string_44[] PROGMEM = "45";
prog_char string_45[] PROGMEM = "46";
prog_char string_46[] PROGMEM = "47";
prog_char string_47[] PROGMEM = "48";
prog_char string_48[] PROGMEM = "49";
prog_char string_49[] PROGMEM = "50";
prog_char string_50[] PROGMEM = "51";
prog_char string_51[] PROGMEM = "52";
prog_char string_52[] PROGMEM = "53";
prog_char string_53[] PROGMEM = "54";
prog_char string_54[] PROGMEM = "55";
prog_char string_55[] PROGMEM = "56";
prog_char string_56[] PROGMEM = "57";
prog_char string_57[] PROGMEM = "58";
prog_char string_58[] PROGMEM = "59";
prog_char string_59[] PROGMEM = "60";
prog_char string_60[] PROGMEM = "61";
prog_char string_61[] PROGMEM = "62";
prog_char string_62[] PROGMEM = "63";
prog_char string_63[] PROGMEM = "64";
prog_char string_64[] PROGMEM = "65";
prog_char string_65[] PROGMEM = "66";
prog_char string_66[] PROGMEM = "67";
prog_char string_67[] PROGMEM = "68";
prog_char string_68[] PROGMEM = "69";
prog_char string_69[] PROGMEM = "70";
prog_char string_70[] PROGMEM = "71";
prog_char string_71[] PROGMEM = "72";
prog_char string_72[] PROGMEM = "73";
prog_char string_73[] PROGMEM = "74";
prog_char string_74[] PROGMEM = "75";
prog_char string_75[] PROGMEM = "76";
prog_char string_76[] PROGMEM = "77";
prog_char string_77[] PROGMEM = "78";
prog_char string_78[] PROGMEM = "79";
prog_char string_79[] PROGMEM = "80";
prog_char string_80[] PROGMEM = "81";
prog_char string_81[] PROGMEM = "82";
prog_char string_82[] PROGMEM = "83";
prog_char string_83[] PROGMEM = "84";
prog_char string_84[] PROGMEM = "85";
prog_char string_85[] PROGMEM = "86";
prog_char string_86[] PROGMEM = "87";
prog_char string_87[] PROGMEM = "88";
prog_char string_88[] PROGMEM = "89";
prog_char string_89[] PROGMEM = "90";
prog_char string_90[] PROGMEM = "91";
prog_char string_91[] PROGMEM = "92";
prog_char string_92[] PROGMEM = "93";
prog_char string_93[] PROGMEM = "94";
prog_char string_94[] PROGMEM = "95";
prog_char string_95[] PROGMEM = "96";
prog_char string_96[] PROGMEM = "97";
prog_char string_97[] PROGMEM = "98";
prog_char string_98[] PROGMEM = "99";

// Then set up a table to refer to your strings.

PROGMEM const char *string_table[] =          // change "string_table" name to suit
{   
  string_0,
  string_1,
  string_2,
  string_3,
  string_4,
  string_5, 
  string_6,
  string_7,
  string_8,
  string_9,
  string_10,
  string_11,
  string_12,
  string_13,
  string_14,
  string_15,
  string_16,
  string_17,
  string_18,
  string_19,
  string_20,
  string_21,
  string_22,
  string_23,
  string_24,
  string_25,
  string_26,
  string_27,
  string_28,
  string_29,
  string_30,
  string_31,
  string_32,
  string_33,
  string_34,
  string_35,
  string_36,
  string_37,
  string_38,
  string_39,
  string_40,
  string_41,
  string_42,
  string_43,
  string_44,
  string_45,
  string_46,
  string_47,
  string_48,
  string_49,
  string_50,
  string_51,
  string_52,
  string_53,
  string_54,
  string_55,
  string_56,
  string_57,
  string_58,
  string_59,
  string_60,
  string_61,
  string_62,
  string_63,
  string_64,
  string_65,
  string_66,
  string_67,
  string_68,
  string_69,
  string_70,
  string_71,
  string_72,
  string_73,
  string_74,
  string_75,
  string_76,
  string_77,
  string_78,
  string_79,
  string_80,
  string_81,
  string_82,
  string_83,
  string_84,
  string_85,
  string_86,
  string_87,
  string_88,
  string_89,
  string_90,
  string_91,
  string_92,
  string_93,
  string_94,
  string_95,
  string_96,
  string_97,
  string_98};

char buffer[100];    // make sure this is large enough for the largest string it must hold
const int analogPin = 0;    // the pin that the potentiometer is attached to
void setup()                    
{
  Serial.begin(9600);
  backlightOn();
}


void loop()                    
{
  /* Using the string table in program memory requires the use of special functions to retrieve the data.
   The strcpy_P function copies a string from program space to a string in RAM ("buffer"). 
   Make sure your receiving string in RAM  is large enough to hold whatever
   you are retrieving from program space. */


  for (int i = 0; i < 6; i++)
  {
    i = map(analogRead(analogPin), 0, 1030, 0, 99);
    strcpy_P(buffer, (char*)pgm_read_word(&(string_table[i]))); // Necessary casts and dereferencing, just copy. 
    selectLineOne();
    Serial.print( buffer );
    delay( 50 );
      
  }
}
void selectLineOne(){  //puts the cursor at line 0 char 0.
   Serial.print(0xFE, BYTE);   //command flag
   Serial.print(128, BYTE);    //position
}
void selectLineTwo(){  //puts the cursor at line 0 char 0.
   Serial.print(0xFE, BYTE);   //command flag
   Serial.print(192, BYTE);    //position
}
void goTo(int position) { //position = line 1: 0-15, line 2: 16-31, 31+ defaults back to 0
if (position<16){ Serial.print(0xFE, BYTE);   //command flag
              Serial.print((position+128), BYTE);    //position
}else if (position<32){Serial.print(0xFE, BYTE);   //command flag
              Serial.print((position+48+128), BYTE);    //position 
} else { goTo(0); }
}

void clearLCD(){
   Serial.print(0xFE, BYTE);   //command flag
   Serial.print(0x01, BYTE);   //clear command.
}
void backlightOn(){  //turns on the backlight
    Serial.print(0x7C, BYTE);   //command flag for backlight stuff
    Serial.print(157, BYTE);    //light level.
}
void backlightOff(){  //turns off the backlight
    Serial.print(0x7C, BYTE);   //command flag for backlight stuff
    Serial.print(128, BYTE);     //light level for off.
}
void serCommand(){   //a general function to call the command flag for issuing all other commands   
  Serial.print(0xFE, BYTE);
}

am i heading in the right direction now?

I don’t get the big string table - surely even “sprintf” would take less program memory?

i must be honest and say i am a complete and utter noob and i am just keeping it simple

it takes up about 3k - just over 10% of what i can have

LOADS of room ;D

AWOL is saying that you don't need strings like that table... at all.

You're calculating a nice variable i. The Serial class already knows how to print variables as numbers without all of the string hassle you're doing.

i = map(analogRead(analogPin), 0, 1023, 0, 99);
Serial.print(i, DEC);