Hallo Zusammen,
ich habe Zwei Motoren die jeweils eine bestimmte Funktion erfüllen aber nur mit einem Arduino
wie kann ich die Code fusionieren ?
Danke
Hallo Zusammen,
ich habe Zwei Motoren die jeweils eine bestimmte Funktion erfüllen aber nur mit einem Arduino
wie kann ich die Code fusionieren ?
Danke
Dazu wäre es sinnvoll, uns die Sketche zu zeigen. Setze Deinen Code bitte in Codetags (</>-Button oben links im Forumseditor oder [code] davor und [/code] dahinter ohne *).
Gruß Tommy
das erste Sketch ist
#include <LiquidCrystal.h> // includes the LiquidCrystal Library
LiquidCrystal lcd(1, 2, 4, 5, 6, 7); // Creates an LC object. Parameters: (rs, enable, d4, d5, d6, d7)
// defines pins numbers
#define stepPin 8
#define dirPin 9
#define outputA 10
#define outputB 11
int counter = 0;
int angle = 0;
int aState;
int aLastState;
void setup() {
// Sets the two pins as Outputs
pinMode(stepPin,OUTPUT);
pinMode(dirPin,OUTPUT);
pinMode (outputA,INPUT);
pinMode (outputB,INPUT);
aLastState = digitalRead(outputA);
lcd.begin(16,2); // Initializes the interface to the LCD screen, and specifies the dimensions (width and height) of the display }
}
void loop() {
aState = digitalRead(outputA);
if (aState != aLastState){
if (digitalRead(outputB) != aState) {
counter ++;
angle ++;
rotateCW();
}
else {
counter--;
angle --;
rotateCCW();
}
if (counter >=30 ) {
counter =0;
}
lcd.clear();
lcd.print("Öffnung: ");
lcd.print(int((2,5-(angle*(1,8)*/360))^2);
lcd.print("deg");
lcd.setCursor(0,0);
}
aLastState = aState;
}
void rotateCW() {
digitalWrite(dirPin,LOW);
digitalWrite(stepPin,HIGH);
delayMicroseconds(2000);
digitalWrite(stepPin,LOW);
delayMicroseconds(2000);
}
void rotateCCW() {
digitalWrite(dirPin,HIGH);
digitalWrite(stepPin,HIGH);
delayMicroseconds(2000);
digitalWrite(stepPin,LOW);
delayMicroseconds(2000);
}
und das zweite ist
#include <LiquidCrystal.h> // includes the LiquidCrystal Library
LiquidCrystal lcd(1, 2, 4, 5, 6, 7); // Creates an LC object. Parameters: (rs, enable, d4, d5, d6, d7)
// defines pins numbers
#define stepPin2 12
#define dirPin2 13
#define outputA 10
#define outputB 11
int counter = 0;
int angle = 0;
int aState;
int aLastState;
void setup() {
// Sets the two pins as Outputs
pinMode(stepPin,OUTPUT);
pinMode(dirPin,OUTPUT);
pinMode (outputA,INPUT);
pinMode (outputB,INPUT);
aLastState = digitalRead(outputA);
lcd.begin(16,2); // Initializes the interface to the LCD screen, and specifies the dimensions (width and height) of the display }
}
void loop() {
aState = digitalRead(outputA);
if (aState != aLastState){
if (digitalRead(outputB) != aState) {
counter ++;
angle ++;
rotateCW();
}
else {
counter--;
angle --;
rotateCCW();
}
if (counter >=30 ) {
counter =0;
}
lcd.clear();
lcd.print("Position: ");
lcd.print(int(angle/360));
lcd.print("deg");
lcd.setCursor(0,0);
}
aLastState = aState;
}
void rotateCW() {
digitalWrite(dirPin2,LOW);
digitalWrite(stepPin2,HIGH);
delayMicroseconds(2000);
digitalWrite(stepPin2,LOW);
delayMicroseconds(2000);
}
void rotateCCW() {
digitalWrite(dirPin2,HIGH);
digitalWrite(stepPin2,HIGH);
delayMicroseconds(2000);
digitalWrite(stepPin2,LOW);
delayMicroseconds(2000);
}
Du mußt die Motore an verschiedene Ausgänge anschließen.
Wenn Du die Umschaltung während der Laufzeit machen willst dann mußt Du die kontrolle in anderen Punkten des Sketches machen.
setup()
{
statusschalter =digitalRead (schalter);
if(statusschalter)
{
setup_programm1
}
else
{
setup_programm2
}
}
loop()
{
if(statusschalter)
{
programm1
}
else
{
programm2
}
}