Advertisement
Guest User

Untitled

a guest
Mar 24th, 2018
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.54 KB | None | 0 0
  1. #include <SPI.h>
  2. #include <WiFiLink.h>
  3. #include <BlynkSimpleWiFiLink.h>
  4.  
  5. unsigned long a, b, f, a2, b2, f2;
  6. char auth[] = "2879ce1054274c4095fd6737041a9746";
  7.  
  8. // WiFi credentials.
  9. char ssid[] = "EEERover";
  10. char pass[] = "exhibition";
  11.  
  12. BLYNK_WRITE(V1) {
  13. //Joystick code
  14.   int x = param[0].asInt();
  15.   int y = param[1].asInt();
  16.   int speedL = 0, speedR = 0, directionL = 0, directionR = 0, tempL = 0, tempR = 0;
  17.   int dirL = 5;
  18.   int dirR = 4;
  19.   int pwmL = 9;
  20.   int pwmR = 10;
  21.  
  22. if (y >= 0) {
  23.  tempR = y - x;
  24.  tempL = y + x;
  25. }
  26.  
  27. if (y < 0) {
  28.  
  29.  if (x <= 0) {
  30.  tempR = -abs(y + x);
  31.  tempL = y - x;
  32.  }
  33.  
  34.  if (x > 0) {
  35.  tempR = y + x;
  36.  tempL = -abs(y - x);
  37.  }
  38. }
  39.  
  40.  if (tempL >= 0) {
  41.  directionL = HIGH;
  42.  speedL = tempL;
  43.  }
  44.  if (tempL < 0) {
  45.  directionL = LOW;
  46.  speedL = -tempL;
  47.  }
  48.  
  49.  if (tempR >= 0) {
  50.  directionR = HIGH;
  51.  speedR = tempR;
  52.  }
  53.  if (tempR < 0) {
  54.  directionR = LOW;
  55.  speedR = -tempR;
  56.  }
  57.  
  58.   analogWrite(pwmL, speedL);
  59.   analogWrite(pwmR, speedR);
  60.   digitalWrite(dirL, directionL);
  61.   digitalWrite(dirR, directionR);
  62.  
  63. }
  64.  
  65. void setup()
  66. {
  67.   Serial.begin(9600);
  68.  
  69.   delay(10);
  70.   pinMode(13, INPUT);
  71.  
  72.   Blynk.begin(auth, ssid, pass, IPAddress(192,168,0,51));
  73. }
  74.  
  75. void loop(){
  76.  
  77.   Blynk.run();
  78.   //IR freq measure
  79.   a = pulseIn(13, HIGH);
  80.   b = pulseIn(13, LOW);
  81.   f = 1000000/(a + b);
  82.  
  83.   if (f<1000){
  84.   Blynk.virtualWrite(V3, f);
  85. }
  86.   //RF freq measure
  87.   a2 = pulseIn(12, HIGH);
  88.   b2 = pulseIn(12, LOW);
  89.   f2 = 1000000/(a2 + b2);
  90.  
  91.   if (f2<1000){
  92.   Blynk.virtualWrite(V4, f2);
  93.   }
  94.  
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement