LAK132 icon

XT test plotter poll low

LAK132 | PRO | 10/02/20 06:49:28 AM UTC (Edited) | 0 ⭐ | 371 👁️ | Never ⏰ | []
C++ |

1.48 KB

|

None

|

0 👍

/

0 👎

#include <Arduino.h>
#include <HardwareSerial.h>
 
#define systemRequest 84
#define modCode       96
#define altModCode    97
 
#define CLOCK_PIN  10
#define DATA_PIN   23
#define SWITCH_PIN 22
 
#define CLOCK digitalRead(CLOCK_PIN)
#define DATA  digitalRead(DATA_PIN)
 
void setup()
{
  Serial.begin(19200);
  Serial.println("Connected");
  pinMode(CLOCK_PIN, INPUT);
  pinMode(DATA_PIN, INPUT);
  pinMode(SWITCH_PIN, OUTPUT);
  digitalWrite(SWITCH_PIN, LOW);
  Keyboard.set_modifier(0);
  Keyboard.set_key1(0);
  Keyboard.set_key2(0);
  Keyboard.set_key3(0);
  Keyboard.set_key4(0);
  Keyboard.set_key5(0);
  Keyboard.set_key6(0);
  Keyboard.send_now();
  while (CLOCK == LOW)
    ;
}
 
const int max_buffer   = 100;
int buffer[max_buffer] = {};
int buffer_index       = 0;
 
void clear_buffer()
{
  for (int i = 0; i < buffer_index; ++i)
  {
    Serial.println(buffer[i]);
    Serial.println(buffer[i]);
    Serial.println(buffer[i]);
  }
  buffer_index = 0;
}
 
void append_buffer(int value)
{
  buffer[buffer_index++] = value;
}
 
void loop()
{
  if (buffer_index + 10 >= max_buffer) clear_buffer();
 
  unsigned long t = micros();
  while (CLOCK == HIGH && (micros() - t) < 200)
    ;
  if (CLOCK == HIGH)
  {
    append_buffer(-2);
    clear_buffer();
  }
  while (CLOCK == HIGH)
    ;
  append_buffer(DATA);
  t = micros();
  while (CLOCK == LOW && (micros() - t) < 60)
    ;
  if (CLOCK == LOW) append_buffer(2);
  while (CLOCK == LOW)
    ;
}
 

Comments