How to take put a value (recievedChar) into a varaible

Hi,
I am an old dog with electronics, also with PLC. but I just now got my Arduino, first time with controllers.
I want to take a command from my computer and use it to set contacts. How do I put the value into a character. For example if i type 1, it will do a certain function, if i type 2 it will do something else etc.

int x = recievedChar; is apparently not the way forward.

Or am I on the wrong track here?

You need a lot more code than that...and you need to post the whole thing not just a tiny snippet.

Steve

Have you read the serial input basics tutorial?

For example if i type 1, it will do a certain function, if i type 2 it will do something else etc.

It can be as simple as

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

void loop()
{
  char x = Serial.read();
  if (x == '1')
    Serial.println("1 entered");
  else if (x == '2')
    Serial.println("2 entered");
}

but note that it needs a lot more code to do anything really useful, but it is a start

dvortex:
int x = recievedChar; is apparently not the way forward.

Or am I on the wrong track here?

Please post the complete program.

Also give some examples of the data being sent to the Arduino.

The parse example in Serial Input Basics should give you some ideas.

...R

Simple servo test code where a character representation of “number” is sent via the serial monitor to the arduino, the characters are captured into a variable, and then that variable is converted into an integer for use with the servo control functions.

// zoomkat 7-30-10 serial servo test
// type servo position 0 to 180 in serial monitor
// for writeMicroseconds, use a value like 1500
// Powering a servo from the arduino usually *DOES NOT WORK*.

String readString;
#include <Servo.h> 
Servo myservo;  // create servo object to control a servo 

void setup() {
  Serial.begin(9600);
  myservo.attach(9);
}

void loop() {

  while (Serial.available()) {

    if (Serial.available() >0) {
      char c = Serial.read();  //gets one byte from serial buffer
      readString += c; //makes the string readString
      delay(3);
    } 
  }

  if (readString.length() >0) {
    Serial.println(readString);
    int n = readString.toInt();
    Serial.println(n);
    myservo.writeMicroseconds(n);
    //myservo.write(n);
    readString="";
  } 
}