Advertisement
Guest User

Untitled

a guest
Aug 8th, 2012
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.83 KB | None | 0 0
  1. // Do not remove the include below
  2. #include "ArduinoC.h"
  3.  
  4. #include <Max3421e.h>
  5. #include <ch9.h>
  6. #include <AndroidAccessory.h>
  7. AndroidAccessory acc("Google, Inc.",
  8.              "DemoKit",
  9.              "DemoKit Arduino Board",
  10.              "1.0",
  11.              "http://www.android.com",
  12.              "0000000012345678");
  13. #define PINS 8
  14. #define STEPS 500
  15. char on = 1, reverse = 0;
  16. char rpm = 0;
  17. Stepper *engine1, *engine2;
  18. //void sendMessage(const char*);
  19. void readSerial();
  20. void step(signed long steps);
  21.  
  22. //The setup function is called once at startup of the sketch
  23. void setup() {
  24.     acc.begin();
  25. Serial.begin(9600);
  26. for (int i = 1; i<=PINS; i++) {
  27. pinMode(i, OUTPUT);
  28. }
  29. pinMode(13, OUTPUT);
  30.  
  31. #ifdef MOREPINS
  32.     engine1 = new Stepper(STEPS, 1, 2, 3, 4);
  33.     engine2 = new Stepper(STEPS, 5, 6, 7, 8);
  34. #else
  35.     engine1 = new Stepper(STEPS, 1, 2);
  36.     engine2 = new Stepper(STEPS, 3, 4);
  37. #endif
  38. engine1->setSpeed(100);
  39. engine2->setSpeed(100);
  40. }
  41.  
  42. void readSerial() {
  43.     if (!acc.isConnected() || false) {
  44.         Serial.println(!acc.isConnected() ? "Not connected!" : "No data incoming!");
  45.         delay(200);
  46.         return;
  47.     }
  48. char inBuffer[3] = {255, 255, 255};
  49. Serial.println("Reading!");
  50. acc.readBytes(inBuffer, 3);
  51. Serial.println("Done reading.");
  52. if ((255 == inBuffer[0]) || (255 == inBuffer[1]) || (255 == inBuffer[2])) {
  53.     //delete inBuffer;
  54.     Serial.println("Null msg!");
  55.     return;
  56. }
  57. Serial.println("Not null!");
  58. on = inBuffer[0];
  59. reverse = inBuffer[1];
  60. rpm = inBuffer[2];
  61. Serial.println(!on ? "ON!" : "OFF! :(");
  62. delete inBuffer;
  63. }
  64.  
  65.  
  66. // The loop function is called in an endless loop
  67. void loop() {
  68.     readSerial();
  69.  
  70.     //double stepSpeed = readSpeed();
  71.     if (on){
  72.         analogWrite(13, (reverse ? 255 / rpm : rpm));
  73.         return;}
  74.     //step(stepSpeed);
  75. }
  76. /*
  77. void sendMessage(const char* msg) {
  78.  
  79. }*/
  80.  
  81. void step(signed long steps) {
  82.  
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement