Cookins

robot1

Oct 14th, 2017
18
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. #define BLYNK_PRINT Serial
  3.  
  4. #include <Stepper.h>
  5. #include <ESP8266_Lib.h>
  6. #include <BlynkSimpleShieldEsp8266.h>
  7.  
  8. // You should get Auth Token in the Blynk App.
  9. // Go to the Project Settings (nut icon).
  10. char auth[] = "b0xxxxxxxxxxxxx2a7185";
  11.  
  12. // Your WiFi credentials.
  13. // Set password to "" for open networks.
  14. char ssid[] = "Pxxxxxxca3";
  15. char pass[] = "gxxxxxxxx";
  16.  
  17. // or Software Serial on Uno, Nano...
  18. #include <SoftwareSerial.h>
  19. SoftwareSerial EspSerial(2, 3); // RX, TX
  20.  
  21. // Your ESP8266 baud rate:
  22. #define ESP8266_BAUD 9600
  23.  
  24. ESP8266 wifi(&EspSerial);
  25.  
  26. const int stepsPerRevolution = 2048;
  27. Stepper rightStepper(stepsPerRevolution, 8,10,9,11);
  28. Stepper leftStepper(stepsPerRevolution, 4,6,5,7);
  29. int state = 5;
  30.  
  31. WidgetTerminal terminal(V5);
  32.  
  33. BLYNK_WRITE(V5)
  34. {
  35. if (String("echo") == param.asStr()) {
  36. terminal.println("echo OK") ;
  37. } else {
  38. terminal.println("FAIL") ;}
  39. }
  40.  
  41. void setup()
  42. {
  43. // Debug console
  44. Serial.begin(9600);
  45.  
  46. delay(10);
  47.  
  48. // Set ESP8266 baud rate
  49. EspSerial.begin(ESP8266_BAUD);
  50. delay(10);
  51.  
  52. rightStepper.setSpeed(18);
  53. leftStepper.setSpeed(18);
  54.  
  55. Blynk.begin(auth, wifi, ssid, pass);
  56.  
  57. terminal.println(F("Blynk v" BLYNK_VERSION ": Device started"));
  58.  
  59. }
  60. BLYNK_WRITE(V0) {
  61. if (param.asInt() == 1) {
  62. state = 1; // forward
  63. } else {
  64. state = 5; // stop
  65. }
  66. Control();
  67. }
  68. BLYNK_WRITE(V1) {
  69. if (param.asInt() == 1) {
  70. state = 2; // backward
  71. } else {
  72. state = 5; // stop
  73. }
  74. Control();
  75. }
  76. BLYNK_WRITE(V3) {
  77. if (param.asInt() == 1) {
  78. state = 3; // right
  79. } else {
  80. state = 5; // stop
  81. }
  82. Control();
  83. }
  84. BLYNK_WRITE(V2) {
  85. if (param.asInt() == 1) {
  86. state = 4; // left
  87. } else {
  88. state = 5; // stop
  89. }
  90. Control();
  91. }
  92.  
  93. void Control() {
  94. //move forward
  95. if (state == 1) {
  96. rightStepper.step(1);
  97. leftStepper.step(-1);
  98. }
  99. //move backward
  100. if (state == 2) {
  101. rightStepper.step(-1);
  102. leftStepper.step(1);
  103. }
  104. //move right
  105. if (state == 3) {
  106. rightStepper.step(-1);
  107. leftStepper.step(-1);
  108. }
  109. //move left
  110. if (state == 4) {
  111. rightStepper.step(1);
  112. leftStepper.step(1);
  113. }
  114. //do nothing
  115. if (state == 5) {
  116. rightStepper.step(0);
  117. leftStepper.step(0);
  118. }
  119. }
  120. void loop()
  121. {
  122. Blynk.run();
  123. }
RAW Paste Data