Commit 2bd06e81 authored by Adrien Oliva's avatar Adrien Oliva
Browse files

Initial import

parents
.pioenvs
.piolibdeps
.clang_complete
.gcc-flags.json
; PlatformIO Project Configuration File
;
; Build options: build flags, source filter
; Upload options: custom upload port, speed and extra flags
; Library options: dependencies, extra library storages
; Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; http://docs.platformio.org/page/projectconf.html
[env:nodemcuv2]
platform = espressif8266
board = nodemcuv2
framework = arduino
#include <Arduino.h>
/******************************************************************************/
/* Pin Definition */
/******************************************************************************/
#define RGB_LED_R (15)
#define RGB_LED_G (12)
#define RGB_LED_B (13)
#define BUTTON_PIN (4)
#define LDR_PIN (0)
/******************************************************************************/
/* Global Variable */
/******************************************************************************/
static uint8_t down = 0;
static uint16_t ldr = 0;
static uint8_t color = 0;
/**************/
/* Setting up */
/**************/
void setup() {
Serial.begin(115200);
Serial.println("Initialization");
pinMode(RGB_LED_R, OUTPUT);
pinMode(RGB_LED_G, OUTPUT);
pinMode(RGB_LED_B, OUTPUT);
pinMode(BUTTON_PIN, INPUT);
pinMode(LDR_PIN, INPUT);
}
/**************************************/
/* Compute next state and show output */
/**************************************/
void next()
{
Serial.printf("Color RGB: #%02x%02x%02x\n",
(color & 0x04) ? 255 : 0,
(color & 0x02) ? 255 : 0,
(color & 0x01) ? 255 : 0);
digitalWrite(RGB_LED_R, (color & 0x04) ? HIGH : LOW);
digitalWrite(RGB_LED_G, (color & 0x02) ? HIGH : LOW);
digitalWrite(RGB_LED_B, (color & 0x01) ? HIGH : LOW);
ldr = analogRead(LDR_PIN);
Serial.printf("Lumens: %d%%\n", ldr * 100 / 1024);
color++;
color %= 0x08;
}
/********************************/
/* Scan user input in main loop */
/********************************/
void loop() {
int button = digitalRead(BUTTON_PIN);
if (down && button) {
Serial.printf("KeyRelease\n");
next();
}
down = (button == 0 ? 1 : 0);
delay(50);
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment