Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #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 == HIGH)
- ;
- }
- 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 == LOW && (micros() - t) < 200)
- ;
- if (CLOCK == LOW)
- {
- append_buffer(-2);
- clear_buffer();
- }
- while (CLOCK == LOW)
- ;
- t = micros();
- while (CLOCK == HIGH && (micros() - t) < 60)
- ;
- if (CLOCK == HIGH) append_buffer(2);
- while (CLOCK == HIGH)
- ;
- append_buffer(1 - DATA);
- }
Advertisement
Add Comment
Please, Sign In to add comment