Advertisement
kubbur

Untitled

Nov 13th, 2014
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 KB | None | 0 0
  1. arduino k��i
  2.  
  3. python k��inn er fyrir ne�an
  4.  
  5. //working k��i
  6. // ssh root@ yourYunsName.local 'telnet localhost 6571'
  7.  
  8.  
  9.  
  10. #include <Console.h>
  11. #include <Servo.h>
  12.  
  13. const int ledPin = 13; // the pin that the LED is attached to
  14. char ib; // a variable to read incoming Console data into
  15. Servo servo1;
  16.  
  17. void setup()
  18.  
  19.  
  20. {
  21. servo1.attach(6); // Attach servo to pin 7
  22. Bridge.begin(); // Initialize Bridge
  23. Console.begin(); // Initialize Console
  24. pinMode(3, OUTPUT); // tone
  25. // Wait for the Console port to connect
  26. while(!Console);
  27.  
  28. Console.println("READY");
  29. tone (3, 800, 200);
  30. delay (200);
  31.  
  32.  
  33. // initialize the LED pin as an output:
  34. pinMode(ledPin, OUTPUT);
  35. }
  36.  
  37. void loop() {
  38. // see if there's incoming Console data:
  39. if (Console.available() > 0) {
  40. // read the oldest byte in the Console buffer:
  41. ib = Console.read();
  42. if (ib == 'S') // if Byte is S
  43. {
  44. uint8_t b1 = Console.read (); //read next 3 numbers that come after S
  45. uint8_t b2 = Console.read ();
  46. uint8_t b3 = Console.read ();
  47. servo1.write((b1 - '0')*100 + (b2 - '0')*10 + b3 - '0');
  48. }
  49. // if it's a capital H (ASCII 72), turn on the LED:
  50. if (ib == 'H') {
  51. digitalWrite(ledPin, HIGH);
  52. }
  53. // if it's an L (ASCII 76) turn off the LED:
  54. if (ib == 'L') {
  55. digitalWrite(ledPin, LOW);
  56. }
  57. }
  58. }
  59.  
  60. python k��i
  61.  
  62. import telnetlib
  63. import time
  64. import sys
  65. HOST = "localhost"
  66. PORT = "6571"
  67. tn = telnetlib.Telnet(HOST, PORT)
  68. tn.write("S090\n\r")
  69. time.sleep(1)
  70. tn.write("S080\n\r")
  71. time.sleep(1)
  72. tn.close()
  73. sys.exit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement