0

I have 2 questions.

  1. Why we have to put our functions before void loop and void setup into VScode+platformio?
  2. I switched from arduino IDE to VScode+platformio today, when I upload the sketch with platformio into my esp-12, it doesn't work. (It works with arduino IDE)

I have this Warning: src\main.cpp:46:24: warning: large integer implicitly truncated to unsigned type [-Woverflow] const byte menuColor = 0XF206;

[EDIT]The problem comes from these lines:

attachInterrupt(digitalPinToInterrupt(enA), enAin, RISING);
attachInterrupt(digitalPinToInterrupt(enB), enBin, RISING);
attachInterrupt(digitalPinToInterrupt(enBtn), enBtnIn, FALLING);


2
  • 1) read [Functions in C++](For question 1, read Function in C++ for better understanding on function declaration. For question 2, 0xF206 is 16-bit long, or 2 bytes, so you should declare your variable as use const unsigned int menuColor = 0xF206;, and read more here.
    – hcheung
    Feb 24, 2020 at 1:06
  • "when I upload the sketch" .... that should say when I compile the sketch .... the upload happens after your sketch is successfully compiled .... in your case, the upload to the ESP-12 never happens
    – jsotola
    Feb 24, 2020 at 15:58

1 Answer 1

1

Why we have to put our functions before void loop and void setup into VScode+platformio?

Because that is how C works. The Arduino IDE hides it from you by adding function prototypes at the start of your code.

I switched from arduino IDE to VScode+platformio today, when I upload the sketch with platformio into my esp-12, it doesn't work. (It works with arduino IDE)

const byte menuColor = 0XF206;

That can never work. The value 0x06 will be assigned to menuColor since a byte is only 8 bits. You need to learn to use data types that are suitable for the values you are trying to store in them.

1
  • Thank, you I understand my error with menuColor. Now I know what's the problem. ``` #include <Arduino.h> const int enBtn = 3; void en(){ digitalWrite(2,1); delay(500); digitalWrite(2,0); delay(500); } void setup() { pinMode(2, OUTPUT); pinMode(enBtn, INPUT); attachInterrupt(digitalPinToInterrupt(enBtn), en, FALLING); //Doesn't work into platformio } void loop() { // put your main code here, to run repeatedly: }
    – 2CoB9
    Feb 24, 2020 at 10:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.