/*
*	BlinkWithNoDelay_Function
*
*	This is an example of how to blink an LED using the NoDelay library by calling a function
*	This allows you to execute code without the use of the delay() function
*	and without having to setup many variables for each time you want to
*	run code in a delay less manner
*	Written by Mario Avenoso of Mtech Creations
*	Based off of the Blink Without Delay example http://www.arduino.cc/en/Tutorial/BlinkWithoutDelay
*	7/10/15

*/

#include<NoDelay.h>

void redBlink();//Must declare function before noDelay, function can not take arguments
void greenBlink();//Must declare function before noDelay, function can not take arguments

noDelay redtime(1000, redBlink);//Creats a noDelay varible set to 1000ms, will call ledBlink function
noDelay greentime(700, greenBlink);//Creats a noDelay varible set to 1000ms, will call ledBlink function
int redpin = 9;
int redState = LOW;
int greenpin = 8;
int greenState = LOW;

void setup() {
  pinMode(redpin, OUTPUT);
  pinMode(greenpin, OUTPUT);
}

void loop() {
    redtime.update();//will check if set time has past and if so will run set function
    greentime.update();//will check if set time has past and if so will run set function
}

void redBlink()
{
	// if the LED is off turn it on and vice-versa:
    if (redState == LOW)
      redState = HIGH;
    else
      redState = LOW;

    // set the LED with the redState of the variable:
    digitalWrite(redpin, redState);
    redtime.setdelay(random(1000));
}



void greenBlink()
{
	// if the LED is off turn it on and vice-versa:
    if (greenState == LOW)
      greenState = HIGH;
    else
      greenState = LOW;

    // set the LED with the redState of the variable:
    digitalWrite(greenpin, greenState);
    greentime.setdelay(random(1000));
}