'pinMode' does not name a type

Hello! So, recently, I wanted to combine 3 codes. But I have an error with pinMode. If someone helps me, Thank you so much!! This is the code:

/*
  Fade

  This example shows how to fade an LED on pin 9 using the analogWrite()
  function.

  The analogWrite() function uses PWM, so if you want to change the pin you're
  using, be sure to use another PWM capable pin. On most Arduino, the PWM pins
  are identified with a "~" sign, like ~3, ~5, ~6, ~9, ~10 and ~11.

  This example code is in the public domain.

  https://www.arduino.cc/en/Tutorial/BuiltInExamples/Fade
*/

int led = 9;           // the PWM pin the LED is attached to
int brightness = 0;    // how bright the LED is
int fadeAmount = 5;    // how many points to fade the LED by
pinMode = (LED_BUILTIN, OUTPUT);
const int sensorPin = 0;
const int ledPin = 10;
int lightCal;
int lightVal;

void setup{
  // We'll set up the LED pin to be an output.
  pinMode(ledPin, OUTPUT);
  lightCal = analogRead(sensorPin);
   pinMode =(LED_BUILTIN, OUTPUT);
    pinMode = (led, OUTPUT);
    
}

void loop{
  pr()
  blink()
  fade()
}

void pr()
{
  //Take a reading using analogRead() on sensor pin and store it in lightVal
  lightVal = analogRead(sensorPin);


  //if lightVal is less than our initial reading (lightCal) minus 50 it is dark and
  //turn pin 9 HIGH. The (-50) part of the statement sets the sensitivity. The smaller
  //the number the more sensitive the circuit will be to variances in light.
  if (lightVal < lightCal - 50)
  {
    digitalWrite(9, HIGH);
  }

  //else, it is bright, turn pin 9 LOW
  else
  {
    digitalWrite(9, LOW);
  }

}
// the loop function runs over and over again forever
void blink() {
  digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);                       // wait for a second
  digitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);                       // wait for a second
}


// the loop routine runs over and over again forever
void fade() {
  // set the brightness of pin 9:
  analogWrite(led, brightness);

  // change the brightness for next time through the loop:
  brightness = brightness + fadeAmount;

  // reverse the direction of the fading at the ends of the fade:
  if (brightness <= 0 || brightness >= 255) {
    fadeAmount = -fadeAmount;
  }
  // wait for 30 milliseconds to see the dimming effect
  delay(30);
}

and the error is

Fade:19:1: error: 'pinMode' does not name a type
pinMode = (LED_BUILTIN, OUTPUT);
^~~~~~~
Fade:25:6: error: variable or field 'setup' declared void
void setup{
^~~~~
Fade:27:26: error: expected '}' before ';' token
pinMode(ledPin, OUTPUT);
^
Fade:28:3: error: 'lightCal' does not name a type
lightCal = analogRead(sensorPin);
^~~~~~~~
Fade:29:4: error: 'pinMode' does not name a type
pinMode =(LED_BUILTIN, OUTPUT);
^~~~~~~
Fade:30:5: error: 'pinMode' does not name a type
pinMode = (led, OUTPUT);
^~~~~~~
Fade:32:1: error: expected declaration before '}' token
}
^
exit status 1
'pinMode' does not name a type

any ideea? The error messages are in void setup(). Or so I think

Put the above in setup( )

And lose the "=" !

2 Likes

See the pinMode function reference.

pinmode is a function, not a variable. In the parentheses go the parameters.

pinMode(LED_BUILTIN, OUTPUT);
2 Likes

And change "void setup{" to "void setup() {". The parens tell the compiler you are declaring a function.

And change:

  pinMode = (LED_BUILTIN, OUTPUT);
  pinMode = (led, OUTPUT);

to

  pinMode(LED_BUILTIN, OUTPUT);
  pinMode(led, OUTPUT);

And change "void loop{" to "void loop() {", same as for setup.

And add ';' after each of these three statements:

  pr()
  blink()
  fade()

Then your sketch will compile.

Thank you very much! You helped me a lot!!!

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.