Example 21‐Alternate blink - GSTCH/SketchMadeEASY GitHub Wiki

A DigitalOutout/LED knows the value on and off. The other DigitalOutout/LED does the same but inverted. If Sketch Made EASY is installed, it can be opened via menu: "File:/Example/SketchMadeEASY/Examples/21-ElseCondition".

Schematic

Code

#include <Easy.h>

//*****************************************************************
// Parameter switch
#define LED1_PIN 6
#define LED2_PIN 38
#define TIMER_INTERVAL_MSEC 1500

void setup()
{
  //((*** Initialize: Configure your sketch here....
  //** Create actuators
  Actuator* led1 = new DigitalOutput(LED1_PIN);
  Actuator* led2 = new DigitalOutput(LED2_PIN);

  //** Create input.
  Input* timer = new Timer(TIMER_INTERVAL_MSEC, true);

  //** Define logic with condition and relation
  // Condition when Timer is high 
  Condition* conditionLed1On = new CompareCondition(timer, OpEQ, Timer::High);  
  Relation* relationLed1On = new Relation1to1(conditionLed1On, led1, FixValue::On());

  // Same for second actuator but inverted
  Condition* conditionLed2On = new ElseCondition(conditionLed1On);
  Relation* relationLed2On = new Relation1to1(conditionLed2On, led2, FixValue::On());

  // Condition when Timer is low
  Condition* conditionLed1Off = new CompareCondition(timer, OpEQ, Timer::Low);
  Relation* relationLed1Off = new Relation1to1(conditionLed1Off, led1, FixValue::Off());

  // Same for second actuator but inverteds
  Condition* conditionLed2Off = new ElseCondition(conditionLed1Off);
  Relation* relationLed2Off = new Relation1to1(conditionLed2Off, led2, FixValue::Off());
// ***))

  // Initialize control
  ControlManagerFactory::GetControlManager()->Setup();
}

//*****************************************************************
void loop() {
  //*** Run: No additional code is required
  ControlManagerFactory::GetControlManager()->Loop();

  delay(5);
}
⚠️ **GitHub.com Fallback** ⚠️