// Adafruit IO Digital Output Example // Tutorial Link: https://learn.adafruit.com/adafruit-io-basics-digital-output // // Adafruit invests time and resources providing this open source code. // Please support Adafruit and open source hardware by purchasing // products from Adafruit! // // Written by Todd Treece for Adafruit Industries // Copyright (c) 2016 Adafruit Industries // Licensed under the MIT license. // // All text above must be included in any redistribution. // // FABACADEMY2020 groupwork modifications for this Adafruit IO digiout example: // -- added software serial for communicating with attiny412 and removed default serial support // -- added secondary Adafruit IO channel for controlling attiny412 // -- added serial communication wit attiny142 to second adafruit IO channel // Group: Jari, Hannu, Achille and Anssi /********* Configuration ************/ // edit the config.h tab and enter your Adafruit IO credentials // and any additional configuration needed for WiFi, cellular, // or ethernet clients. #include "config.h" #include //Included SoftwareSerial Library /******** Example Starts Here ***********/ // digital pin 4 on ESP8266 #define LED_PIN 4 // let's define software serial SoftwareSerial Serialm(3,1); // set up the 'digital' feed (button ESP in Adafruit IO UX) AdafruitIO_Feed *digital = io.feed("digital"); //set up the 'digital2' feed (button attiny142 in Adafruit IO UX) AdafruitIO_Feed *digital2 = io.feed("digital2"); void setup() { // GPIO pin is defined to be output pinMode(LED_PIN, OUTPUT); // start the software serial connection Serialm.begin(9600); // connect to io.adafruit.com Serialm.print("Connecting to Adafruit IO"); io.connect(); // set up a message handler for the 'digital' and 'digital2' feeds. // handleMessage and handlemessage2 functions (defined below) // will be called whenever a message is // received from adafruit io. digital->onMessage(handleMessage); digital2->onMessage(handleMessage2); // wait for a connection while(io.status() < AIO_CONNECTED) { Serialm.print("."); delay(500); } // we are connected Serialm.println(); Serialm.println(io.statusText()); // Adafruit IO feeds are refreshed digital->get(); digital2->get(); } void loop() { // io.run(); is required for all sketches. // it should always be present at the top of your loop // function. it keeps the client connected to // io.adafruit.com, and processes any incoming data. io.run(); } // this function is called whenever an 'digital' feed message // is received from Adafruit IO. it was attached to // the 'digital' feed in the setup() function above. void handleMessage(AdafruitIO_Data *data) { Serialm.print("ESP received <- "); if(data->toPinLevel() == HIGH) Serialm.println("HIGH"); else Serialm.println("LOW"); digitalWrite(LED_PIN, data->toPinLevel()); } // this function is called whenever an 'digital2' feed message // is received from Adafruit IO. it was attached to // the 'digital' feed in the setup() function above. void handleMessage2(AdafruitIO_Data *data) { Serialm.print("Attiny412 received <- "); if(data->toPinLevel() == HIGH){ Serialm.println("HIGH2"); // let's send 2 via serial connection to attiny412. Thiss will lit put LED on attiny412 to HIGH Serialm.write("2"); } else { Serialm.println("LOW2");; // let's send 0 via serial connection to attiny412. This will put led on attinyt412 to LOW Serialm.write("0"); } }