Can't get arduino code to work

So, even though I have ´´´#include <Arduino.h>´´´ in my code, it says that it can’t be found. Can someone help me? Thanks!

Please show the content of your platformio.ini and some minimal code to reproduce the error.

#include <Arduino.h>

const int wait = 500;
int redLedState;

void setup()
{
  pinMode(13, OUTPUT);
  Serial.begin(9600);
}

void loop()
{
  digitalWrite(13, HIGH);
  redLedState = digitalRead(13);
  Serial.print(" Red LED State is ");
  	if (redLedState = 1 ){
      Serial.println("On (1)");
	}
  delay(wait);
  digitalWrite(13, LOW);
  redLedState = digitalRead(13);
  Serial.print(" Red LED State is ");
  	if (redLedState = 1 ){
      Serial.println("Off (0)");
	}
  delay(wait);
}

and

[env:uno]
platform = atmelavr
board = uno
framework = arduino

For better readability I edited your post.

Please use pre-formatted text when posting code and log sections.

The settings in platformio.ini are okay.
The code does contain errors (both programming and logical errors).

That doesn’t make sense.
Pin 13 is HIGH because the digitalWrite. A digitalRead will also always return HIGH.

You’re using the assignment operator "=" here.
But you have to use the comparison operator "==":

if (redLedState == 1) 

The same error is in your 2nd if-statement plus an additional error:

Aside from the wrong operator again, the comparison must be against 0 instead of 1:

if (redLedState == 0) {
  Serial.println("Off (0)");
}

But none of this relates to the error you have.

Do you have multiple projects open in the VS Code workspace at the same time?
If so, remove all other projects from the workspace and restart VS Code.

If the error still occurs try “Rebuild IntelliSense Index” in Project Tasks / Miscellaneous:

image

1 Like