Advertisement
Guest User

Untitled

a guest
Oct 19th, 2013
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 KB | None | 0 0
  1. #include "simpletools.h" // Include simpletools header
  2. #include "adcDCpropab.h" // Include ping header
  3. #include "servo.h"
  4. #include "fdserial.h"
  5. #include "simpletext.h"
  6.  
  7. #define emic_tx 6
  8. #define emic_rx 7
  9.  
  10. int main() // main function
  11. {
  12. pause(1000);
  13. adc_init(21, 20, 19, 18);
  14. fdserial *Emic2 = fdserial_open(emic_rx, emic_tx, 0, 9600);
  15.  
  16. float lrV, udV;
  17. int ud, lr;
  18.  
  19. while(1) // Repeat indefinitely
  20. {
  21. udV = adc_volts(2);
  22. lrV = adc_volts(3);
  23.  
  24. ud = 200*(udV-2.5)/5;
  25. lr = 200*(lrV-2.5)/5;
  26.  
  27. if (ud > 10)
  28. {
  29. print("Up \n");
  30. dprint(Emic2, "s");
  31. dprint(Emic2, "Up up and away!\n");
  32. servo_angle(16, 900);
  33. pause(500);
  34. servo_angle(16, 1025);
  35. pause(500);
  36. }
  37. else if (ud < -10)
  38. {
  39. print("Down \n");
  40. dprint(Emic2, "s");
  41. dprint(Emic2, "We're going down!\n");
  42. servo_angle(16, 1200);
  43. pause(500);
  44. servo_angle(16, 1025);
  45. pause(500);
  46. }
  47. if (lr > 10)
  48. {
  49. print("Right \n");
  50. dprint(Emic2, "s");
  51. dprint(Emic2, "To the right, to the right!\n");
  52. servo_angle(17, 900);
  53. pause(500);
  54. servo_angle(17, 1020);
  55. pause(500);
  56. }
  57. else if (lr < -10)
  58. {
  59. print("Left \n");
  60. dprint(Emic2, "s");
  61. dprint(Emic2, "To the left, to the left!\n");
  62. servo_angle(17, 1200);
  63. pause(500);
  64. servo_angle(17, 1020);
  65. pause(500);
  66. }
  67. pause(100);
  68. }
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement