# 'x' does not name a type

**URL:** <https://forum.arduino.cc/t/x-does-not-name-a-type/549439>\
**Category:** Programming\
**Created:** [October 5, 2018, 5:10am UTC](https://forum.arduino.cc/t/x-does-not-name-a-type/549439 "2018-10-05T05:10:36Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![YAB](https://avatars.discourse-cdn.com/v4/letter/y/ea666f/32.png) [@YAB](https://forum.arduino.cc/u/YAB)\
**Post date:** [October 5, 2018, 5:10am UTC](https://forum.arduino.cc/t/x-does-not-name-a-type/549439/1 "2018-10-05T05:10:36Z")

</div>

```cpp
x = 13
void setup(){
  pinMode(x, OUTPUT);
}
void loop(){
  digitalWrite(x, HIGH);
  delay(100);
  digitalWrite(x, LOW);
  delay(100);
}

```

The error i am getting is

```cpp
exit status 1
'x' does not name a type

```

---

<div class="post-metadata">

**Author:** ![pert](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/pert/32/217111_2.png) [@pert](https://forum.arduino.cc/u/pert)\
**Post date:** [October 5, 2018, 5:40am UTC](https://forum.arduino.cc/t/x-does-not-name-a-type/549439/2 "2018-10-05T05:40:14Z")

</div>

This is how a variable declaration looks:

```cpp
byte x = 13;

```

You must declare the type of the variable.

The type determines how much memory is assigned to the variable, and thus how large/small a number it can hold. The type also determines whether the variable can hold negative numbers (signed types) or only positive numbers (unsigned types).

In the case of a variable that will store a pin number, the use of the unsigned 8 bit byte type is a good choice because there are no negative pin numbers. A byte can hold numbers up to 255 and there are no Arduino boards that have more than than many pins.

All C++ statements must end in a semicolon.

You can find more information on types here:

> **[Arduino Reference - Arduino Reference](https://www.arduino.cc/reference/en/)**
>
> The Arduino programming language Reference, organized into Functions, Variable and Constant, and Structure keywords.

---

<div class="post-metadata">

**Author:** ![YAB](https://avatars.discourse-cdn.com/v4/letter/y/ea666f/32.png) [@YAB](https://forum.arduino.cc/u/YAB)\
**Post date:** [October 5, 2018, 8:23am UTC](https://forum.arduino.cc/t/x-does-not-name-a-type/549439/3 "2018-10-05T08:23:34Z")

</div>

Thank you so much it works out well....

---

<div class="post-metadata">

**Author:** ![pert](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/pert/32/217111_2.png) [@pert](https://forum.arduino.cc/u/pert)\
**Post date:** [October 5, 2018, 12:21pm UTC](https://forum.arduino.cc/t/x-does-not-name-a-type/549439/4 "2018-10-05T12:21:05Z")

</div>

I'm glad to hear it's working now. Enjoy!  
Per

---

<div class="post-metadata">

**Author:** ![johnwasser](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/johnwasser/32/214270_2.png) [@johnwasser](https://forum.arduino.cc/u/johnwasser)\
**Post date:** [October 5, 2018, 2:29pm UTC](https://forum.arduino.cc/t/x-does-not-name-a-type/549439/5 "2018-10-05T14:29:31Z")

</div>

In general you should use more meaningful names for your variables and constants. It appears that you are using the name 'x' to mean "The pin number of the built-in LED". (Note: The Arduino IDE already provides a name: LED\_BUILTIN.)

```cpp
void setup()
{
  pinMode(LED_BUILTIN, OUTPUT);
}

void loop()
{
  digitalWrite(LED_BUILTIN, HIGH);
  delay(100);
  digitalWrite(LED_BUILTIN, LOW);
  delay(100);
}

```

If you wanted to blink an LED that you wire to a DIFFERENT pin it would be good to use a name that includes the terms LED and Pin, like:

```cpp
const byte LEDPin = 5;

void setup()
{
  pinMode(LEDPin, OUTPUT);
}

void loop()
{
  digitalWrite(LEDPin, HIGH);
  delay(100);
  digitalWrite(LEDPin, LOW);
  delay(100);
}

```

If you are blinking multiple LEDs of different colors, you should add the color name to make it clear which is which:

```cpp
const byte RedLEDPin = 5;
const byte GreenLEDPin = 7;

void setup()
{
  pinMode(RedLEDPin, OUTPUT);
  pinMode(GreenLEDPin, OUTPUT);
}

void loop()
{
  digitalWrite(RedLEDPin, HIGH);
  delay(100);
  digitalWrite(GreenLEDPin, HIGH);
  delay(100);
  digitalWrite(GreenLEDPin, LOW);
  delay(100);
  digitalWrite(RedLEDPin, LOW);
  delay(100);
}

```

Once you get up to three or more pins that you want to treat similarly, it's time to learn about arrays and loops:

```cpp
const byte RedLEDPin = 5;
const byte GreenLEDPin = 7;
const byte BlueLEDPin = 3;

const byte LED_COUNT = 3;
const byte LEDPins[LED_COUNT] = {RedLEDPin, GreenLEDPin, BlueLEDPin};

void setup()
{
  for (int i = 0; i < LED_COUNT; i++)
  {
    pinMode(LEDPins[i], OUTPUT);
  }
}

void loop()
{
  // Light up each in turn
  for (int i = 0; i < LED_COUNT; i++)
  {
    digitalWrite(LEDPins[i], HIGH);
    delay(100);
  }

  // Turn off each in reverse order
  for (int i = LED_COUNT-1; i >= 0; i--)
  {
    digitalWrite(LEDPins[i], LOW);
    delay(100);
  }
}

```

Now, if you want to add more LEDs to the sequence you only need to change the value of LED\_COUNT and add the new pin name to the array. If you want to change the order in which the LEDs light up you just have to change the order in which you put them in the array. Nothing else has to change.

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [May 5, 2021, 11:24pm UTC](https://forum.arduino.cc/t/x-does-not-name-a-type/549439/6 "2021-05-05T23:24:12Z")

</div>


