Advertisement
Krzyspx

esp_NANO

Nov 11th, 2016
3,252
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.79 KB | None | 0 0
  1.  
  2. void setup()
  3. {
  4.   Serial.begin(115200);  //
  5. }
  6. void loop()
  7. {
  8.   recivestrfromserial();
  9. }
  10. //>>>>>>>>>>>>>>>>>>> my Programs
  11.  
  12. void Program_vPin5(String strvPin) {
  13. }
  14. //etc ...
  15.  
  16. void Program_vPin29(String strvPin) {
  17. }
  18.  
  19. //from APP to NANO   >>>>>>>>>>>>>>>>
  20. // equivalent BLYNK_WRITE(VPin)
  21.  
  22. void Blynkwrite(String str2) {
  23.   byte pin2;
  24.   String strdata2;
  25.   if (str2.charAt(0) != 'V') pin2 = 199; else {
  26.     String istr = str2.substring(1, str2.indexOf(':')); // nr vPin
  27.     pin2 = istr.toInt();
  28.     strdata2 = str2.substring(str2.indexOf(':') + 1); // if nr vPin typ int
  29.   }
  30.   switch (pin2 + 1) { // Jump to program recived vPin
  31.     case 5: Program_vPin5(strdata2);  break;
  32.     // etc....
  33.     case 30: Program_vPin29(strdata2);  break;
  34.    // case 200:   Serial.println("ERROR - no V");  break; //Program for error
  35.     default: ;
  36.   }
  37. }
  38.  
  39. // equivalent   Blynk.virtualWrite(VPin, Data);
  40.  
  41. void BlynkvirtualWrite (byte vPin, String z) {
  42.   String  str1 = 'v' + String(vPin) + ':' + z;
  43.   sendstrtoserial(str1);
  44. }
  45.  
  46. // ....................................... recive string from serial
  47.  
  48. bool  stringComplete = false;
  49. String inputString = "";
  50. byte licznikodbioru = 0;
  51.  
  52. void recivestrfromserial () {
  53.   if (stringComplete) {
  54.     Blynkwrite(inputString);
  55.     inputString = "";
  56.     stringComplete = false;
  57.     licznikodbioru = 0;
  58.   }
  59. }
  60.  
  61. void serialEvent() { //odbiór string z Serial
  62.   // Serial.println("odbior");
  63.   while (Serial.available()) {
  64.     licznikodbioru++;
  65.     char inChar = (char)Serial.read();
  66.     inputString += inChar;
  67.     if (inChar == '\n') {
  68.       stringComplete = true;
  69.     }
  70.     if (licznikodbioru > 50) inputString = "";
  71.   }
  72. }
  73.  
  74. // ................................. send string to serial
  75. void sendstrtoserial (String toserial) {
  76.   Serial.println(toserial);
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement