D TeamDionysios Satikidis
Published © GPL3+

LEA - Light Environment Automation

With Lea you can automate the lights according to the brightness of the environment.

IntermediateWork in progress5 hours1,690
LEA - Light Environment Automation

Things used in this project

Hardware components

Photon
Particle Photon
×1
Breadboard (generic)
Breadboard (generic)
×1
NeoPixel Ring - 12 x 5050 RGB LED Adafruit 1643
×1
SparkFun mini potocell SEN-09088
×1
SparkFun Button
×1
LED (generic)
LED (generic)
×1
Resistor 10k ohm
Resistor 10k ohm
Used for photocell
×1

Story

Read more

Code

lea.ino

C/C++
implemented state machine
/*
 *  This file is a sample application, based
 *  on the IoT Prototyping Framework (IoTPF)

    This application and IoTPF is free software: you can redistribute it     and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    IoTPF is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU v3 General Public License for more details.

    Released under GNU v3

    You should have received a copy of the GNU General Public License
    along with IoTPF.  If not, see <http://www.gnu.org/licenses/>.
 */
 
 /**
    Internet of Things Prototyping Framework IoTPF  
    @Version 1.0
    @author Dionysios Satikidis
    
    LEA 2017/2018
    @version 1.0
    @author Matthias Geckeler and Felix Grammling
*/

#include "Button_Connection.h"
#include "Time_Connection.h"
#include "Light_Connection.h"
#include "LED_Connection.h"
#include "NeoPixelRing_Connection.h"

Time_Connection tc;
Light_Connection lc;
LED_Connection ledc;
NeoPixelRing_Connection nc;
Button_Connection bc;

typedef enum STATE{START, ONLINE, OFFLINE, ENABLED_MODE, AUTOMATIC_MODE, DISABLED_MODE, IN_TIME, NOT_IN_TIME, DARK, BRIGHT} STATE_TYPE;

STATE_TYPE actState = START;
STATE_TYPE nextState = START;

void setup() {
    tc.init();
    lc.init();
    ledc.init();
    nc.init();
    bc.init();
}

void loop() {

    switch(actState) {
        case START: 
            if (Particle.connected()) {
                nextState = ONLINE;
            }
            else {
                nextState = OFFLINE;
            }
            break;
            
        case OFFLINE: 
            ledc.turnGreenOff();
            ledc.turnRedOn();
            nextState = START;
            break;
            
        case ONLINE: 
            ledc.turnRedOff();
            ledc.turnGreenOn();
            bc.handleMode();
            if (bc.isEnabledMode()) {
                nextState = ENABLED_MODE;
            }
            if (bc.isAutomaticMode()) {
                nextState = AUTOMATIC_MODE;
            }
            if (bc.isDisabledMode()) {
                nextState = DISABLED_MODE;
            }
            break;
           
        case ENABLED_MODE:
            ledc.turnBlueOff();
            ledc.turnWhiteOn();
            nc.showAllPixels();
            nextState = START;
            break;
            
        case DISABLED_MODE:
            ledc.turnBlueOn();
            ledc.turnWhiteOff();
            nc.hideAllPixels();
            nextState = START;
            break;
        
        case AUTOMATIC_MODE:
            ledc.turnBlueOff();
            ledc.turnWhiteOff();
            if (tc.isInTime()) {
                nextState = IN_TIME;
            }
            else {
                nextState = NOT_IN_TIME;
            }
            break;
         
        case NOT_IN_TIME: 
            nc.hideAllPixels();
            nextState = START;
            break; 
            
        case IN_TIME: 
            if (lc.isBright()) {
                nextState = BRIGHT;
            }
            else {
                nextState = DARK;
            }
            break;
        
        case DARK: 
            nc.showAllPixels();
            nextState=START;
            break;
            
        case BRIGHT: 
            nc.hideAllPixels();
            nextState=START;
            break;
        
        default:
            nextState=START;
    }
    
    actState = nextState;

    delay(100);
}

Credits

D Team

D Team

2 projects • 1 follower
Dionysios Satikidis

Dionysios Satikidis

17 projects • 32 followers
Dev. Experience Platforms Guy at Mercedes-Benz Lecturer IoT Ecosystems & Applied AI at Brunel Univ. and Univ. of Applied Sciences Esslingen.
Thanks to Dionysios Satikidis.

Comments