i dit read this link
http://forum.arduino.cc/index.php?topic=396450
but i dont know if the solution to my problem is in there, i could not really find it
for the pins, i did almost use them all, the only digital IO pins i have left are 8-13. but all my analog pins are not used. as for my rx/tx pins, theyre not used either.
as for the code that i'm using right now this is the pure basics for the mega:
void setup() {
pinMode(8,OUTPUT);
pinMode(9,OUTPUT);
pinMode(10,OUTPUT);
pinMode(11,OUTPUT);
Serial.begin(9600);
}
void loop() {
digitalWrite(8,HIGH); //S1 open
digitalWrite(9,LOW);
digitalWrite(10,LOW);
digitalWrite(11,LOW);
Serial.println("S1 open");
delay(500);
digitalWrite(8,LOW); //S2 Open
digitalWrite(9,LOW);
digitalWrite(10,HIGH);
digitalWrite(11,LOW);
Serial.println("S2 open");
delay(500);
digitalWrite(8,HIGH); // S3 Open
digitalWrite(9,HIGH);
digitalWrite(10,LOW);
digitalWrite(11,LOW);
Serial.println("S3 open");
delay(500);
digitalWrite(8,HIGH); //S4 Open
digitalWrite(9,LOW);
digitalWrite(10,LOW);
digitalWrite(11,HIGH);
Serial.println("S4 open");
delay(500);
digitalWrite(8,LOW); //S1 close
digitalWrite(9,HIGH);
digitalWrite(10,LOW);
digitalWrite(11,LOW);
Serial.println("S1 close");
delay(500);
digitalWrite(8,LOW); //S2 close
digitalWrite(9,LOW);
digitalWrite(10,LOW);
digitalWrite(11,HIGH);
Serial.println("S2 close");
delay(500);
digitalWrite(8,HIGH); // S3 close
digitalWrite(9,LOW);
digitalWrite(10,HIGH);
digitalWrite(11,LOW);
Serial.println("S3 close");
delay(500);
digitalWrite(8,LOW); // S4 close
digitalWrite(9,HIGH);
digitalWrite(10,HIGH);
digitalWrite(11,LOW);
Serial.println("S4 close");
delay(500);
}
it is just to send a High or a low to a pin on the UNO, then the UNO tells which motor has to to wath with the following code
#include <Servo.h>
Servo servo1;
Servo servo2;
Servo servo3;
Servo servo4;
int pin2waarde;
int pin4waarde;
int pin7waarde;
int pin8waarde;
int pin2 = 2;
int pin4 = 4;
int pin7 = 7;
int pin8 = 8;
void setup() {
servo1.attach(6);
servo2.attach(9);
servo3.attach(10);
servo4.attach(11);
pinMode(pin2,INPUT);
pinMode(pin4,INPUT);
pinMode(pin7,INPUT);
pinMode(pin8,INPUT);
servo1.write(0);
servo2.write(0);
servo3.write(0);
servo4.write(0);
Serial.begin(9600);
}
void loop() {
pin2waarde=digitalRead(pin2);
pin4waarde=digitalRead(pin4);
pin7waarde=digitalRead(pin7);
pin8waarde=digitalRead(pin8);
if(pin2waarde != LOW|| pin4waarde != LOW ||pin7waarde != LOW ||pin8waarde != LOW ){
if(pin2waarde==HIGH && pin7waarde ==LOW && pin4waarde==LOW && pin8waarde==LOW){
servo1.write(0);
}
if(pin4waarde==HIGH && pin2waarde == LOW && pin7waarde==LOW && pin8waarde ==LOW){
servo1.write(180);
}
if(pin7waarde==HIGH && pin2waarde==LOW && pin4waarde==LOW && pin8waarde == LOW){
servo2.write(0);
}
if(pin8waarde==HIGH && pin2waarde==LOW && pin7waarde==LOW && pin4waarde==LOW){
servo2.write(180);
}
if(pin2waarde==HIGH && pin4waarde==HIGH && pin7waarde==LOW && pin8waarde == LOW){
servo3.write(0);
}
if(pin2waarde==HIGH && pin7waarde ==HIGH && pin8waarde == LOW && pin4waarde==LOW){
servo3.write(180);
}
if(pin2waarde==HIGH&& pin8waarde ==HIGH && pin7waarde==LOW && pin4waarde==LOW){
servo4.write(0);
}
if(pin4waarde==HIGH && pin7waarde == HIGH && pin8waarde == LOW && pin2waarde==LOW){
servo4.write(180);
}
}
delay(250);
}
it is probably quite long for what it should do and it might be a project above my programming level/experience but it works this way. the only problem im having are "ghost" signals, sometime it just randomly opens/closes a servo so i thought the TX/RX communication would be a better idea buti have 0 experience with that sort of coding and i have no idea how to aproach it