#include #include #include #include #define photo_tra 34 #define LED_PIN 32 #define NUM_LEDS 2 #define BRIGHTNESS 10 const int CUTOFF = -52; int flag = 0; CRGB leds[NUM_LEDS]; #define BRIGHTNESS 10 BLEScan *scan; int red = 139, green = 0, blue = 0; //int red = 139; //int green = 0; //int blue = 0; //#define BEACON_UUID "54fe3d7c-bd21-11ea-b3de-0242ac130004" // Mesh Setup #include "painlessMesh.h" // set these to whatever you like - don't use your home info - this is a separate private network #define MESH_SSID "whateverYouLike" #define MESH_PASSWORD "somethingSneaky" #define MESH_PORT 5555 int LED_SW; // Forward declare functions - for PlatformIO compatability // this gets called when the designated controller sends a command to start a new animation // init any animation specific vars for the new mode, and reset the timer vars void receivedCallback( uint32_t from, String &msg ); void newConnectionCallback(uint32_t nodeId); // this gets called when a node is added or removed from the mesh, so set the controller to the node with the lowest chip id void changedConnectionCallback(); void nodeTimeAdjustedCallback(int32_t offset); // sort the given list of nodes void sortNodeList(SimpleList &nodes); // check the timer and do one animation step if needed void stepAnimation(); // send a broadcast message to all the nodes specifying the new animation mode for all of them void sendMessage(int LED_SW); painlessMesh mesh; void setup() { pinMode(photo_tra,INPUT); BLEDevice::init(""); FastLED.addLeds(leds, NUM_LEDS); scan = BLEDevice::getScan(); // スキャンオブジェクトを取得 scan->setActiveScan(true); // パッシブスキャンに設定 FastLED.setBrightness(BRIGHTNESS); //painlessMESH //mesh.setDebugMsgTypes( ERROR | MESH_STATUS | CONNECTION | SYNC | COMMUNICATION | GENERAL | MSG_TYPES | REMOTE ); // all types on mesh.setDebugMsgTypes( ERROR | STARTUP ); // set before init() so that you can see startup messages mesh.init( MESH_SSID, MESH_PASSWORD, MESH_PORT ); mesh.onReceive(&receivedCallback); mesh.onNewConnection(&newConnectionCallback); mesh.onChangedConnections(&changedConnectionCallback); mesh.onNodeTimeAdjusted(&nodeTimeAdjustedCallback); //mesh.scheduler.addTask( taskSendMessage ); //taskSendMessage.enable(); Serial.begin(115200); //original LED_SW = 0; sendMessage(LED_SW); } double amb; void loop() { mesh.update(); amb = analogRead(photo_tra); Serial.println(amb); if(amb < 10){ LED_SW = 1; sendMessage(LED_SW); } else { LED_SW = 3; sendMessage(LED_SW); } delay(200); } void receivedCallback( uint32_t from, String &msg ) { Serial.printf("Setting display mode to %s. Received from %u\n", msg.c_str(), from); LED_SW = msg.toInt(); switch (LED_SW) { case 1: break; case 2: // rainbow colors leds[0] = CRGB(red, green, blue); leds[1] = CRGB(red, green, blue); FastLED.setBrightness(BRIGHTNESS/2); FastLED.show(); break; case 3: // rainbow colors leds[0] = CRGB(0, 0, 0); leds[1] = CRGB(0, 0, 0); FastLED.show(); break; default: break; } } void newConnectionCallback(uint32_t nodeId) { Serial.printf("--> startHere: New Connection, nodeId = %u\n", nodeId); } // newConnectionCallback void changedConnectionCallback() { Serial.printf("Changed connections\n"); } void nodeTimeAdjustedCallback(int32_t offset) { Serial.printf("Adjusted time %u. Offset = %d\n", mesh.getNodeTime(),offset); } void sendMessage(int LED_SW) { String msg; //msg += mesh.getNodeId(); msg += String(LED_SW); mesh.sendBroadcast( msg ); }