Vanemate ringitund 31.05.17

ARDUINO

Saatja ja vastuvõtja
Kui saatja poolel vajutada nuppu, siis vastuvõtja poolel läheb lamp põlema.

Saatja nupuga

#define rfTransmitPin 4
#define ledPin 13
#define buttonPin 2
int buttonState = 0;
void setup() {
  pinMode(rfTransmitPin, OUTPUT);
  pinMode(ledPin, OUTPUT);
  pinMode(buttonPin, INPUT);
}
void loop() {
  buttonState = digitalRead(buttonPin);
  if (buttonState == HIGH) {
    digitalWrite(rfTransmitPin, HIGH);
    digitalWrite(ledPin, HIGH);
  } else {
    digitalWrite(rfTransmitPin, LOW);
    digitalWrite(ledPin, LOW);
  }
}

Vastuvõtja lambiga

#define rfReceivePin A0  //RF Receiver pin = Analog pin 0
 #define ledPin 13        //Onboard LED = digital pin 13
 unsigned int data = 0;   // variable used to store received data
 const unsigned int upperThreshold = 70;  //upper threshold value
 const unsigned int lowerThreshold = 50;  //lower threshold value
 void setup(){
   pinMode(ledPin, OUTPUT);
   Serial.begin(9600);
 }
 void loop(){
   data=analogRead(rfReceivePin);    //listen for data on Analog pin 0
    if(data>upperThreshold){
     digitalWrite(ledPin, LOW);   //If a LOW signal is received, turn LED OFF
     Serial.println(data);
   }
   if(data<lowerThreshold){
     digitalWrite(ledPin, HIGH);   //If a HIGH signal is received, turn LED ON
     Serial.println(data);
   }
 }