Advertisement
Guest User

Untitled

a guest
Jan 21st, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.80 KB | None | 0 0
  1. #define DBGpin 13
  2.  
  3. #define TXpin 7
  4. #define RETRANSMIT 4
  5.  
  6. int tOneHigh = 250; //275;
  7. int tOneLow = 250; //170;
  8.  
  9. int tZeroHigh = 250;
  10. int tZeroLow = 1250;
  11.  
  12. int tSyncHigh = 250;
  13. int tSyncLow = 2500;
  14.  
  15. int tPauseHigh = 250;
  16. int tPauseLow = 10000;
  17.  
  18. char *dim[15] = {
  19. "01010110",
  20. "01011001",
  21. "01011010",
  22. "01100101",
  23. "01100110",
  24. "01101001",
  25. "01101010",
  26. "10010101",
  27. "10010110",
  28. "10011001",
  29. "10011010",
  30. "10100101",
  31. "10100110",
  32. "10101001",
  33. "10101010"
  34. };
  35.  
  36. char *On1 = "0101010110011001011010101010011001010101010101011001011001010101";
  37.  
  38. void setup() {
  39. pinMode(TXpin, OUTPUT);
  40. pinMode(DBGpin, OUTPUT);
  41. Serial.begin(9600);
  42.  
  43. void loop() {
  44. test();
  45. // group(on);
  46. }
  47.  
  48. void test() {
  49. Serial.println("Turn on #1");
  50. sendPackets(On1);
  51. delay(100);
  52.  
  53. void sendPackets(char *pkt) {
  54. for (int i = 0; i < RETRANSMIT; i++) {
  55. sendPacket(pkt);
  56. }
  57. Serial.println("");
  58. }
  59.  
  60. void sendPacket(char *pkt) {
  61. sendSync();
  62. sendCode(pkt, strlen(pkt));
  63. sendPause();
  64. Serial.println("");
  65. }
  66.  
  67. void sendCode(char *str, int len) {
  68. char *p = str;
  69. int i = 0;
  70. while (i <= len) {
  71. if (*p == '0') {
  72. sendZero();
  73. }
  74. if (*p == '1') {
  75. sendOne();
  76. }
  77. p++;
  78. i++;
  79. }
  80. }
  81.  
  82. void sendZero() {
  83. Serial.print("0");
  84. digitalWrite(TXpin, HIGH);
  85. delayMicroseconds(tZeroHigh);
  86. digitalWrite(TXpin, LOW);
  87. delayMicroseconds(tZeroLow);
  88. }
  89.  
  90. void sendOne() {
  91. Serial.print("1");
  92. digitalWrite(TXpin, HIGH);
  93. delayMicroseconds(tOneHigh);
  94. digitalWrite(TXpin, LOW);
  95. delayMicroseconds(tOneLow);
  96. }
  97.  
  98. // Sync
  99. void sendSync() {
  100. Serial.print("S");
  101. digitalWrite(TXpin, HIGH);
  102. delayMicroseconds(tSyncHigh);
  103. digitalWrite(TXpin, LOW);
  104. delayMicroseconds(tSyncLow);
  105. }
  106.  
  107. // Pause
  108. void sendPause() {
  109. Serial.print("P");
  110. digitalWrite(TXpin, HIGH);
  111. delayMicroseconds(tPauseHigh);
  112. digitalWrite(TXpin, LOW);
  113. delayMicroseconds(tPauseLow);
  114. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement