-->
Page 1 of 1

Wifi Push Button State

PostPosted: Sun Aug 09, 2015 7:12 am
by xpbr
Hi everyone,

I am trying to program my own little version of a LED dimmer.Currently I am dimming an LED up and down as long as a hardware button connected to the UNO is pressed. It keeps the brightness of the LED at the exact brightness that it has when the button is released. I'm happy with the code but would like to use it on an ESP-12 and replace the hardware button with an web or app based button. The regular wifi led example unfortunately only sends a ON or OFF command but doesn't register if the button is currently pressed or released.

Can someone give me a hint what to look for or what to implement for making this brightness selection process wifi capable?

Thank you!

Code: Select all#include "cie1931.h"

int fadeAmount = 1;    // how many points to fade the LED by
int onPercent = 0;     // variable for percentage display
byte i = 0;            // variable for led brightness corrected

int led = 3;              // the pin that the LED is attached to
int const buttonPin = 2;  // the pin that the button is attached to


void setup() {

  pinMode(led, OUTPUT);       // setup the ledPin
  pinMode(buttonPin, INPUT);  // setup the buttonPin
 
}

void loop() {
 
  //if button is pressed run fade function
  if (digitalRead(buttonPin) == HIGH) {
    fade ();
  }


void fade () {
  analogWrite(led, cie[i]);

  // change the brightness for next time through the loop:
  i = i + fadeAmount;

  // reverse the direction of the fading at the ends of the fade:
  if (i == 0 || i == 255) {
    delay(2000);                                    //wait 2 seconds in full on and off state
    fadeAmount = -fadeAmount ;
  }
  // wait for 30 milliseconds to see the dimming effect
  delay(10);
}