NAzT
5/28/2015 - 4:03 AM

esp8266.arduino.ticker.ino

esp8266.arduino.ticker.ino

/*
  Passing paramters to Ticker callbacks
  
  Apart from void(void) functions, the Ticker library supports 
  functions taking one argument. This argument's size has to be less or
  equal to 4 bytes (so char, short, int, float, void*, char* types will do).
  
  This sample runs two tickers that both call one callback function,
  but with different arguments.

  An LED connected to GPIO1 will be pulsing. Use a built-in LED on ESP-01
  or connect an external one to TXD on other boards.
*/

#include <Ticker.h>

Ticker tickerSetHigh;
Ticker tickerSetLow;

void setPin(int state) {
//  digitalWrite(1, state);
 char buff[10];
 sprintf(buff, "%lu -> %d", millis(), state);
 Serial.println(buff);
}

void setup() {
  Serial.begin(115200);
  delay(50);
  Serial.println("GOGOGO"); 
  delay(500);
  // every 337 ms, call setPin(0) 
  tickerSetLow.attach_ms(337, setPin, 0);
 
  // every 771 ms, call setPin(1)
  tickerSetHigh.attach_ms(771, setPin, 1);
}

void loop() {
}