igendel

QRing Receiver Code

Apr 8th, 2021
418
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // by Ido Gendel, 2021
  2. // For the Arduino Micro
  3.  
  4. #include <Keyboard.h>
  5.  
  6. #define MAX_WAIT 25U
  7. #define BUFFER_SIZE 1000U
  8.  
  9. char data[BUFFER_SIZE];
  10. uint16_t bufIndex = 0;
  11. uint32_t stamp = 0;
  12.  
  13. void setup() {
  14.  
  15.   Serial1.begin(57600);
  16.   Serial.begin(115200); // For debugging
  17.   Keyboard.begin();
  18.   stamp = millis();
  19.  
  20. }
  21.  
  22. void loop() {
  23.  
  24.   char c;
  25.  
  26.   while (0 == Serial1.available()) {
  27.  
  28.     if (bufIndex && (millis() - stamp >= MAX_WAIT)) {
  29.      
  30.       data[bufIndex] = 13;
  31.       data[bufIndex+1] = 10;
  32.       data[bufIndex+2] = 0;
  33.       Keyboard.print(data);
  34.       bufIndex = 0;
  35.      
  36.     }
  37.    
  38.   }
  39.  
  40.   while (Serial1.available()) {
  41.    
  42.     c = Serial1.read();
  43.     // Serial.println((byte)c); // For debugging
  44.     if (c > 31) {
  45.       data[bufIndex++] = c;
  46.     }
  47.     stamp = millis();      
  48.    
  49.   }
  50.  
  51. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×