Hi,
so i just started to program with arduino. My program consists of 2 arduino boards (Micro) and a (Leonardo + Ethernet Shield ( later for php))....
So i want to put 2 Reed and 2 magnets (1 on the top, 1 on the bottom of the window) between the window so i can see if the window is closed, tilted or open.
This information should be gathered from the Arduino Micro and should be send to the Leonardo. Unforunatly my skript has some mistakes but i dont find them...
I am new to Arduino programing and i would really appreciate it if you could look at my skript and help me.
Slave Code
//i2c Slave (Micro)
#include <Wire.h>
int Window_Led_Pin1 = 13;
//int Window_Led_Pin2 = 12;
int Window_Top_Pin = 6;
int Window_Bot_Pin = 5;
int val = Serial.read() - '0';
int x = 0;
void setup() {
pinMode(Window_Led_Pin1, OUTPUT);
pinMode(Window_Led_Pin1, OUTPUT);
pinMode(Window_Top_Pin, INPUT);
pinMode(Window_Bot_Pin, INPUT);
Wire.begin(5);
Wire.onRequest(requestEvent);
}
void loop()
{
while (digitalRead(Window_Bot_Pin))
{
Serial.println("Das Fenster ist gekippt");
digitalWrite(Window_Led_Pin1, HIGH);
x = 1;
}
if(!digitalRead(Window_Top_Pin))
{
digitalWrite(Window_Led_Pin1, LOW);
}
while (digitalRead(Window_Top_Pin))
{
Serial.println("Das Fenster ist geschlossen");
digitalWrite(Window_Led_Pin1, HIGH);
x = 2;
}
if(!digitalRead(Window_Bot_Pin))
{
digitalWrite(Window_Led_Pin1, LOW);
Serial.println("Das Fenster ist offen");
x = 3;
}
}
void requestEvent()
{
if (x == 1)
{
Wire.write ("Das Fenster ist gekippt");
}
if (x == 2)
{
Wire.write ("Das Fenster ist geschlossen");
}
if (x == 3)
{
Wire.write ("Das Fenster ist offen");
}
}
//i2c Master (Leonardo + Ethernet Shield)
#include <Wire.h>
void setup()
{
Wire.begin();
Serial.begin(9600);
}
void loop()
{
Wire.requestFrom(5);
while(Wire.available())
{
char c = Wire.read();
Serial.print(c);
}
delay(500);
}