I handl in the school ardoino ide and we write a code the did work there but it did no work in the platform IO i dont know why can any body help thanks<3

#include <Arduino.h>
#define T0 34
#define T1 35
#define T2 36
#define LED 2

void setup()
{
pinMode(LED, OUTPUT);
pinMode(T0, INPUT);
pinMode(T1, INPUT);
pinMode(T2, INPUT);
digitalWrite(LED, HIGH);

attachInterrupt(digitalPinToInterrupt(T0), isr_T0, FALLING);
}

void loop()
{
if (digitalRead(T1) == LOW)
{
digitalWrite(LED, HIGH);
}
if (digitalRead(T2) == LOW)
{
digitalWrite(LED, LOW);
}
}

void isr_T0()
{
digitalWrite(LED, LOW);
}

You’ll find the answer here Convert Arduino file to C++ manually — PlatformIO latest documentation

Please use pre-formatted text when posting code or log files.
Also post the error log or at least describe the error you receive.
This will make it easier to help you.

1 Like

When I try to compile your code in a project, the following error message appears:

src/main.cpp: In function 'void setup()':
src/main.cpp:15:44: error: 'isr_T0' was not declared in this scope
 attachInterrupt(digitalPinToInterrupt(T0), isr_T0, FALLING);

This means the declaration of the function is missing.

#include <Arduino.h>
#define T0 34
#define T1 35
#define T2 36
#define LED 2

**void isr_T0();**  // <------- that was it

void setup()
{
pinMode(LED, OUTPUT);
pinMode(T0, INPUT);
pinMode(T1, INPUT);
pinMode(T2, INPUT);
digitalWrite(LED, HIGH);

attachInterrupt(digitalPinToInterrupt(T0), isr_T0, FALLING);
}

void loop()
{
if (digitalRead(T1) == LOW)
{
digitalWrite(LED, HIGH);
}
if (digitalRead(T2) == LOW)
{
digitalWrite(LED, LOW);
}
}

void isr_T0()
{
digitalWrite(LED, LOW);
}

https://learn.microsoft.com/en-us/cpp/cpp/declarations-and-definitions-cpp?view=msvc-170

I didn’t have an ESP board at hand and didn’t test the hardware requirements but if it worked in the Arduino IDE, it should work now :wink:

best regards
Holger

2 Likes
void isr_T0();

of course without the asterisks :slightly_smiling_face:

Why the “bold” font didn’t work here, no idea! :face_with_raised_eyebrow:

Formatting styles cannot be applied within a pre-formatted text block as the text is already formatted.