-
Notifications
You must be signed in to change notification settings - Fork 0
Example 01 ‐ Switch and Lamp
Hans Rothenbuehler edited this page Apr 3, 2025
·
6 revisions
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.
Input* switchOnOff = new Switch2Position(SWITCH_PIN);
//---- Create actuator:
// A DigitalOutput knows the value On and Off.
Actuator* led = new DigitalOutput(LED_PIN);
//---- Define logic with conditions and relations
// Define relation when switch is on
Condition* conditionSwitchOn = new CompareCondition(switchOnOff, OpEQ, Switch2Position::On);
Relation* switchOnRelation = new Relation1to1(conditionSwitchOn, led, FixValue::On());
// Define relation when switch is off
Condition* conditionSwitchOff = new CompareCondition(switchOnOff, OpEQ, Switch2Position::Off);
Relation* 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);
} Wiki
Getting started
Classes
Input
- Calculate
- ConditionInput
- DependentInput
- DigitalInput
- FixValue
- Inverter
- IteratorValue
- JoystickAxis
- LoopSwitch
- MonoFlop
- Switch2Position
- Switch3Position
- Timer
- ToggleSwitch
- UltrasonicRangefinder
- VariableInput
Actuator
- ActuatorCollection
- Buzzer
- DigitalOutput
- EncoderMotorI2C
- EncoderMotorL298
- EncoderMotorL9110
- MotorI2C
- MotorL298
- MotorL9110
- MotorStepperRotate
- MotorStepperRotateI2C
- Servo360I2C
- Servo360PWM
- Servo360T1
- Servo360T2
- ServoPWM
- ServoStepperPosition
- ServoStepperPositionI2C
- ServoI2C
- ServoT1
- ServoT2
- VariableOutput
Condition
Relation
RemoteControl
Common
Sketches
Templates
Examples
- 01-Switch and Lamp
- 02-Dimming LED
- 03-Dimming LED with Switch
- 04-Blinking LED
- 05‐Motor fix speed, direction‐switch
- 06‐Motor variable speed, direction‐switch
- 07‐Motor variable speed, direction‐ and main‐switch
- 08‐Motor toggles between limit switches
- 09‐Motor toggles between limit switches, main switch
- 10‐Main Motor turns between limit switches, second follows
- 11-Two motors, one turns after the other
- 12-Servo360 controlled by a Joystick
- 13-Stepper motor with variable speed
- 14-RemoteControl of a motor with FlySky FS-i6X
- 15-RemoteControl of a motor with an App
- 16-EncoderMotor and LED controlled by FlySky-RemoteControl
- 17-Servo position in relation to a potentiometer
- 18-Stepper angle controlled by joystick
- 19-Buzzer tone in relation to distance
- 20-Dependent input
- 21-Alternate blink