Advertisement
Guest User

Untitled

a guest
Nov 25th, 2021
75
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #define CYCLE       1000
  2. #define W_0         600
  3. #define W_1         400
  4.  
  5. #define INTRO_1     1500
  6. #define INTRO_0     1500
  7.  
  8. #define OUTRO_1     1500
  9.  
  10.  
  11. void report(int pin, unsigned long count)
  12. {
  13.     char msg[16] = {'T', 'Z', 'S', 0x04, 'C', 'o', 'u', 'n', 't', ':'};
  14.     msg[10] = (count >> 8) & 0xff;
  15.     msg[11] = count & 0xff;
  16.     send_msg(pin, msg, 12);
  17. }
  18.  
  19. void send_msg(int pin, char * bp, int n)
  20. {
  21.     intro(pin);
  22.     send_bytes(pin, bp, n);
  23.     //outro(pin);
  24. }
  25.  
  26. void send_bytes(int pin, char * bp, int n)
  27. {
  28.     while (n-- > 0) {
  29.         int b = *bp++ & 0xff;
  30.         int m = 0x80;
  31.         while (m != 0) {
  32.             int w = (b & m) ? W_1 : W_0;
  33.             digitalWrite(pin, HIGH);
  34.             delayMicroseconds(w);
  35.             digitalWrite(pin, LOW);
  36.             delayMicroseconds(CYCLE-w);
  37.             m >>= 1;
  38.         }
  39.     }
  40. }
  41.  
  42. void intro(int pin)
  43. {
  44.     digitalWrite(pin, HIGH);
  45.     delayMicroseconds(INTRO_1);
  46.     digitalWrite(pin, LOW);
  47.     delayMicroseconds(INTRO_0);
  48. }
  49.  
  50. void outro(int pin)
  51. {
  52.     digitalWrite(pin, HIGH);
  53.     delayMicroseconds(OUTRO_1);
  54.     digitalWrite(pin, LOW);
  55. }
  56.  
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement