GPIO mapping in ESP8266

I bought an ESP8266 and a programmer board:

image

The board maps IO2 to GPIO2, IO5 to GPIO5 and so on.

I'm using FastLED.

#define FASTLED_ALLOW_INTERRUPTS 0

#include <FastLED.h>

#define NUM_LEDS 1

#define DATA_PIN 2
#define BUTTON_PIN 5

void ICACHE_RAM_ATTR buttonPushEvent ();

CRGB leds[NUM_LEDS];

void setup() {
  Serial.begin(9600);
  attachInterrupt(digitalPinToInterrupt(BUTTON_PIN), buttonPushEvent, CHANGE);

  FastLED.addLeds<WS2811, DATA_PIN, RGB>(leds, NUM_LEDS);
}

void loop() { 
  leds[0] = CRGB::Blue;
  FastLED.show();
  delay(500);
  leds[0] = CRGB::Black;
  FastLED.show();
  delay(500);
}

void buttonPushEvent() {
  Serial.println("Hola");
}

I actually connected my LED strips to the PIN 4, and a touch button to PIN 5.

I can't understand and wrap my head around the fact why putting LED strips to PIN2 doesn't work!

This code actually works fine, but I can't wrap my head around the fact that why putting the LED strip to PIN2 doesn't work. In code, it actually says PIN2 is for the LEDs.

On the other hand, IO5 has a button connected, which works according to the code I've written. So touching the button activates on IO5 and prints "Hola".

I moved the button to IO4, it works as usual if I change code to enable button on 4 instead.

But when I connect the LED to IO4, my code has to say #define DATA_PIN 2. When I connect the LED to IO0, my code has to say #define DATA_PIN 0.

What's going on in here with the LEDs? Why I have to put wrong pin number with trial and error to get it working?

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