I'm building a project for school.
In that project I would like to have one Arduino to control multiple arduino's (up to 4). Those 'slaves' than control an H-Bridge to control 2 motors seperatly.
What I've managed so far is to make the H-Bridge and set 1 one motor to react like I want with the following sketch.
//const int switchPin = 2; // switch input
const int motor1Pin = 3; // H-bridge leg 1 (pin 2, 1A)
const int motor2Pin = 4; // H-bridge leg 2 (pin 7, 2A)
const int enablePin = 9; // H-bridge enable pin
void setup() {
// set the switch as an input:
//pinMode(switchPin, INPUT);
Serial.begin(9600);
// set all the other pins you're using as outputs:
pinMode(motor1Pin, OUTPUT);
pinMode(motor2Pin, OUTPUT);
pinMode(enablePin, OUTPUT);
// set enablePin high so that motor can turn on
digitalWrite(enablePin, LOW);
}
void loop(){
// go
digitalWrite(enablePin, HIGH);
digitalWrite(motor1Pin, HIGH); // set leg 1 of the H-bridge high
digitalWrite(motor2Pin, LOW); // set leg 2 of the H-bridge low
delay(2000);
Serial.println("1");
// break1
digitalWrite(enablePin, LOW);
digitalWrite(motor1Pin, LOW); // set leg 1 of the H-bridge low
digitalWrite(motor2Pin, LOW); // set leg 2 of the H-bridge high
Serial.println("2");
delay(300);
digitalWrite(enablePin, HIGH);
digitalWrite(motor1Pin, LOW); // set leg 1 of the H-bridge low
digitalWrite(motor2Pin, HIGH); // set leg 2 of the H-bridge high
Serial.println("3");
delay(300);
digitalWrite(enablePin, LOW);
digitalWrite(motor1Pin, LOW); // set leg 1 of the H-bridge low
digitalWrite(motor2Pin, LOW); // set leg 2 of the H-bridge high
delay(3000);
digitalWrite(enablePin, HIGH);
digitalWrite(motor1Pin, LOW); // set leg 1 of the H-bridge low
digitalWrite(motor2Pin, HIGH); // set leg 2 of the H-bridge high
delay(300);
digitalWrite(enablePin, LOW);
digitalWrite(motor1Pin, LOW); // set leg 1 of the H-bridge low
digitalWrite(motor2Pin, LOW); // set leg 2 of the H-bridge high
delay(2000);
digitalWrite(enablePin, LOW);
digitalWrite(motor1Pin, LOW); // set leg 1 of the H-bridge low
digitalWrite(motor2Pin, LOW); // set leg 2 of the H-bridge high
delay(300);
// back
digitalWrite(enablePin, HIGH);
digitalWrite(motor1Pin, LOW); // set leg 1 of the H-bridge high
digitalWrite(motor2Pin, HIGH); // set leg 2 of the H-bridge low
delay(2000);
// break2
digitalWrite(enablePin, LOW);
digitalWrite(motor1Pin, LOW); // set leg 1 of the H-bridge low
digitalWrite(motor2Pin, LOW); // set leg 2 of the H-bridge high
delay(10000);
}
I've put this in project guidance to get as much guidance as could be.
To first come up with a way to make my system work with the arduino's. (looked up on I2C, but didn't find a clean easy tutorial, for a beginner like me, alternatives)
Second how to control 2 motors separately of the H-Bridge with the former sketch.
Than I would try program the master arduino, to command arduino 3 and 1 for example to control their motor with the above sketch.
Hope it's clear to everybody what I'm trying to build.