arduino programming on-the-go

Hello, I have a question for you guys. I need some way to change a variable on the arduino at least, or reprogram it entirely on some type of portable device. The easiest option (I believe) would be to use two buttons and a Binary display, most complicated some sort of Pocket PC with a serial terminal and a serial prompt on the arduino. Does anyone have a simpler idea or an implementation example?

Here is my code:
(Dists is the variable that I need to modify)

int pin = 9;
volatile int state = LOW;
volatile int Count = 0;
volatile int Dists = 1024;

void setup()
{
  pinMode(pin, OUTPUT);
  attachInterrupt(1, Dist, FALLING);
}

void loop()
{
  digitalWrite(pin, HIGH);
}

void Dist()
{
  Count++;
  if (Count >= Dists)
  {
    digitalWrite(pin, LOW);
  }
}

PS. Does this code look Ok? It is meant to be a very basic odometer, to make a car travel a certain distance and then stop.

How do you need to change it? Just to certain values or to any value?

Easiest way I can think of is storing it in the EEPROM and then getting something to talk to it serially or even just a button to change it.

Right now, I would need to adjust it to any value, but after I test and calibrate the robot, I could limit it down to ~10 specific numbers

This thread http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1199810491
has a discussion and code examples about sending integer values to the arduino using the serial port. If your portable device can connect to the arduino serial port this is one way to do it.

If you want to permanently save these values, then you could call functions like these to save and restore you values

// functions to read and write integer values into EEPROM
// if you only have one value to save, Address is 0;
// see http://www.arduino.cc/en/Reference/EEPROM for more info
void WriteEEPromInt(int Address, int Value)
{
    EEPROM.write(Address , (unsigned int)Value >> 8); 
    EEPROM.write(Address +1, (unsigned int)Value & 0xff); 
}

int ReadEEPromInt(int Address )
{
   return  (EEPROM.read(Address)  << 8) + EEPROM.read(Address +1) ;   
}

Assuming it isn't outside the scope of your project you could add a simple IR receiver circuit to your device that recognizes 0-9 (and something like # as a terminator) from a remote you have lying around.

I was considering using serial, but I don't have any easily accessible portable serial terminal devices. I know my PSP, ipod touch, and old Ipaq pda have serial ports, but none(except maybe the ipaq) have serial terminal software. Right now I am leaning towards the IR remote programming. I have many salvaged 38khz IR receivers, so I will be trying that tonight.

Also, I have my revised code. It works, reading an IR wheel encoder and controlling the distance of the vehicle. I am building it for the http://soinc.org/events/sample/ElectricVehicle_C08_v13%20_1_.pdfElectric Vehicle event in the Science Olympiad.

int pin = 9;
int ledPin = 13;
volatile int state = LOW;
volatile int Count = 0;
volatile int Dists = 65;

void setup()
{
  pinMode(pin, OUTPUT);
  pinMode(ledPin, OUTPUT);      // sets the digital pin as output
  attachInterrupt(1, Dist, FALLING);
}

void loop()
{
  digitalWrite(pin, HIGH);
}

void Dist()
{
  Count++;
  if (Count >= Dists)
  {
    digitalWrite(pin, LOW);
    digitalWrite(ledPin, HIGH);   // sets the LED on
    delay(100000);    
  }
}

EDIT: I just changed my mind. Iam in the process of obtaining a cybiko classic device, which has a built in serial port and keyboard, and you can easily uase it as a portable serial terminal.

Sorry to bump/double post, but I have another question. I changed my mind yet again, and decided to us an HP 100lx as the terminal. The problem is that the device can only send one byte at a time. Here is my test code:

int incomingByte = 0;      // for incoming serial data

void setup() {
      Serial.begin(9600);      // opens serial port, sets data rate to 9600 bps
}

void loop() {

      // send data only when you receive data:
      if (Serial.available() > 0) {
                Serial.println("Type in a Number");
            // read the incoming byte:
            incomingByte = Serial.read();

            // say what you got:
            Serial.print("I received: ");
                Serial.println(incomingByte, BYTE);

      }
}

Every time I press a key, the arduino returns with that value. But, If I use the serial monitor in the arduino software, It still sends the data back one byte at a time. I need to send a number, 4-5 characters long, and Have it save to a variable.

Every time I press a key, the arduino returns with that value. But, If I use the serial monitor in the arduino software, It still sends the data back one byte at a time. I need to send a number, 4-5 characters long, and Have it save to a variable.

You need a buffer and a end byte.
So when you get a byte you stick it in the buffer. If its the end byte (0x00?) then you process the instruction.

... If I use the serial monitor in the arduino software, It still sends the data back one byte at a time. I need to send a number, 4-5 characters long, and Have it save to a variable.

If you just want to receive integer values then you may want to look at the code linked in the beginning of reply#3.

I looked at that code, and will it compile and go right on the arduino, or is it just a function. It has no Setup or loop functions, so I wondered what else it would take to run it.

it is a function to be included in a sketch. But here is the key functionality in a sketch similar to yours

int incomingByte = 0;      // for incoming serial data

void setup() {
      Serial.begin(9600);      // opens serial port, sets data rate to 9600 bps
}

void loop() {
  
      // send data only when you receive data:
       if(Serial.available() >= 2 ){ 
          uint8_t      msb = Serial.read();    // this assumes the msb is sent first,
          uint8_t      lsb = Serial.read();
          incomingByte = lsb + (msb <<8);

           Serial.println("Type in a Number"); 
              // say what you got:
            Serial.print("I received: ");
          Serial.println(incomingByte, BYTE);
        }  
}

Note that you need to send your integer as two bytes for this to work.