I am trying to built an elevator/ lift using 3 or more anduino uno's and 1 mega(as maser).
uno:
I have connected 1 ir sensor, 1 button, 1 led and 1 7- segment display to the uno.
if i press the button the led will light up and stays like that until the ir sensor detects the elevator cage. then the led will turn off and the 7 -segment display will show to floor number.
master:
the master is used for the stepper motor and a keypad.
what the master has to do is ask the slaves in this case the uno's about whether the button is pressed or not.
senario:
cage is at floor 2 and is detected by ir senor. if I press the button at floor 2 the mega must know that the cage is already there. And if I press the button at floor 3 the mega must know that the cage is at floor 2 and that the button at floor 3 is press. and the it must control the motor to bring the cage to floor 3 and show on the 7- segment display.
I must use i2c
I am sorry if it's hard to understand the text. My Enlish is not good.
this is the code for the uno:
#include<arduino.h>
const int dataPin = 11; // wire to 74HC595 pin 11
const int latchPin = 8; // to 74HC595 pin 8
const int clockPin = 12; // to 74HC595 pin 12
int nummers[6] = {126, 12, 182, 158, 204, 204}; //0, 1, 2, 3, 4, 5
int buttonvalue = 0;
int button = 2;
int buttonLed = 3;
// ir sensor and irleds
int irLedGreen = 5;
int irLedRed = 6;
#define IR 4
int detect = 0;
void setup() {
Serial.begin(9600);
//ir sensor
pinMode(irLedGreen, OUTPUT);
pinMode(IR, INPUT);
pinMode(irLedRed, OUTPUT);
//shift out
pinMode(dataPin, OUTPUT);
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
//button
pinMode(button, INPUT);
pinMode(buttonLed, OUTPUT);
}
void loop() {
buttonvalue = digitalRead(button);
detect = digitalRead(IR);
//ir sensor led. It will be green if it detects something else it will be red.
if (detect == LOW) // if if detects something do the following.
{
digitalWrite(irLedGreen, HIGH);
digitalWrite(irLedRed, LOW);
} else {
digitalWrite(irLedGreen, LOW);
digitalWrite(irLedRed, HIGH);
}
if (buttonvalue != 0 ) // button is pressed
{
digitalWrite(buttonLed, HIGH);
Serial.println("button");
}
else if (detect == LOW) {
digitalWrite(buttonLed, LOW);
digitalWrite(latchPin, LOW); // prepare shift register for data
shiftOut(dataPin, clockPin, MSBFIRST, nummers[4]); // send data
digitalWrite(latchPin, HIGH); // update display
Serial.println("obstakel");
}
digitalWrite(latchPin, LOW); // prepare shift register for data
shiftOut(dataPin, clockPin, MSBFIRST, nummers[0]); // send data
digitalWrite(latchPin, HIGH); // update display
}