Moin
Teil 3
nun habe ich in meinem Bw eine kleine Drehscheibe von Faller einen Kohlenkran und einen Wasserkran.
Diese drei Bauteile haben alle schon Servo eingebaut und den Film dazu gibt es hier:
https://www.youtube.com/watch?v=1qbSsk3Zp1s
https://www.youtube.com/watch?v=M8lYCi6A...hYpgAsn&index=8
Doch auch dafür braucht man eine Steuerung...nun wieder zurück an den PC und locker weiter geschrieben.
Der neue Sketch für die zweite Steuerung:
#########################################################
// Steuerung Nr2 für das Feldbahn Bw1
#include <Servo.h>
Servo myservo; // servo1 poti a5
Servo myservo1; // servo1 poti a6
Servo myservo2; // servo1 poti a7
Servo myservo3; // servo1 taster 1+2
Servo myservo4; // servo1 taster 3+4
Servo myservo5; // servo1 taster 5+6
int tasterPin1 = 2; //Taster1 an Pin 2 angeschlossen
int tasterPin2 = 4; //Taster2 an Pin 4 angeschlossen
int tasterStatus1, tasterStatus2;
int tasterPin3 = 7; //Taster3 an Pin 7 angeschlossen
int tasterPin4 = 8; //Taster4 an Pin 8 angeschlossen
int tasterStatus3, tasterStatus4;
int tasterPin5 = 14; //Taster5 an Pin 14 angeschlossen
int tasterPin6 = 15; //Taster6 an Pin 15 angeschlossen
int tasterStatus5, tasterStatus6;
int potpin = 5; // analog pin5 used to connect the potentiometer
int val; // variable0 to read the value from the analog pin
int potpin1 = 6; // analog pin6 used to connect the potentiometer
int val1; // variable1 to read the value from the analog pin
int potpin2 = 7; // analog pin7 used to connect the potentiometer
int val2; // variable2 to read the value from the analog pin
void setup() {
myservo.attach(11); // attaches the servo on pin 11 to the servo object
myservo1.attach(10); // attaches1 the servo on pin 12 to the servo object
myservo2.attach(9); // attaches2 the servo on pin 3 to the servo object
myservo3.attach(5); // attaches3 the servo on pin 5 to the servo object
myservo4.attach(6); // attaches4 the servo on pin 6 to the servo object
myservo4.attach(3); // attaches4 the servo on pin 6 to the servo object
pinMode(tasterPin1, INPUT);
pinMode(tasterPin2, INPUT);
myservo3.attach(3); //Servomotor0 wurde an Pin 3 angeschlossen
pinMode(tasterPin3, INPUT);
pinMode(tasterPin4, INPUT);
myservo4.attach(5); //Servomotor1 wurde an Pin 6 angeschlossen
pinMode(tasterPin5, INPUT);
pinMode(tasterPin6, INPUT);
myservo5.attach(6); //Servomotor2 wurde an Pin 9 angeschlossen
digitalWrite(tasterPin1, true); // pullup Wiederstand einschalten
digitalWrite(tasterPin2, true); // pullup Wiederstand einschalten
digitalWrite(tasterPin3, true); // pullup Wiederstand einschalten
digitalWrite(tasterPin4, true); // pullup Wiederstand einschalten
digitalWrite(tasterPin5, true); // pullup Wiederstand einschalten
digitalWrite(tasterPin6, true); // pullup Wiederstand einschalten
}
void loop() {
val = analogRead(potpin); // reads the value of the potentiometer (value between 0 and 1023)
val = map(val, 0, 1023, 0, 180); // scale it to use it with the servo (value between 0 and 180)
myservo3.write(val); // servo1 pin 3
delayMicroseconds(1); // waits for the servo to get there
val1 = analogRead(potpin1); // reads the value of the potentiometer (value between 0 and 1023)
val1 = map(val1, 0, 1023, 0, 180); // scale it to use it with the servo (value between 0 and 180)
myservo4.write(val1); // servo2 pin 5
delayMicroseconds(1); // waits for the servo to get there
val2 = analogRead(potpin2); // reads the value of the potentiometer (value between 0 and 1023)
val2 = map(val2, 0, 1023, 0, 180); // scale it to use it with the servo (value between 0 and 180)
myservo5.write(val2); // servo3 pin 6
delayMicroseconds(1); // waits for the servo to get there
// servo0
{
tasterStatus1 = digitalRead(tasterPin1);//servo3
tasterStatus2 = digitalRead(tasterPin2);
if (tasterStatus1 == 0)
{
myservo.write(157); //Dreht nach links
delayMicroseconds(20);
}
if (tasterStatus2 == 0)
{
myservo.write(0); //Dreht nach rechts
delayMicroseconds(20);
}
delayMicroseconds(10);
//servo1
tasterStatus3 = digitalRead(tasterPin3);//servo4
tasterStatus4 = digitalRead(tasterPin4);
if (tasterStatus3 == 0)
{
myservo1.write(157); //Dreht nach links
delayMicroseconds(20);
}
if (tasterStatus4 == 0)
{
myservo1.write(0); //Dreht nach rechts
delayMicroseconds(20);
}
delayMicroseconds(10);
// servo2
tasterStatus5 = digitalRead(tasterPin5);//servo5
tasterStatus6 = digitalRead(tasterPin6);
if (tasterStatus5 == 0)
{
myservo2.write(157); //Dreht nach links
delayMicroseconds(20);
}
if (tasterStatus6 == 0)
{
myservo2.write(0); //Dreht nach rechts
delayMicroseconds(20);
}
delayMicroseconds(10);
}
}
################################################################
Die Bilder von diesen zwei Baustellen werde ich zu einem Späteren Zeipunkt hier noch zeigen.
Doch für heute ist wirklich Schluß, bis bald Gruß
Karsten