string to int - stuck with the basics

hello guys,
I'm actually a new comer here. when I was following a basic project I got stuck with converting string to int, but that int is a pre-defined one. For the easiness, I have remove the bulky coding and developed a simple basic example to tell my problem to you guys.this is the code.

From the following code, I want to print 54 in the serial monitor.

int pin1=54;

int Num=1;

int ans=parseInt("pinNum"); // this is the problem. this is wrong.

void setup(){
Serial.begin(9600); // to print the answer
}

void loop()
{
Serial.println(ans); // I expect the answer from this code line as 54
delay(1000);
}

Hi,
Welcome to the forum.

That is funny, you already know what is wrong.
Don't use the parseInt(), use the Println() to print the integer.

In the reference : http://arduino.cc/en/Serial/Println
it says that the parameter can be 'any type'. You can use integer, longs, strings as a parameter and it will be converted and printed. It's a very flexible and easy function.

Serial.println( pin1);

The parseInt() reads the serial data, and tries to read an integer. Suppose you type a number in the serial monitor (on the computer) and the Arduino should read that number. That is what the parseInt() is for.

Copy the following program into your IDE and compile it. When done, run the Serial monitor (Tools --> Serial Monitor), type in a number that is less than 32000 and click the Send button. After seeing what happens, explain what's going on in the program.

void setup() {

  Serial.begin(9600);
}

void loop() {
 
  int charsRead;
  int value;
  char inputBuffer[11];

  if (Serial.available() > 0) {
    charsRead = Serial.readBytesUntil('\n', inputBuffer, 10);
    inputBuffer[charsRead] = '\0';
    value = atoi(inputBuffer);
    Serial.println(value);
  }    
}