Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Servo.h>
- Servo myservo; // create servo object to control a servo
- // a maximum of eight servo objects can be created
- int pos = 0; // variable to store the servo position
- int lightSensorPin = 0;
- int motorPin = 3;
- int buttonPin = 2;
- int servoPin = 9;
- void setup()
- {
- Serial.begin(9600);
- pinMode(motorPin, OUTPUT);
- myservo.attach(servoPin); // attaches the servo on pin 9 to the servo object
- myservo.write(0);
- delay(500);
- analogWrite(motorPin, 140);
- }
- /*
- If implemented with the
- int getLight() {
- int val = analogRead(lightSensorPin);
- Serial.println(val);
- // WHITE
- if (val < 650) {
- return 0;
- }
- // GRAY
- if (val < 700) {
- return 1;
- }
- // BLACK
- return 2;
- }
- */
- void jump() {
- Serial.println("jumping");
- //myservo.write(10);
- //delay(400);
- myservo.write(20);
- delay(400);
- //myservo.write(10);
- //delay(400);
- myservo.write(0);
- delay(500);
- }
- void loop()
- {
- /* For Mario Jump */
- int buttonState = digitalRead(buttonPin);
- //int lightValue = analogRead(lightSensorPin);
- //Serial.println(lightValue);
- if (buttonState == HIGH) {
- jump();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement