Guest User

Untitled

a guest
Apr 21st, 2018
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.20 KB | None | 0 0
  1. /*************************************************************
  2. Download latest Blynk library here:
  3. https://github.com/blynkkk/blynk-library/releases/latest
  4.  
  5. Blynk is a platform with iOS and Android apps to control
  6. Arduino, Raspberry Pi and the likes over the Internet.
  7. You can easily build graphic interfaces for all your
  8. projects by simply dragging and dropping widgets.
  9.  
  10. Downloads, docs, tutorials: http://www.blynk.cc
  11. Sketch generator: http://examples.blynk.cc
  12. Blynk community: http://community.blynk.cc
  13. Follow us: http://www.fb.com/blynkapp
  14. http://twitter.com/blynk_app
  15.  
  16. Blynk library is licensed under MIT license
  17. This example code is in public domain.
  18.  
  19. *************************************************************
  20. =>
  21. => USB HOWTO: http://tiny.cc/BlynkUSB
  22. =>
  23.  
  24. This sketch shows how to read values from Virtual Pins
  25.  
  26. App project setup:
  27. Slider widget (0...100) on Virtual Pin V1
  28. *************************************************************/
  29.  
  30. /* Comment this out to disable prints and save space */
  31. #define BLYNK_PRINT SwSerial
  32. #define TRIGGER 9
  33. #define ECHO 10
  34.  
  35. #include <SoftwareSerial.h>
  36. SoftwareSerial SwSerial(10, 11); // RX, TX
  37.  
  38. #include <BlynkSimpleStream.h>
  39.  
  40. // You should get Auth Token in the Blynk App.
  41. // Go to the Project Settings (nut icon).
  42. char auth[] = "YOUR AUTH TOKEN HERE";
  43.  
  44. // This function will be called every time Slider Widget
  45. // in Blynk app writes values to the Virtual Pin V1
  46. BLYNK_WRITE(V5)
  47. {
  48. int pinValue = param.asInt(); // assigning incoming value from pin V1 to a variable
  49.  
  50. // process received value
  51. }
  52.  
  53. void setup()
  54. {
  55. // Debug console
  56. SwSerial.begin(9600);
  57. Serial.begin(9600);
  58. Blynk.begin(Serial, auth);
  59. pinMode(TRIGGER, OUTPUT);
  60. pinMode(ECHO, INPUT);
  61.  
  62. }
  63.  
  64. void loop()
  65. {
  66. long duration, distance;
  67. digitalWrite(TRIGGER, LOW);
  68. delayMicroseconds(2);
  69.  
  70. digitalWrite(TRIGGER, HIGH);
  71. delayMicroseconds(10);
  72.  
  73. digitalWrite(TRIGGER, LOW);
  74. duration = pulseIn(ECHO, HIGH);
  75. distance = (duration/2) / 29.1;
  76. Blynk.virtualWrite(V5, distance);
  77. delay(200);
  78. Blynk.run();
  79.  
  80. }
Add Comment
Please, Sign In to add comment