Advertisement
Guest User

Mario Servo

a guest
Apr 1st, 2013
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. #include <Servo.h>
  2.  
  3. Servo myservo; // create servo object to control a servo
  4. // a maximum of eight servo objects can be created
  5.  
  6. int pos = 0; // variable to store the servo position
  7. int lightSensorPin = 0;
  8. int motorPin = 3;
  9. int buttonPin = 2;
  10. int servoPin = 9;
  11.  
  12. void setup()
  13. {
  14. Serial.begin(9600);
  15. pinMode(motorPin, OUTPUT);
  16. myservo.attach(servoPin); // attaches the servo on pin 9 to the servo object
  17. myservo.write(0);
  18. delay(500);
  19. analogWrite(motorPin, 140);
  20. }
  21.  
  22. /*
  23. If implemented with the
  24. int getLight() {
  25. int val = analogRead(lightSensorPin);
  26. Serial.println(val);
  27. // WHITE
  28. if (val < 650) {
  29. return 0;
  30. }
  31. // GRAY
  32. if (val < 700) {
  33. return 1;
  34. }
  35. // BLACK
  36. return 2;
  37.  
  38. }
  39. */
  40.  
  41. void jump() {
  42. Serial.println("jumping");
  43. //myservo.write(10);
  44. //delay(400);
  45. myservo.write(20);
  46. delay(400);
  47. //myservo.write(10);
  48. //delay(400);
  49. myservo.write(0);
  50. delay(500);
  51. }
  52.  
  53. void loop()
  54. {
  55.  
  56. /* For Mario Jump */
  57. int buttonState = digitalRead(buttonPin);
  58.  
  59. //int lightValue = analogRead(lightSensorPin);
  60. //Serial.println(lightValue);
  61.  
  62. if (buttonState == HIGH) {
  63. jump();
  64. }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement