User Tools

Site Tools


berend

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revisionBoth sides next revision
berend [2019/03/26 19:11] inneberend [2019/03/26 23:04] wrusman
Line 39: Line 39:
 ==== Drivers : ==== ==== Drivers : ====
 Er is een grote kans dat Mac en Windows gebruikers extra [[https://sparks.gogo.co.nz/ch340.html|drivers]] moeten installeren zodat de Arduino door hun computers herkent wordt. Op Linux zouden de drivers standaard beschikbaar moeten zijn.  Er is een grote kans dat Mac en Windows gebruikers extra [[https://sparks.gogo.co.nz/ch340.html|drivers]] moeten installeren zodat de Arduino door hun computers herkent wordt. Op Linux zouden de drivers standaard beschikbaar moeten zijn. 
 +
 +=== Code ===
 +basis code voor lopen :
 +<code>
 +#include <Servo.h>
 +
 +Servo lefthip;    // create servo object to control the left hip servo
 +Servo leftfoot;   // create servo object to control the left foot servo
 +Servo righthip;   // create servo object to control the right hip servo
 +Servo rightfoot;  // create servo object to control the right foot servo
 +
 +
 +void setup() {
 +  lefthip.attach(2);    // attaches the servo on pin 2 to the left hip servo object
 +  leftfoot.attach(3);   // attaches the servo on pin 3 to the left foot servo object
 +  righthip.attach(5);  // attaches the servo on pin 5 to the right hip servo object
 +  rightfoot.attach(4);  // attaches the servo on pin 4 to the right foot servo object
 +  lefthip.write(90);    // center the servo
 +  leftfoot.write(90);    // center the servo
 +  righthip.write(90);    // center the servo
 +  rightfoot.write(90);    // center the servo
 +}
 +
 +
 +void loop() {
 +  stepforward(10);
 +  delay(10000);
 +}
 +
 +void stepforward(int steps)
 +{
 +  moveServo(rightfoot,90,60);
 +  moveServo(leftfoot,90,50);
 +
 +  moveServo(lefthip,90,60);
 +  moveServo(righthip,90,60);
 +
 +  for (int x=0; x <= steps; x++){
 +
 +  moveServo(leftfoot,50,90);
 +  moveServo(rightfoot,60,90);
 +  moveServo(leftfoot,90,120);
 +  moveServo(rightfoot,90,130);
 +  
 +  moveServo(righthip,60,120);
 +  moveServo(lefthip,60,120);
 +    
 +  moveServo(rightfoot,130,90);
 +  moveServo(leftfoot,120,90);
 +  moveServo(rightfoot,90,60);
 +  moveServo(leftfoot,90,50);
 +
 +  moveServo(lefthip,120,60);
 +  moveServo(righthip,120,60);
 +  }
 +
 +  moveServo(leftfoot,50,90);
 +  moveServo(righthip,60,90);
 +  moveServo(lefthip,60,90);
 +  moveServo(rightfoot,60,90);
 +
 +}
 +
 +
 +void moveServo(Servo servoName, int oldAngle, int newAngle)
 +{
 +  if (newAngle > oldAngle){
 +    for (int x=oldAngle; x <= newAngle; x++)
 +    {
 +      servoName.write(x); 
 +      delay(10);
 +    }
 +  }
 +  if (newAngle < oldAngle){
 +    for (int x=oldAngle; x >= newAngle; x--)
 +    {
 +      servoName.write(x);
 +      delay(10); 
 +    }
 +  }
 +  
 +}
 +</code>
  
berend.txt · Last modified: 2019/06/28 12:37 by wrusman