Advertisement
Guest User

Untitled

a guest
Feb 8th, 2014
67
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #define motor1Pin1 9
  2. #define motor1Pin2 3
  3. #define motor2Pin1 6
  4. #define motor2Pin2 5
  5. //#define redLed 4
  6. //#define greenLed 5
  7. //#define blueLed 6
  8.  
  9. #include <PS3USB.h>
  10. #ifdef dobogusinclude
  11. #include <spi4teensy3.h>
  12. #endif
  13.  
  14. USB Usb;
  15. /* You can create the instance of the class in two ways */
  16. PS3USB PS3(&Usb); // This will just create the instance
  17. //PS3USB PS3(&Usb,0x00,0x15,0x83,0x3D,0x0A,0x57); // This will also store the bluetooth address - this can be obtained from the dongle when running the sketch
  18.  
  19. boolean printAngle;
  20. uint8_t state = 0;
  21.  
  22. void setup()
  23. {
  24. pinMode(motor1Pin1, OUTPUT); //this is an output because the Arduino is telling the motor to spin
  25. pinMode(motor1Pin2, OUTPUT);
  26. pinMode(motor2Pin1, OUTPUT);
  27. pinMode(motor2Pin2, OUTPUT);
  28. //pinMode(redLed, OUTPUT);
  29. //pinMode(greenLed, OUTPUT);
  30. //pinMode(blueLed, OUTPUT);
  31. Serial.begin(115200);
  32. while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection
  33. if (Usb.Init() == -1) {
  34. Serial.print(F("\r\nOSC did not start"));
  35. while (1); //halt
  36. }
  37. Serial.print(F("\r\nPS3 USB Library Started"));
  38. }
  39.  
  40. void loop()
  41. {
  42. Usb.Task();
  43.  
  44. if (PS3.PS3Connected || PS3.PS3NavigationConnected)
  45. {
  46. if (PS3.getButtonPress (R1))
  47. {
  48. GoForward();
  49. //Serial.print(F("\r\nR1"));
  50. }
  51. if (PS3.getButtonPress (L1))
  52. {
  53. GoBackward();
  54. //Serial.print(F("\r\nL1"));
  55. }
  56.  
  57. if (PS3.getAnalogHat(LeftHatX) == 255)
  58. {
  59. GoRight();
  60. //Serial.print(F("\r\nLeftHatX: "));
  61. //Serial.print(PS3.getAnalogHat(LeftHatX));
  62. }
  63. if (PS3.getAnalogHat(LeftHatX) == 0)
  64. {
  65. GoLeft();
  66. // Serial.print(F("\r\nLeftHatX: "));
  67. //Serial.print(PS3.getAnalogHat(LeftHatX));
  68. }
  69. if (PS3.getButtonClick (CIRCLE))
  70. {
  71. Stop();
  72. }
  73. }
  74. }
  75.  
  76. void GoForward()
  77. {
  78. digitalWrite(motor1Pin1, LOW);
  79. digitalWrite(motor1Pin2, HIGH);
  80. digitalWrite(motor2Pin1, LOW);
  81. digitalWrite(motor2Pin2, HIGH);
  82. }
  83.  
  84. void GoBackward()
  85. {
  86. digitalWrite(motor1Pin1, HIGH);
  87. digitalWrite(motor1Pin2, LOW);
  88. digitalWrite(motor2Pin1, HIGH);
  89. digitalWrite(motor2Pin2, LOW);
  90. }
  91. void Stop()
  92. {
  93. digitalWrite(motor1Pin1, LOW);
  94. digitalWrite(motor1Pin2, LOW);
  95. digitalWrite(motor2Pin1, LOW);
  96. digitalWrite(motor2Pin2, LOW);
  97. }
  98. void GoLeft()
  99. {
  100. digitalWrite(motor1Pin1, LOW);
  101. digitalWrite(motor1Pin2, HIGH);
  102. digitalWrite(motor2Pin1, HIGH);
  103. digitalWrite(motor2Pin2, LOW);
  104. }
  105. void GoRight()
  106. {
  107. digitalWrite(motor1Pin1, HIGH);
  108. digitalWrite(motor1Pin2, LOW);
  109. digitalWrite(motor2Pin1, LOW);
  110. digitalWrite(motor2Pin2, HIGH);
  111. }
Advertisement
RAW Paste Data Copied
Advertisement