#include #ifdef __AVR__ #include // Required for 16 MHz Adafruit Trinket #endif // Which pin on the Arduino is connected to the NeoPixels? #define PIN 32 // On Trinket or Gemma, suggest changing this to 1 // How many NeoPixels are attached to the Arduino? #define NUMPIXELS 2// Popular NeoPixel ring size // When setting up the NeoPixel library, we tell it how many pixels, // and which pin to use to send signals. Note that for older NeoPixel // strips you might need to change the third parameter -- see the // strandtest example for more information on possible values. Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRBW + NEO_KHZ800); #define DELAYVAL 500 // Time (in milliseconds) to pause between pixels // 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() { Serial.begin(115200); // These lines are specifically to support the Adafruit Trinket 5V 16 MHz. // Any other board, you can remove this part (but no harm leaving it): #if defined(__AVR_ATtiny85__) && (F_CPU == 16000000) clock_prescale_set(clock_div_1); #endif pixels.begin(); // INITIALIZE NeoPixel strip object (REQUIRED) // END of Trinket-specific code. //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() ; //original LED_SW = 0; sendMessage(LED_SW); } void loop() { mesh.update(); // BLEScanResults results = scan->start(1); // int best = CUTOFF; // int count = results.getCount(); // for (int i = 0; i < count; i++) { // BLEAdvertisedDevice d = results.getDevice(i); // int rssi = d.getRSSI(); // Serial.println(rssi); // if (rssi > best) { // best = rssi; // } // } // if(best > CUTOFF){ // red = 139; // green = 0; // blue= 0; // leds[0] = CRGB(red, green, blue); // leds[1] = CRGB(red, green, blue); // FastLED.show(); // LED_SW = 1; // flag = 1; // } // else if(flag){ // leds[0] = CRGB(red, green, blue); // leds[1] = CRGB(red, green, blue); // FastLED.setBrightness(BRIGHTNESS/2); // FastLED.show(); // } // else { // leds[0] = CRGB(0, 0, 0); // leds[1] = CRGB(0, 0, 0); // FastLED.show(); // } // sendMessage(LED_SW); // } } 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: pixels.setPixelColor(0, 139, 0, 0, 0); pixels.setPixelColor(1, 139, 0, 0, 0); pixels.show(); LED_SW = 3; sendMessage(LED_SW); break; case 2: // rainbow colors break; case 3: // rainbow colors pixels.setPixelColor(0, 75,0,130, 0); pixels.setPixelColor(1, 75,0,130, 0); pixels.show(); LED_SW = 2; sendMessage(LED_SW); 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 ); }