Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void setup()
- {
- Serial.begin(115200); //
- }
- void loop()
- {
- recivestrfromserial();
- }
- //>>>>>>>>>>>>>>>>>>> my Programs
- void Program_vPin5(String strvPin) {
- }
- //etc ...
- void Program_vPin29(String strvPin) {
- }
- //from APP to NANO >>>>>>>>>>>>>>>>
- // equivalent BLYNK_WRITE(VPin)
- void Blynkwrite(String str2) {
- byte pin2;
- String strdata2;
- if (str2.charAt(0) != 'V') pin2 = 199; else {
- String istr = str2.substring(1, str2.indexOf(':')); // nr vPin
- pin2 = istr.toInt();
- strdata2 = str2.substring(str2.indexOf(':') + 1); // if nr vPin typ int
- }
- switch (pin2 + 1) { // Jump to program recived vPin
- case 5: Program_vPin5(strdata2); break;
- // etc....
- case 30: Program_vPin29(strdata2); break;
- // case 200: Serial.println("ERROR - no V"); break; //Program for error
- default: ;
- }
- }
- // equivalent Blynk.virtualWrite(VPin, Data);
- void BlynkvirtualWrite (byte vPin, String z) {
- String str1 = 'v' + String(vPin) + ':' + z;
- sendstrtoserial(str1);
- }
- // ....................................... recive string from serial
- bool stringComplete = false;
- String inputString = "";
- byte licznikodbioru = 0;
- void recivestrfromserial () {
- if (stringComplete) {
- Blynkwrite(inputString);
- inputString = "";
- stringComplete = false;
- licznikodbioru = 0;
- }
- }
- void serialEvent() { //odbiór string z Serial
- // Serial.println("odbior");
- while (Serial.available()) {
- licznikodbioru++;
- char inChar = (char)Serial.read();
- inputString += inChar;
- if (inChar == '\n') {
- stringComplete = true;
- }
- if (licznikodbioru > 50) inputString = "";
- }
- }
- // ................................. send string to serial
- void sendstrtoserial (String toserial) {
- Serial.println(toserial);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement