Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Timers.h> // my favorite timer
- Timers <4> akcja; // 4 wątki
- #define led_green 7
- #define led_red 8 // na D8
- //>>>>>>>>>>>>>>>>>>> my Programs
- void Program_vPin0(String strvPin) { // blink led from ESP timer
- digitalWrite(led_red, intfromstr(strvPin));
- }
- //etc ...
- void Program_vPin29(String strvPin) {
- }
- //from APP to NANO >>>>>>>>>>>>>>>>
- // equivalent BLYNK_WRITE(VPin)
- void Blynkwrite(String str2) {
- String istr = str2.substring(1, str2.indexOf(':')); // nr vPin
- byte pin2 = istr.toInt();
- String strdata2 = str2.substring(str2.indexOf(':') + 1); // if nr vPin typ int
- int data2 = strdata2.toInt();
- if (str2.charAt(0) == 'V') {
- switch (pin2 + 1) { // Switch to progrma for recived vPin
- case 1: Program_vPin0(strdata2); break;
- // etc....
- case 30: Program_vPin29(strdata2); break;
- default: ;
- }
- }
- }
- // equivalent Blynk.virtualWrite(VPin, Data);
- void BlynkvirtualWrite_str (byte vPin, String z) { // send str to APP
- String str1 = 'S' + String(vPin) + ':' + z;
- sendstrtoserial(str1);
- }
- void BlynkvirtualWrite_int (byte vPin, int z) { // send int to APP
- String str1 = 'I' + String(vPin) + ':' + String(z);
- sendstrtoserial(str1);
- }
- void BlynkvirtualWrite_led(byte vPin, byte Value) { // send LEDs data to APP
- String str1 = 'L' + String(vPin) + ':' + String(Value);
- sendstrtoserial(str1);
- }
- void BlynkvirtualWrite_col(byte vPin, String col) { // send color data to APP
- String str1 = 'C' + String(vPin) + ':' + col;
- sendstrtoserial(str1);
- }
- void BlynkvirtualWrite_On(byte vPin, String ON) { // send onLabel data to APP
- String str1 = 'N' + String(vPin) + ':' + ON;
- sendstrtoserial(str1);
- }
- void BlynkvirtualWrite_Off(byte vPin, String OFF) { // send offLabel data to APP
- String str1 = 'F' + String(vPin) + ':' + OFF;
- sendstrtoserial(str1);
- }
- int intfromstr(String str) {
- String strdata3 = str.substring(str.indexOf(':') + 1); // if nr vPin typ int
- return strdata3.toInt();
- }
- // ....................................... recive string from serial
- bool stringComplete = false;
- String inputString = "";
- byte licznikodbioru = 0;
- int startrecive = 0;
- void recivestrfromserial () {
- if (stringComplete) {
- Serial.println("od " + String(inputString)); //test
- Blynkwrite(inputString);
- inputString = "";
- stringComplete = false;
- licznikodbioru = 0;
- startrecive = 0;
- }
- }
- void serialEvent() { //odbiór string z Serial
- if (Serial.available()) {
- licznikodbioru++;
- char inChar = (char)Serial.read();
- if (startrecive == 0) {
- if ((inChar == 'V')) startrecive = 1;
- }
- if (startrecive == 1) {
- if (inChar == '\r') {
- stringComplete = true;
- inChar = '\0';
- inputString += inChar;
- startrecive = 0;
- } else inputString += inChar;
- }
- if (licznikodbioru > 50) inputString = "";
- }
- }
- // ................................. send string to serial
- void sendstrtoserial (String toserial) {
- Serial.println(toserial);
- }
- void setup()
- {
- pinMode(led_red, OUTPUT);
- pinMode(led_green, OUTPUT);
- akcja.attach(0, 5000, timer1sek); // 1 sek
- Serial.begin(115200); //
- }
- void loop()
- {
- akcja.process(); //
- recivestrfromserial();
- }
- void timer1sek() { //test
- blinkLedgreen(); // blink led on NANO
- blinkvLed(); //blink vLed from NANO
- blinkvLed2(); //blink vLed from NANO
- }
- bool flagaled = 0;
- void blinkLedgreen() { //test
- flagaled = !flagaled;
- digitalWrite(led_green, flagaled);
- }
- int x = 0;
- void blinkvLed() { //for test
- if (flagaled) BlynkvirtualWrite_led(3, 255); else BlynkvirtualWrite_led(3, 0);
- x++;
- BlynkvirtualWrite_int(7, x);
- }
- void blinkvLed2() { //for test
- String col1 = "#FF0000";
- String col2 = "#00FF00";
- if (flagaled) BlynkvirtualWrite_led(4, 255); else BlynkvirtualWrite_led(4, 0);
- if (flagaled) BlynkvirtualWrite_col(5, col1); else BlynkvirtualWrite_col(5, col2);
- if (flagaled) BlynkvirtualWrite_Off(5, "UP"); else BlynkvirtualWrite_Off(5, "DOWN");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement