Advertisement
Guest User

Untitled

a guest
Nov 13th, 2018
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. // RTI_RGB = 0x40, RTI_PAL = 0x45, RTI_NTSC = 0x4C, RTI_OFF = 0x46
  2. // brightness levels 0x20, 0x61, 0x62, 0x23, 0x64, 0x25, 0x26, 0x67, 0x68, 0x29, 0x2A, 0x2C, 0x6B, 0x6D, 0x6E, 0x2F
  3.  
  4. #define R_PIN 3
  5. #define AUTO_CLOSE_PIN 5
  6. #define SERIAL_SWITCH_PIN 4
  7.  
  8. bool zpatecka_on = false;
  9.  
  10. int x=0;
  11.  
  12. void setup()
  13. {
  14. Serial.begin(2400);
  15.  
  16. //nastavi pin na 1
  17. pinMode(R_PIN, INPUT_PULLUP);
  18. attachInterrupt(digitalPinToInterrupt(R_PIN), preruseni, CHANGE);
  19. }
  20.  
  21. void loop()
  22. {
  23.  
  24. if (zpatecka_on == true){
  25. zpateckaOn();
  26. if (digitalRead(AUTO_CLOSE_PIN) == LOW){
  27. x==1;
  28. }
  29. }
  30. else
  31. {
  32. zpateckaOff();
  33. }
  34.  
  35. }
  36.  
  37. void preruseni()
  38. {
  39. //if (zpatecka_on == false){
  40.  
  41. if (digitalRead(R_PIN) == HIGH)
  42. {
  43. zpatecka_on = true;
  44. }
  45. else
  46. {
  47. zpatecka_on=false;
  48.  
  49. }
  50. }
  51.  
  52. void zpateckaOn()
  53. {
  54. rtiWrite(0x4C);
  55. rtiWrite(0x6B);
  56. rtiWrite(0x83);
  57. digitalWrite(SERIAL_SWITCH_PIN, HIGH);
  58.  
  59. }
  60.  
  61. void zpateckaOff()
  62. {
  63. // Kod po vyrazeni zpatecky
  64. if (digitalRead(AUTO_CLOSE_PIN) == HIGH)
  65. {
  66. rtiWrite(0x46);
  67. rtiWrite(0x6B);
  68. rtiWrite(0x83);
  69. digitalWrite(SERIAL_SWITCH_PIN, LOW);
  70. }
  71. else if (digitalRead(AUTO_CLOSE_PIN) == LOW and x==1)
  72. {
  73. rtiWrite(0x40);
  74. rtiWrite(0x6B);
  75. rtiWrite(0x83);
  76. digitalWrite(SERIAL_SWITCH_PIN, LOW);
  77. x==0;
  78. }
  79. }
  80.  
  81. void rtiWrite(char byte) {
  82. Serial.print(byte);
  83. delay(100);
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement