NAzT
7/20/2017 - 7:18 AM

button2.ino

button2.ino

#include <Arduino.h>

// Pin 13 has an LED connected on most Arduino boards.
#define LedPin 2 // BUILTIN_LED
#define AButtonPin 13
#define BButtonPin 0

// include libraries
#include <Task.h>

// include sub files
#include "ButtonTask.h" // this implements the button task
uint8_t BButtonCount = 0;
TaskManager taskManager;

ButtonTask BButtonTask([](ButtonState state) {
  Serial.println("B Button Task");
  if (state == ButtonState_Released)
  {
    digitalWrite(4, LOW);   // turn the LED off (LOW is the voltage level)
  }
}, BButtonPin);

ButtonTask AButtonTask([](ButtonState state) {
  Serial.println("A Button Task");
  if (state == ButtonState_Released)
  {
    int pin5State = digitalRead(5);
    digitalWrite(5, !pin5State);
  }
}, AButtonPin);



void setup()
{
  Serial.begin(115200);
  pinMode(LedPin, OUTPUT);

  pinMode(5, OUTPUT);
  pinMode(4, OUTPUT);

  digitalWrite(5, HIGH);
  digitalWrite(4, HIGH);

  taskManager.StartTask(&BButtonTask);
  taskManager.StartTask(&AButtonTask);

  Serial.println();
  Serial.println("Running...");
}

void loop()
{
  taskManager.Loop();
}