Discuss here different C compiler set ups, and compiling executables for the ESP8266

User avatar
By Swarnalatha J
#43679 Hi,
Code: Select all#include "ets_sys.h"
#include "osapi.h"
#include "gpio.h"
#include "os_type.h"
#include "user_config.h"

static const int pin = 0;
int flag = 0;
void service (void)
{
flag=1;
uint32 gpio_status = GPIO_REG_READ(GPIO_STATUS_ADDRESS);
GPIO_REG_WRITE(GPIO_STATUS_W1TC_ADDRESS, gpio_status);
}

void ICACHE_FLASH_ATTR user_init()
{
  // init gpio subsytem
 gpio_init();

 gpio_output_set(0, 0, BIT0, 0);
 gpio_output_set(0, 0, 0, BIT5);
       gpio_pin_intr_state_set(GPIO_ID_PIN(5), GPIO_PIN_INTR_NEGEDGE);
        ETS_GPIO_INTR_ENABLE();
        ETS_GPIO_INTR_ATTACH(service, NULL);

 while(true)
{
 if(flag == 1)
{
if(GPIO_INPUT_GET(pin)) //read current status of led and set low if it is high now
 {
  //set gpio low
  gpio_output_set(0, BIT0, 0, 0);
 }
  else
  {
    // set gpio high
   gpio_output_set(BIT0, 0, 0, 0);

  }
while(GPIO_INPUT_GET(5) == 0);           // for long press of button stay inside this loop. Do not consider it as another input.

flag = 0;
}


}
}


I'm using ESP8266 nodemcu board. I have purchased the board in this link.
http://www.ebay.in/itm/V3-4M-FLASH-ESP-12-Lua-Nodemcu-WIFI-Dev-Board-Internet-Of-Things-with-ESP8266-/272105661276?ssPageName=ADME:L:OC:IN:3160I have done the program for toggling an led (which is connected to GPIO0). I have connected switch to GPIO5. I have attached a word document of my c program. I tried coding it with ubuntu. The program is working fine for single button press. But when i keep on pressing the button, the program false triggers. eg: If my current state of led is ON. When I go for a long press, it must consider it as single press and it must turn off. But what happens is, It turns off when i press and again turns on when I release the button. Can you please help me in finding the problem.