Example 01 ‐ Switch and LED - GSTCH/SketchMadeEASY GitHub Wiki
This document describe a simple example, turning a LED on and off by switch. To not use any resistors, the input is set to PullDownInternal. This is the default value as well. If Sketch Made EASY is installed, it can be opened via menu: "File:/Example/SketchMadeEASY/Example/01-SwitchAndLamp".

#include <Easy.h>
#define SWITCH_PIN 39
#define LED_PIN 6
void setup() {
//*** Configure your sketch here...
//((----------------- Initialize:
//---- Create input:
// A switch with two positions knows the value On and Off.
Switch2Position* switchOnOff = new Switch2Position(SWITCH_PIN);
//---- Create actuator:
// A DigitalOutput knows the value On and Off.
DigitalOutput* led = new DigitalOutput(LED_PIN);
//---- Define logic with conditions and relations
// Define relation when switch is on
CompareCondition* conditionSwitchOn = new CompareCondition(switchOnOff, OpEQ, Switch2Position::On);
Relation1to1* switchOnRelation = new Relation1to1(conditionSwitchOn, led, FixValue::On());
// Define relation when switch is off
CompareCondition* conditionSwitchOff = new CompareCondition(switchOnOff, OpEQ, Switch2Position::Off);
Relation1to1* switchOffRelation = new Relation1to1(conditionSwitchOff, led, FixValue::Off());
//-----------------))
// Initialize control
ControlManagerFactory::GetControlManager()->Setup();
}
void loop() {
// Run: No additional code is required
ControlManagerFactory::GetControlManager()->Loop();
// Depending on Arduino it needs a short delay. Do not add any other delays!
delay(5);
}