Advertisement
Alonnso_888

RF q n funciona

Apr 18th, 2019
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const int rfPin = A0;
  2. const int rfTransmitPin = 4;
  3. int led = 13;
  4. int inty;
  5. bool rf_on=true;
  6. bool rf_print=true;
  7. float sensorValue=0;
  8. int RF=0;
  9. String RF_Sinal="0";
  10. int RF_play=false;
  11. int RF_c=2;
  12. bool RF_led=false;
  13. int delayRF=1;
  14.  
  15. void setup() {
  16.  Serial.begin(250000);
  17.  pinMode(led,OUTPUT);
  18.  pinMode(rfTransmitPin, OUTPUT);  
  19. }
  20.  
  21. void loop() {
  22.   sensorValue= analogRead(rfPin);
  23.  
  24.   //Serial.print("Voltage output = ");
  25.   //Serial.println(sensorValue*5/1023);
  26.   if(rf_on){
  27.     RF=(sensorValue*5/1023);
  28.     RF_Sinal=(RF_Sinal+String(RF));
  29.     Serial.println(RF_Sinal);
  30.     //delay(50);
  31.   }
  32.   if(RF_Sinal.length()==100 & rf_on){
  33.     //Serial.print("Characers:");
  34.     //Serial.print(String(RF_Sinal[2])+String(RF_Sinal[3])+String(RF_Sinal[4]));
  35.     rf_on=false;
  36.     RF_play=true;
  37.     Serial.println("");
  38.     Serial.println("RF = "+RF_Sinal);
  39.     Serial.println("INIT...");
  40.   }
  41.   if(RF_play){
  42.     //digitalWrite(led, HIGH);
  43.     Serial.println(delayRF);
  44.     if(RF_c <= 100){
  45.       //Serial.println("<=100");
  46.       //Serial.println(RF_c+" = "+RF_Sinal[3]);
  47.       //Serial.println(RF_Sinal[RF_c]);
  48.       //digitalWrite(rfTransmitPin, HIGH);
  49.     if(String(RF_Sinal[RF_c])=="2" or String(RF_Sinal[RF_c])=="1"){
  50.       Serial.println("RF_Sinal ON");
  51.       digitalWrite(rfTransmitPin, HIGH);
  52.       //digitalWrite(led, HIGH);
  53.       delay(delayRF);
  54.       RF_c++;
  55.     }if(String(RF_Sinal[RF_c])=="0"){
  56.       Serial.println("RF_Sinal OFF");
  57.       digitalWrite(rfTransmitPin, LOW);
  58.       //digitalWrite(led, LOW);
  59.       delay(delayRF);
  60.       RF_c++;
  61.     }else{
  62.       RF_c=2;
  63.       delayRF++;
  64.     }
  65.    }
  66.  }
  67.  if(rfTransmitPin==HIGH){
  68.   digitalWrite(led, HIGH);
  69.  }else{
  70.   digitalWrite(led, LOW);
  71.  }
  72.  
  73.   if (sensorValue > 1000){
  74.     inty++;
  75.   }else{
  76.     inty=0;
  77.   }
  78.   if(inty >= 4){
  79.     //digitalWrite(led,HIGH);
  80.   }else{
  81.     //digitalWrite(led,LOW);
  82.   }/*
  83.   if(RF==2){
  84.     digitalWrite(rfTransmitPin, HIGH);  
  85.   }else{
  86.     digitalWrite(rfTransmitPin, LOW);
  87.   }*/
  88.   //delay(50);
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement