Advertisement
Krzyspx

brama3,5transmit

Dec 2nd, 2016
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.54 KB | None | 0 0
  1. #include <Arduino.h>
  2. // matryca programów
  3. void Program_vPin0(String strvPin);
  4. void Program_vPin10(String strvPin);
  5. void Program_vPin11(String strvPin);
  6. void Program_vPin12(String strvPin);
  7. void Program_vPin13(String strvPin);
  8. //void Program_vPin14(String strvPin);
  9. void Program_vPin15(String strvPin);
  10. void Program_vPin16(String strvPin);
  11. //void Program_vPin17(String strvPin);
  12. void Program_vPin29(String strvPin);
  13. void Program_vPin34(String strvPin);
  14.  
  15. // equivalent BLYNK_WRITE(VPin)   vPin from APP to NANO  
  16.  
  17. void Blynkwrite(String str2) {
  18.  
  19.   String istr = str2.substring(1, str2.indexOf(':')); // nr vPin
  20.   byte pin2 = istr.toInt();
  21.   String  strdata2 = str2.substring(str2.indexOf(':') + 1); // if nr vPin typ int
  22.   int  data2 = strdata2.toInt();
  23.  
  24.   if (str2.charAt(0) == 'V') {
  25.  
  26.     switch (pin2 + 1) { // Switch to progrma for recived vPin
  27.       case 1: Program_vPin0(strdata2);  break;
  28.      
  29.   //    case 10: Program_vPin9(strdata2);  break;
  30.       case 11: Program_vPin10(strdata2);  break;
  31.       case 12: Program_vPin11(strdata2);  break;
  32.       case 13: Program_vPin12(strdata2);  break;
  33.       case 14: Program_vPin13(strdata2);  break;
  34.    //   case 15: Program_vPin14(strdata2);  break;
  35.       case 16: Program_vPin15(strdata2);  break;
  36.       case 17: Program_vPin16(strdata2);  break;
  37.    //   case 18: Program_vPin17(strdata2);  break;
  38.       // etc....
  39.       case 30: Program_vPin29(strdata2);  break;
  40.             case 35: Program_vPin34(strdata2);  break;
  41.       default: ;
  42.     }
  43.   }
  44. }
  45.  
  46. // equivalent   Blynk.virtualWrite(VPin, Data);
  47.  
  48. void sendstrtoserial (String toserial) {
  49.   Serial.println(toserial);
  50. }
  51. void BlynkvirtualWrite(char Ch, byte vPin, String str) { // send to APP
  52.   String  str1 = Ch + String(vPin) + ':' + str; // string to send
  53.   sendstrtoserial(str1);
  54. }
  55. void BlynkvirtualWrite_str (byte vPin1, String str1) { // send str to APP
  56.   BlynkvirtualWrite('S', vPin1, str1);
  57. }
  58. void BlynkvirtualWrite_int (byte vPin2, int z)  { // send int to APP
  59.   BlynkvirtualWrite('I', vPin2, String(z));
  60. }
  61. void BlynkvirtualWrite_led(byte vPin3, byte Value) { // send LEDs data to APP
  62. BlynkvirtualWrite('L', vPin3, String(Value));
  63. }
  64. void BlynkvirtualWrite_col(byte vPin4, String col) { // send color data to APP
  65. BlynkvirtualWrite('C', vPin4, col);
  66. }
  67. void BlynkvirtualWrite_On(byte vPin5, String ON) { // send onLabels data to APP
  68. BlynkvirtualWrite('N', vPin5, ON);
  69. }
  70. void BlynkvirtualWrite_Off(byte vPin6, String OFF) { // send offLabel data to APP
  71.  BlynkvirtualWrite('F', vPin6, OFF);
  72. }
  73. void BlynkvirtualWrite_order(byte vPin7, String str7) { // send order to esp
  74.  BlynkvirtualWrite('O', vPin7, str7);
  75. }
  76.  
  77. // ....................................... recive string from serial
  78.  
  79. bool  stringComplete = false;
  80. String inputString = "";
  81. byte licznikodbioru = 0;
  82. int startrecive = 0;
  83.  
  84. void recivestrfromserial () {
  85.   if (stringComplete) {
  86.     Serial.println("od  " + String(inputString)); //test
  87.     Blynkwrite(inputString);
  88.     inputString = "";
  89.     stringComplete = false;
  90.     licznikodbioru = 0;
  91.     startrecive = 0;
  92.   }
  93. }
  94.  
  95. void serialEvent() { //odbiór string z Serial
  96.   if (Serial.available()) {
  97.     licznikodbioru++;
  98.     char inChar = (char)Serial.read();
  99.     if (startrecive == 0) {
  100.       if ((inChar == 'V'))  startrecive = 1;
  101.     }
  102.     if (startrecive == 1) {
  103.       if (inChar == '\r')  {
  104.         stringComplete = true;
  105.         inChar = '\0';
  106.         inputString += inChar;
  107.         startrecive = 0;
  108.       } else  {inputString += inChar;}
  109.     }
  110.     if (licznikodbioru > 60) {inputString = "";}
  111.   }
  112. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement