Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- transmitter //pro mini// קודן
- rf to pin 12
- */
- #include <RH_ASK.h>
- #include <SPI.h> // Not actually used but needed to compile
- #include <EEPROM.h>
- #define RED_LED 9
- #define GREEN_LED 8
- #define NO1 A1
- #define NO2 A2
- #define NO3 A3
- #define NO4 A4
- bool OffCamera = false; //false = camera on //true = camera off
- int number;
- int x = 0;
- int Restart = 0;
- int code[6];
- int EEprom = 0;
- int y = 0;
- unsigned long TIME;
- void setup() {
- code[0] = EEPROM.read(0);
- code[1] = EEPROM.read(1);
- code[2] = EEPROM.read(2);
- code[3] = EEPROM.read(3);
- code[4] = EEPROM.read(4);
- code[5] = EEPROM.read(5);
- Serial.begin(9600); // Debugging only
- if (!driver.init())
- Serial.println("init failed");
- /* //enter the code //do only once And reburn without it
- EEPROM.write(0,1);
- EEPROM.write(1,1);
- EEPROM.write(2,1);
- EEPROM.write(3,1);
- EEPROM.write(4,1);
- EEPROM.write(5,1);
- */
- /* //print the code
- for(int i = 0; i<6; i++){
- Serial.println(code[i]);
- delay(1000);
- }
- */
- pinMode(NO1, INPUT_PULLUP);
- pinMode(NO2, INPUT_PULLUP);
- pinMode(NO3, INPUT_PULLUP);
- pinMode(NO4, INPUT_PULLUP);
- pinMode(GREEN_LED, OUTPUT); //green led
- pinMode(RED_LED , OUTPUT); //red led
- }
- void loop() {
- checkForPressedNumber(); //Check if code is entered //OffCamera - false = camera on //true = camera off
- if (x > 5) Check_if_the_code_is_correct(); //Checks if the code is correct
- if ( Restart > 5) Check_6_pressed(); //check 6 pressed for reset the code
- if (Restart > 0) { //Check how much time has passed from the last pressde
- if ( millis() - TIME >= 3000) { //Checks if 3 seconds have passed, last click
- tooMuchTime();
- }
- }
- }
- //Check if code is entered
- void checkForPressedNumber() {
- if (analogRead(NO1) < 500) number = 1;
- if (analogRead(NO2) < 500) number = 2;
- if (analogRead(NO3) < 500) number = 3;
- if (analogRead(NO4) < 500) number = 4;
- while (analogRead(NO1) < 500 || analogRead(NO2) < 500 || analogRead(NO3) < 500 || analogRead(NO4) < 500) {
- TIME = millis();
- delay(10); //wait
- digitalWrite(GREEN_LED , HIGH);
- }
- delay(50);
- if (number != 0) { //enter Once when one of the button is pressed
- tone(11, 600, 80);
- if (code[Restart] == number)x++; //check if the number is correct
- Restart++;
- //Serial.println(x);
- //Serial.println(Restart);
- digitalWrite(GREEN_LED , LOW);
- }
- number = 0;
- }
- //if the code is correct //Do what is here
- void Check_if_the_code_is_correct() {
- digitalWrite(GREEN_LED, HIGH);
- delay(300); //open
- tone(11, 300, 1000);
- Serial.println("open");
- OffCamera = true; //false = camera on //true = camera off
- x = 0;
- EEprom = 1;
- Restart = 0;
- }
- //if the code is correct //Do what is here
- void Check_6_pressed() {
- Restart = 0;
- x = 0;
- delay(300);
- tone(11, 600, 75);
- digitalWrite(RED_LED, HIGH);
- delay(100);
- tone(11, 600, 75);
- delay(400);
- digitalWrite(RED_LED, LOW);
- }
- //too much time has passed since the last pressed
- void tooMuchTime() {
- x = 0;
- Restart = 0;
- delay(300);
- tone(11, 600, 75);
- digitalWrite(RED_LED, HIGH);
- delay(100);
- tone(11, 600, 75);
- delay(400);
- digitalWrite(RED_LED, LOW);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement