Advertisement
kubbur

Untitled

Nov 18th, 2014
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1.  
  2. #include <Console.h>
  3. #include <Servo.h>
  4.  
  5. char ib;
  6. Servo servo1;
  7.  
  8. void setup()
  9.  
  10. {
  11. servo1.attach(6); // Attach servo to pin 7
  12. Bridge.begin(); // Initialize Bridge
  13. Console.begin(); // Initialize Console
  14. pinMode(3, OUTPUT); // tone
  15. }
  16.  
  17. void loop() {
  18. if (Console.available() > 0)
  19. {
  20. ib = Console.read();
  21. if (ib == 'S') // if Byte is S
  22. {
  23. uint8_t b1 = Console.read (); //read next 3 numbers that come after S
  24. uint8_t b2 = Console.read ();
  25. uint8_t b3 = Console.read ();
  26. servo1.write((b1 - '0')*100 + (b2 - '0')*10 + b3 - '0'); //put them in the correct order
  27. }
  28.  
  29. if (ib == 't') {
  30. uint8_t b1 = Console.read ();
  31. tone(3, (b1 - '0')*100, 200);
  32.  
  33. } //ex: t8 gives tone 800 on pin 3 for 200 ms
  34.  
  35. if (ib == 'T') {
  36. uint8_t b1 = Console.read ();
  37. tone(3, (b1 - '0')*1000, 200);
  38.  
  39. } //ex: gives tone 8000 on pin 3 for 200 ms
  40. }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement