Test version 5

parent 77d2cff9
......@@ -104,13 +104,18 @@ void setup() {
pinMode(BUT2_PIN, INPUT_PULLUP);
pinMode(LED_PIN, OUTPUT);
pinMode(WREN_PIN, OUTPUT);
digitalWrite(LED_PIN,LOW);
digitalWrite(LED_PIN,LOW);
ADDR = (digitalRead(ADDR3_PIN)<<3) | (digitalRead(ADDR2_PIN)<<2) | (digitalRead(ADDR1_PIN)<<1) | (digitalRead(ADDR0_PIN)) ;
if(ADDR == MASTER_ADDR){
digitalWrite(WREN_PIN,HIGH); // para o transciever do master possa enviar
}else
digitalWrite(WREN_PIN,LOW); //para os slaves receberem
asynch9_init(BAUD);
}
......@@ -119,21 +124,21 @@ void loop() {
// put your main code here, to run repeatedly:
// Master
if(ADDR == MASTER_ADDR){
digitalWrite(WREN_PIN,HIGH); // para o transciever do master possa enviar
lastButtonState1 = buttonState1;
lastButtonState2 = buttonState2;
buttonState1 = digitalRead(BUT1_PIN);
buttonState2 = digitalRead(BUT2_PIN);
if(buttonState1 != lastButtonState1){
if(buttonState1 == LOW){
if(buttonState1 == 0){
if(last_ADDR == SLAVE1_ADDR){
send_data(15);
send_data(1);
} else {
send_addr(SLAVE1_ADDR);
send_data(15);
send_data(1);
last_ADDR = SLAVE1_ADDR;
}
}
}else if(buttonState1 != lastButtonState1){ //quando o button é libertado
if(buttonState1 == HIGH){
}else if(buttonState1 == 1){
if(last_ADDR == SLAVE1_ADDR){
send_data(0);
} else {
......@@ -142,20 +147,20 @@ void loop() {
last_ADDR = SLAVE1_ADDR;
}
}
}
lastButtonState1 = buttonState1;
if(buttonState2 != lastButtonState2){
if(buttonState2 == LOW){
if(buttonState2 == 0){
if(last_ADDR == SLAVE2_ADDR){
send_data(15);
send_data(1);
} else {
send_addr(SLAVE2_ADDR);
send_data(15);
send_data(1);
last_ADDR = SLAVE2_ADDR;
}
}
}else if(buttonState2 != lastButtonState2){
if(buttonState2 == HIGH){
}else if(buttonState2 == 1){
if(last_ADDR == SLAVE2_ADDR){
send_data(0);
} else {
......@@ -164,8 +169,8 @@ void loop() {
last_ADDR = SLAVE2_ADDR;
}
}
}
lastButtonState2 = buttonState2;
}
//slaves
......@@ -178,11 +183,7 @@ void loop() {
}else if(getData == 1 && ADDR != *data){
UCSR0A |= (1<<MPCM0); //senao for o seu endereco continuar a ouvir "addr"
}
/* if(*data == 15 && getData == 0)
digitalWrite(LED_PIN, HIGH);
if(*data == 0 && getData == 0)
digitalWrite(LED_PIN, LOW);
*/
if(getData==0)
digitalWrite(LED_PIN,*data);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment