Willkommen auf unserem Seminar-Blog

Immer auf dem aktuellen Stand bleiben

Dieser Seminar-Blog befindet sich noch im Aufbau und wird in den kommenden Tagen entsprechend verfeinert.

Member Login

Lost your password?

Registration is closed

Sorry, you are not allowed to register by yourself on this site!

You must either be invited by one of our team member or request an invitation by email at viad.info {at} zhdk {dot} ch.

PhC, Aufgabe 12: Micro Servo Serial Controler

18. November 2010

YouTube Preview Image
<pre>/*
example to control pololu serial servo board
with software serial on pins 2 and 3 of arduino

see user guide

http://iad.projects.zhdk.ch/physicalcomputing/wp-content/files/ssc03a_guide.pdf

error codes of indicator leds are on page 4 of the user guide
*/

#include <SoftwareSerial.h>
// only speeds up to 9600 baud possible

#define rx 3   // rx = receive data
#define tx 2   // tx = transceive = send data

SoftwareSerial mySerial = SoftwareSerial(rx, tx);

// variables -------------------------------------

// the setup -------------------------------------
void setup(){
 pinMode(rx, INPUT);
 pinMode(tx, OUTPUT);
 mySerial.begin(9600);
/*
 for (int i=0; i<=4; i++) {
 reset(i);
 delay(1000);
 }*/
}

// the loop --------------------------------------
void loop(){
//  for (int i=0; i<=2; i++) { // make 3 steps left and right
 for (int j=0; j<=4; j++) { // turn 5 servo motors to the left
 turn_left(j);
 delay(200);
 }
 delay(1000);
 for (int j=4; j>=0; j--) { // turn 5 servo motors to the right, start with the 5th motor
 turn_right(j);
 delay(200);
 }
 delay(1000);
//  }
}

// function --------------------------------------
void reset (int servo) {
 mySerial.print(255, BYTE);      // Protocol Header
 mySerial.print(servo+8, BYTE);        // Servo 0 from 0 - 180°
 mySerial.println(5, BYTE);   // set degree
}

void turn_left (int servo){
 mySerial.print(255, BYTE);      // Protocol Header
 mySerial.print(servo+8, BYTE);        // Servo 0 from 0 - 180°
 mySerial.println(5, BYTE);   // set degree
}

void turn_right (int servo){
 mySerial.print(255, BYTE);      // Protocol Header
 mySerial.print(servo+8, BYTE);        // Servo 0 from 0 - 180°
 mySerial.println(200, BYTE);   // set degree
}