Black Lives Matter - Action and Equality. ... Adafruit is open and shipping.
0

ESP8266 - two buttons - one example
Moderators: adafruit_support_bill, adafruit

Forum rules
If you're posting code, please make sure your code does not include your Adafruit IO Active Key or WiFi network credentials.
Please be positive and constructive with your questions and comments.

Re: ESP8266 - two buttons - one example

by HENRIO_IO on Thu Aug 18, 2016 7:44 am

Please I just created an account with Adafruit.com. And I couldn't see any button to press for my AIO Key generation.
Iam HENRIO_IO

HENRIO_IO
 
Posts: 3
Joined: Thu Aug 18, 2016 6:56 am

Re: ESP8266 - two buttons - one example

by sadams260 on Thu Aug 18, 2016 8:13 am

are you at io.adafruit.com ?

sadams260
 
Posts: 16
Joined: Thu Jun 23, 2016 9:04 pm

Re: ESP8266 - two buttons - one example

by HENRIO_IO on Fri Aug 19, 2016 3:49 am

yes I am
please help

HENRIO_IO
 
Posts: 3
Joined: Thu Aug 18, 2016 6:56 am

Re: ESP8266 - two buttons - one example

by HENRIO_IO on Fri Aug 19, 2016 3:59 am

Thanks Sadams260. It worked

HENRIO_IO
 
Posts: 3
Joined: Thu Aug 18, 2016 6:56 am

Re: ESP8266 - two buttons - one example

by flyboy1015 on Fri Mar 24, 2017 9:29 am

For anyone who may want to use millis() to create a delay without stopping the processor with a delay() command, I'd recommend adjusting the routine suggested by smcculley. I've run this several times and scratched my head for a while until it finally clicked. He provided the code below.

Code: Select all | TOGGLE FULL SIZE
 // get current time stamp
  cts = millis();
  // if enough time has passed, read the AIO status
  if (cts - 10000 > lats) {
    readAio();
    // set last timestamp to current
    lats = cts;
  }


I'd recommend making a small, but important change. When the program starts, cts and lats should be 0. It's always best to set those values in your declaration, just to be sure. When cts, which you set equal to millis() in the previous line of code, is 0, or less than 10000 and you subtract 10000, you have rolled over backwards. This means that the if() statement is now true, so it runs the routine readAio() every time it reaches this statement until you roll over at 0. That means that this routine, readAio() will run continuously for the first 10 seconds (10000 milliseconds) of your program. If you watch your dashboard, you'll see values populating every couple of seconds==bad, possibly banned after enough time.

So here is my recommendation. Switch places between the value you want to wait for and the lats variable. See below.

Code: Select all | TOGGLE FULL SIZE
 // get current time stamp
  cts = millis();
  // if enough time has passed, read the AIO status
  if (cts - lats > 10000) {
    readAio();
    // set last timestamp to current
    lats = cts;
  }


At the beginning of the code, both values, cts and lats are both 0, so the routine does not call readAio() until 10000 milliseconds has passed. My understanding of what happens after the rollover is that the unsigned long values will take care of themselves, so that cts-lats will still result in the desired value. I'm still researching this as it hasn't really clicked in my brain yet.

I hope this helps.

flyboy1015
 
Posts: 5
Joined: Thu Dec 29, 2016 8:44 pm

Please be positive and constructive with your questions and comments.