SHARE
TWEET

Untitled

a guest Oct 23rd, 2019 65 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.   transmitter //pro mini// קודן
  3.   rf to pin 12
  4. */
  5. #include <RH_ASK.h>
  6. #include <SPI.h> // Not actually used but needed to compile
  7. #include <EEPROM.h>
  8.  
  9. #define RED_LED 9
  10. #define GREEN_LED 8
  11. #define NO1 A1
  12. #define NO2 A2
  13. #define NO3 A3
  14. #define NO4 A4
  15.  
  16. bool OffCamera = false; //false = camera on //true = camera off
  17.  
  18. int number;
  19. int x = 0;
  20. int Restart = 0;
  21. int code[6];
  22. int EEprom = 0;
  23. int y = 0;
  24. unsigned long TIME;
  25.  
  26. void setup() {
  27.     code[0] = EEPROM.read(0);
  28.     code[1] = EEPROM.read(1);
  29.     code[2] = EEPROM.read(2);
  30.     code[3] = EEPROM.read(3);
  31.     code[4] = EEPROM.read(4);
  32.     code[5] = EEPROM.read(5);
  33.  
  34.   Serial.begin(9600);    // Debugging only
  35.   if (!driver.init())
  36.     Serial.println("init failed");
  37.   /* //enter the code //do only once And reburn without it
  38.     EEPROM.write(0,1);
  39.     EEPROM.write(1,1);
  40.     EEPROM.write(2,1);
  41.     EEPROM.write(3,1);
  42.     EEPROM.write(4,1);
  43.     EEPROM.write(5,1);
  44.   */
  45.  
  46.  
  47.   /* //print the code
  48.   for(int i = 0; i<6; i++){
  49.     Serial.println(code[i]);
  50.     delay(1000);
  51.     }
  52.   */
  53.   pinMode(NO1, INPUT_PULLUP);
  54.   pinMode(NO2, INPUT_PULLUP);
  55.   pinMode(NO3, INPUT_PULLUP);
  56.   pinMode(NO4, INPUT_PULLUP);
  57.   pinMode(GREEN_LED, OUTPUT); //green led
  58.   pinMode(RED_LED , OUTPUT); //red led
  59. }
  60.  
  61.  
  62. void loop() {
  63.  
  64.   checkForPressedNumber(); //Check if code is entered //OffCamera - false = camera on //true = camera off
  65.  
  66.   if (x > 5) Check_if_the_code_is_correct(); //Checks if the code is correct
  67.  
  68.   if ( Restart > 5) Check_6_pressed(); //check 6 pressed for reset the code
  69.  
  70.   if (Restart > 0) { //Check how much time has passed from the last pressde
  71.     if ( millis() - TIME >= 3000) { //Checks if 3 seconds have passed, last click
  72.       tooMuchTime();
  73.     }
  74.   }
  75. }
  76.  
  77. //Check if code is entered
  78. void checkForPressedNumber() {
  79.   if (analogRead(NO1) < 500) number = 1;
  80.   if (analogRead(NO2) < 500) number = 2;
  81.   if (analogRead(NO3) < 500) number = 3;
  82.   if (analogRead(NO4) < 500) number = 4;
  83.   while (analogRead(NO1) < 500 || analogRead(NO2) < 500 || analogRead(NO3) < 500 || analogRead(NO4) < 500) {
  84.     TIME = millis();
  85.     delay(10); //wait
  86.     digitalWrite(GREEN_LED , HIGH);
  87.   }
  88.   delay(50);
  89.  
  90.   if (number != 0) { //enter Once when one of the button is pressed
  91.     tone(11, 600, 80);
  92.     if (code[Restart] == number)x++; //check if the number is correct
  93.     Restart++;
  94.     //Serial.println(x);
  95.     //Serial.println(Restart);
  96.     digitalWrite(GREEN_LED , LOW);
  97.   }
  98.   number = 0;
  99. }
  100.  
  101. //if the code is correct //Do what is here
  102. void Check_if_the_code_is_correct() {
  103.   digitalWrite(GREEN_LED, HIGH);
  104.   delay(300);                      //open
  105.   tone(11, 300, 1000);
  106.   Serial.println("open");
  107.   OffCamera = true; //false = camera on //true = camera off
  108.  
  109.   x = 0;
  110.   EEprom = 1;
  111.   Restart = 0;
  112. }
  113.  
  114. //if the code is correct //Do what is here
  115. void Check_6_pressed() {
  116.   Restart = 0;
  117.   x = 0;
  118.   delay(300);
  119.   tone(11, 600, 75);
  120.   digitalWrite(RED_LED, HIGH);
  121.   delay(100);
  122.   tone(11, 600, 75);
  123.   delay(400);
  124.   digitalWrite(RED_LED, LOW);
  125. }
  126.  
  127. //too much time has passed since the last pressed
  128. void tooMuchTime() {
  129.   x = 0;
  130.   Restart = 0;
  131.   delay(300);
  132.   tone(11, 600, 75);
  133.   digitalWrite(RED_LED, HIGH);
  134.   delay(100);
  135.   tone(11, 600, 75);
  136.   delay(400);
  137.   digitalWrite(RED_LED, LOW);
  138. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top