Added Bigroom Light
This commit is contained in:
5
BigRoom_Light/.gitignore
vendored
Normal file
5
BigRoom_Light/.gitignore
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
.pio
|
||||
.vscode/.browse.c_cpp.db*
|
||||
.vscode/c_cpp_properties.json
|
||||
.vscode/launch.json
|
||||
.vscode/ipch
|
||||
10
BigRoom_Light/.vscode/extensions.json
vendored
Normal file
10
BigRoom_Light/.vscode/extensions.json
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
{
|
||||
// See http://go.microsoft.com/fwlink/?LinkId=827846
|
||||
// for the documentation about the extensions.json format
|
||||
"recommendations": [
|
||||
"platformio.platformio-ide"
|
||||
],
|
||||
"unwantedRecommendations": [
|
||||
"ms-vscode.cpptools-extension-pack"
|
||||
]
|
||||
}
|
||||
8
BigRoom_Light/I2C_Arduino.code-workspace
Normal file
8
BigRoom_Light/I2C_Arduino.code-workspace
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"folders": [
|
||||
{
|
||||
"path": "."
|
||||
}
|
||||
],
|
||||
"settings": {}
|
||||
}
|
||||
39
BigRoom_Light/include/README
Normal file
39
BigRoom_Light/include/README
Normal file
@@ -0,0 +1,39 @@
|
||||
|
||||
This directory is intended for project header files.
|
||||
|
||||
A header file is a file containing C declarations and macro definitions
|
||||
to be shared between several project source files. You request the use of a
|
||||
header file in your project source file (C, C++, etc) located in `src` folder
|
||||
by including it, with the C preprocessing directive `#include'.
|
||||
|
||||
```src/main.c
|
||||
|
||||
#include "header.h"
|
||||
|
||||
int main (void)
|
||||
{
|
||||
...
|
||||
}
|
||||
```
|
||||
|
||||
Including a header file produces the same results as copying the header file
|
||||
into each source file that needs it. Such copying would be time-consuming
|
||||
and error-prone. With a header file, the related declarations appear
|
||||
in only one place. If they need to be changed, they can be changed in one
|
||||
place, and programs that include the header file will automatically use the
|
||||
new version when next recompiled. The header file eliminates the labor of
|
||||
finding and changing all the copies as well as the risk that a failure to
|
||||
find one copy will result in inconsistencies within a program.
|
||||
|
||||
In C, the usual convention is to give header files names that end with `.h'.
|
||||
It is most portable to use only letters, digits, dashes, and underscores in
|
||||
header file names, and at most one dot.
|
||||
|
||||
Read more about using header files in official GCC documentation:
|
||||
|
||||
* Include Syntax
|
||||
* Include Operation
|
||||
* Once-Only Headers
|
||||
* Computed Includes
|
||||
|
||||
https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html
|
||||
46
BigRoom_Light/lib/README
Normal file
46
BigRoom_Light/lib/README
Normal file
@@ -0,0 +1,46 @@
|
||||
|
||||
This directory is intended for project specific (private) libraries.
|
||||
PlatformIO will compile them to static libraries and link into executable file.
|
||||
|
||||
The source code of each library should be placed in a an own separate directory
|
||||
("lib/your_library_name/[here are source files]").
|
||||
|
||||
For example, see a structure of the following two libraries `Foo` and `Bar`:
|
||||
|
||||
|--lib
|
||||
| |
|
||||
| |--Bar
|
||||
| | |--docs
|
||||
| | |--examples
|
||||
| | |--src
|
||||
| | |- Bar.c
|
||||
| | |- Bar.h
|
||||
| | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html
|
||||
| |
|
||||
| |--Foo
|
||||
| | |- Foo.c
|
||||
| | |- Foo.h
|
||||
| |
|
||||
| |- README --> THIS FILE
|
||||
|
|
||||
|- platformio.ini
|
||||
|--src
|
||||
|- main.c
|
||||
|
||||
and a contents of `src/main.c`:
|
||||
```
|
||||
#include <Foo.h>
|
||||
#include <Bar.h>
|
||||
|
||||
int main (void)
|
||||
{
|
||||
...
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
PlatformIO Library Dependency Finder will find automatically dependent
|
||||
libraries scanning project source files.
|
||||
|
||||
More information about PlatformIO Library Dependency Finder
|
||||
- https://docs.platformio.org/page/librarymanager/ldf.html
|
||||
22
BigRoom_Light/platformio.ini
Normal file
22
BigRoom_Light/platformio.ini
Normal file
@@ -0,0 +1,22 @@
|
||||
; 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
|
||||
; https://docs.platformio.org/page/projectconf.html
|
||||
|
||||
[env:pro8MHzatmega328]
|
||||
platform = atmelavr
|
||||
board = pro8MHzatmega328
|
||||
framework = arduino
|
||||
lib_deps =
|
||||
# RECOMMENDED
|
||||
# Accept new functionality in a backwards compatible manner and patches
|
||||
fastled/FastLED @ ^3.5.0
|
||||
powerbroker2/SerialTransfer @ ^3.1.3
|
||||
monitor_speed = 115200
|
||||
monitor_port = COM3
|
||||
upload_port = COM3
|
||||
152
BigRoom_Light/src/main.cpp
Normal file
152
BigRoom_Light/src/main.cpp
Normal file
@@ -0,0 +1,152 @@
|
||||
#include <Arduino.h>
|
||||
#include <FastLED.h>
|
||||
#include <SoftwareSerial.h>
|
||||
#include <SerialTransfer.h>
|
||||
|
||||
#define RELAY_PIN 4
|
||||
#define LED_PIN 9 // the pin which attaches to the neopixel data pin
|
||||
#define COLOR_ORDER RGB // sets the color order in which the LEDs are designed for
|
||||
#define CHIPSET WS2812 // the chipset that the neopixels use
|
||||
#define NUM_LEDS 82 // how many leds are being adderessed
|
||||
|
||||
#define BRIGHTNESS 200 // sets the overall brightness of the leds
|
||||
#define FRAMES_PER_SECOND 60 // how fast should the led animation render
|
||||
#define COOLING 55 // defines the level at which the lighting effect fades before a new "flame" generates
|
||||
#define SPARKING 120 // defines the rate of flicker which we will see from the flame animation
|
||||
|
||||
bool gReverseDirection = true; // set this to true if you need to invert the animation direction
|
||||
|
||||
CRGB leds[NUM_LEDS]; // sets up an array that we can manipulate to set/clear led data.
|
||||
uint8_t ledsB[NUM_LEDS];
|
||||
|
||||
CRGBPalette16 currentPalette; // sets a variable for CRGBPalette16 which allows us to change this value later
|
||||
CRGBPalette16 gPal;
|
||||
|
||||
struct I2cRxStruct {
|
||||
//byte mode;//, hue, saturation, bright;
|
||||
byte mode, r, g, b;
|
||||
//uint32_t RGB;
|
||||
};
|
||||
I2cRxStruct rxData;
|
||||
|
||||
SerialTransfer myTransfer;
|
||||
|
||||
bool newRxData = false;
|
||||
|
||||
// I2C control stuff
|
||||
#include <Wire.h>
|
||||
|
||||
const byte thisAddress = 9; // these need to be swapped for the other Arduino
|
||||
const byte otherAddress = 8;
|
||||
|
||||
//=================================
|
||||
void showNewData();
|
||||
void receiveEvent(int numBytesReceived);
|
||||
|
||||
const byte rxPin = 3;
|
||||
const byte txPin = 2;
|
||||
SoftwareSerial lampSerial(rxPin, txPin);
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
Serial.println("\nStarting I2C Slave demo\n");
|
||||
pinMode(RELAY_PIN, OUTPUT);
|
||||
digitalWrite(RELAY_PIN, HIGH);
|
||||
pinMode(LED_BUILTIN, OUTPUT);
|
||||
//pinMode(LED_PIN, OUTPUT);
|
||||
|
||||
lampSerial.begin(19200);
|
||||
myTransfer.begin(lampSerial);
|
||||
FastLED.addLeds<CHIPSET, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS);//.setCorrection( TypicalLEDStrip );
|
||||
//FastLED.addLeds<CHIPSET, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS);
|
||||
// FastLED.setBrightness( BRIGHTNESS ); // sets the brightness to the predetermined levels
|
||||
// for(int i = 0; i < NUM_LEDS; i++){
|
||||
// leds[i] = CRGB(16, 16, 16);
|
||||
// ledsB[i] = 100;
|
||||
// }
|
||||
// FastLED.show();
|
||||
}
|
||||
|
||||
void loop() {
|
||||
static uint32_t cRun = millis();
|
||||
static bool powerOn = false;
|
||||
uint8_t rn;
|
||||
// if(cRun + 1000 < millis()){
|
||||
// digitalWrite(LED_PIN, !digitalRead(LED_PIN));
|
||||
// cRun = millis();
|
||||
|
||||
// }
|
||||
// return;
|
||||
if(myTransfer.available()){
|
||||
uint16_t recSize = 0;
|
||||
recSize = myTransfer.rxObj(rxData, recSize);
|
||||
Serial.print(rxData.mode);
|
||||
Serial.print("-");
|
||||
Serial.print(rxData.r, 16);
|
||||
Serial.print("-");
|
||||
Serial.print(rxData.g, 16);
|
||||
Serial.print("-");
|
||||
Serial.println(rxData.b, 16);
|
||||
newRxData = true;
|
||||
}
|
||||
|
||||
random16_add_entropy(random());
|
||||
//randomSeed(analogRead(A1));
|
||||
// // this bit checks if a message has been received
|
||||
if (newRxData == true) {
|
||||
if(rxData.mode > 0){
|
||||
if(!digitalRead(RELAY_PIN)){
|
||||
digitalWrite(RELAY_PIN, LOW);
|
||||
digitalWrite(LED_BUILTIN, HIGH);
|
||||
Serial.println("Power ON");
|
||||
cRun = millis();
|
||||
}
|
||||
}
|
||||
else{
|
||||
if(digitalRead(RELAY_PIN)){
|
||||
digitalWrite(RELAY_PIN, HIGH);
|
||||
digitalWrite(LED_BUILTIN, LOW);
|
||||
Serial.println("Power OFF");
|
||||
powerOn = false;
|
||||
}
|
||||
}
|
||||
if(cRun + 500 < millis()){
|
||||
if (rxData.mode != 2) showNewData();
|
||||
Serial.println("Show LED");
|
||||
powerOn = true;
|
||||
newRxData = false;
|
||||
//cRun = millis();
|
||||
}
|
||||
}
|
||||
if((rxData.mode == 2) && powerOn){
|
||||
if(cRun + 100 < (millis())){
|
||||
cRun = millis();
|
||||
for(int i = 0; i < NUM_LEDS; i++){
|
||||
rn = random8(100);
|
||||
ledsB[i] += int((rn - ledsB[i]) / 3.0);
|
||||
leds[i] = CRGB(int(2.55 * ledsB[i]), int(0.5 * ledsB[i]), 0);
|
||||
//CHSV(HUE_ORANGE, 100, uint8_t(ledsB[i]));//
|
||||
}
|
||||
FastLED.show(); // display this frame
|
||||
}
|
||||
}
|
||||
// if(cRun + 1000 < millis()){
|
||||
// digitalWrite(RELAY_PIN, !digitalRead(RELAY_PIN));Serial.println(digitalRead(RELAY_PIN));
|
||||
// cRun = millis();
|
||||
// }
|
||||
}
|
||||
|
||||
void showNewData() {
|
||||
for(int i = 0; i < NUM_LEDS; i++){
|
||||
//leds[i].setRGB(rxData.RGB >> 16, rxData.RGB << 16 >> 24, rxData.RGB << 24 >> 24);
|
||||
// Serial.print("Led "); Serial.print(i);
|
||||
// Serial.print("\tR:"); Serial.print(rxData.r, 16);
|
||||
// Serial.print(" G:"); Serial.print(rxData.g, 16);
|
||||
// Serial.print(" B:"); Serial.println(rxData.b, 16);
|
||||
leds[i].setRGB(rxData.r, rxData.g, rxData.b);
|
||||
//leds[i].setHSV(rxData.hue, rxData.saturation, rxData.bright);
|
||||
}
|
||||
FastLED.setBrightness(255);
|
||||
FastLED.show(); // display this frame
|
||||
}
|
||||
|
||||
11
BigRoom_Light/test/README
Normal file
11
BigRoom_Light/test/README
Normal file
@@ -0,0 +1,11 @@
|
||||
|
||||
This directory is intended for PlatformIO Test Runner and project tests.
|
||||
|
||||
Unit Testing is a software testing method by which individual units of
|
||||
source code, sets of one or more MCU program modules together with associated
|
||||
control data, usage procedures, and operating procedures, are tested to
|
||||
determine whether they are fit for use. Unit testing finds problems early
|
||||
in the development cycle.
|
||||
|
||||
More information about PlatformIO Unit Testing:
|
||||
- https://docs.platformio.org/en/latest/advanced/unit-testing/index.html
|
||||
@@ -13,8 +13,8 @@
|
||||
|
||||
#define WIFI_SSID "wf-home"
|
||||
#define WIFI_PASSWORD "0ndthnrf"
|
||||
#define WIFI_SSID2 "BR"
|
||||
#define WIFI_PASSWORD2 "499727479o"
|
||||
//#define WIFI_SSID2 "BR"
|
||||
//#define WIFI_PASSWORD2 "499727479o"
|
||||
#define MQTT_SERV "192.168.1.111"
|
||||
#define TOPIC "home/kor/"
|
||||
|
||||
@@ -66,10 +66,10 @@ void setup()
|
||||
{
|
||||
Serial.begin(9600);
|
||||
WiFi.mode(WIFI_STA);
|
||||
WiFi.persistent(false);
|
||||
//WiFi.persistent(false);
|
||||
WiFi.hostname(HOSTNAME);
|
||||
wifiMulti.addAP(WIFI_SSID, WIFI_PASSWORD);
|
||||
wifiMulti.addAP(WIFI_SSID2, WIFI_PASSWORD2);
|
||||
//wifiMulti.addAP(WIFI_SSID, WIFI_PASSWORD);
|
||||
//wifiMulti.addAP(WIFI_SSID2, WIFI_PASSWORD2);
|
||||
ArduinoOTA.onStart([]() {
|
||||
Serial.println("ArduinoOTA start");
|
||||
});
|
||||
@@ -249,8 +249,8 @@ void loop()
|
||||
|
||||
void connectToWifi() {
|
||||
Serial.println("Connecting to Wi-Fi...");
|
||||
wifiMulti.run();
|
||||
//WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
|
||||
//wifiMulti.run();
|
||||
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
|
||||
}
|
||||
|
||||
void connectToMqtt() {
|
||||
|
||||
Reference in New Issue
Block a user