Skip to content

Instantly share code, notes, and snippets.

@awfulwoman
Forked from mharsch/mt_viki_remote
Created June 29, 2023 19:14
Show Gist options
  • Save awfulwoman/7d7fe48aba547af15eb129892e0d87e1 to your computer and use it in GitHub Desktop.
Save awfulwoman/7d7fe48aba547af15eb129892e0d87e1 to your computer and use it in GitHub Desktop.
Arduino replaces MT-VIKI KVM remote module for changing / polling selected KVM input
#include <math.h>
// connected to 'D+' pin on mini USB
const int input_pin = 11;
// connected to 'D-' pin on mini USB
const int output_pin = 12;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(input_pin, INPUT);
pinMode(output_pin, OUTPUT);
digitalWrite(output_pin, HIGH);
}
void loop() {
if (Serial.available() > 0) {
int new_port = Serial.parseInt();
if (new_port >= 1 && new_port <=8) {
set_port(new_port);
}
int port = get_port();
Serial.println(port);
}
}
int get_port() {
unsigned long duration;
double ms;
int p;
duration = pulseIn(input_pin, LOW);
ms = round(duration / 1000.0);
p = ((int) ms / 20);
return (p);
}
void set_port(int p) {
digitalWrite(output_pin, LOW);
delay(20);
digitalWrite(output_pin, HIGH);
delay(20);
digitalWrite(output_pin, LOW);
delay(p * 20);
digitalWrite(output_pin, HIGH);
delay(200);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment