Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- String purple = "00111100111100001111000011000011000011000011001111000011000011";
- //
- volatile bool received = false;
- volatile unsigned long timings[25];
- volatile static int i = 0;
- void handler()
- {
- static unsigned long duration = 0;
- static unsigned long lastTime = 0;
- // static int i = 0;
- static bool sync1 = false; // wykrycie synchronizacji
- if (received == true)
- {
- return;
- }
- long time = micros();
- duration = time - lastTime;
- lastTime = time;
- if ( duration > 1800 && duration < 2000)
- {
- sync1 = true;
- }
- if (sync1 == true)
- {
- i = (i + 1);
- timings[i] = duration;
- if ( duration > 2000)
- {
- received = true;
- sync1 = false;
- }
- }
- }
- void setup()
- {
- Serial.begin(9600);
- Serial.println("Start");
- pinMode(2, INPUT_PULLUP);
- attachInterrupt(digitalPinToInterrupt(2), handler, CHANGE);
- }
- void loop()
- {
- String bitcode;
- String code;
- if (received == true)
- {
- detachInterrupt(digitalPinToInterrupt(2));
- for(unsigned int a=2; a < i ; a++ )
- {
- if ( a%2 == 0)
- {
- if( timings[a] > 180 && timings[a] < 320)
- {
- bitcode = "00" ;
- code = code + String(bitcode);
- }
- else if(timings[a] > 400 && timings[a] < 700)
- {
- bitcode = "0000" ;
- code = code + String(bitcode);
- }
- }
- else if( a%2 !=0)
- {
- if( timings[a] > 180 && timings[a] < 320)
- {
- bitcode = "11" ;
- code = code + String(bitcode);
- }
- else if(timings[a] > 400 && timings[a] < 700)
- {
- bitcode = "1111" ;
- code = code + String(bitcode);
- }
- }
- }
- Serial.println(code);
- if(code == purple)
- {
- Serial.println("receive ok");
- }
- delay(3000);
- received = false;
- attachInterrupt(digitalPinToInterrupt(2), handler, CHANGE);
- i=0;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement