Example 02‐Dimming LED - GSTCH/SketchMadeEASY GitHub Wiki

This document describe a simple example, dimming a LED by potentiometer. If Sketch Made EASY is installed, it can be opened via menu: "File:/Example/SketchMadeEASY/Example/02-DimmingLED".

Schematic

Code

#include <Easy.h>

//*****************************************************************
#define POTI_PIN A0
#define LED_PIN 6

void setup()
{
  //((*** Initialize: Configure your sketch here....
 
  //** Create actuator:
  // A variable output has a range from 0 to 255. It's needs PWM pin.
  Actuator* led = new VariableOutput(LED_PIN);

  //** Create input 
  // In this case we define the input for the actuator into the action.
  // This is an analog pin with a value range of 0...1023.
  Input* poti = new VariableInput(POTI_PIN);

  //** Define logic with conditions and relations
  // Condition NULL means "always true"
  Relation* relation = new Relation1to1(NULL, led, poti);
  // ***))

  // 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);
}
⚠️ **GitHub.com Fallback** ⚠️