Progress!
Parts Required:
1x Arduino Leonardo
1x 220 ohm resistor
Arduino IDE Code:
//Copyright Jeroen van der Velden 2018
//Released under by-nc-sa Non-Commercial Share Alike
//https://hackaday.io/project/8448
#include "Keyboard.h"
int lockpin = 13;
bool oldstate=false;
bool debugmode=false;
bool keystate=false;
char outchar=' ';
const int acctrip = 200;
const int restrip = 400;
const int rettrip = 600;
const int onlimit = 700;
const int offlimit = 890;
void setup() {
pinMode(lockpin,INPUT_PULLUP); //no need for a pullup.
// open the serial port
Serial.begin(9600);
}
void loop() {
int analogValue = analogRead(A0);
debugmode=digitalRead(lockpin);
if (debugmode==false)
Keyboard.begin();
else
Keyboard.end();
if (analogValue>offlimit)
keystate=false;
else keystate=true;
if (oldstate != keystate)
{oldstate=keystate;
if (debugmode==false)
Keyboard.write('c');
else
Serial.println ('c');
}
if ((analogValue <= onlimit)&&(analogValue>=acctrip))
{if (analogValue>rettrip) outchar='8';
else if (analogValue >restrip) outchar='7';
else if (analogValue>acctrip) outchar='9';
if (debugmode==false)
Keyboard.write(outchar);
else
{Serial.print(outchar);
Serial.print(" ");
Serial.println(analogValue);
};
}
//analogvalue in keyscan limit
else
{Serial.print("No char ");
Serial.println(analogValue);
}
delay(150);
}
How to wire:
Connect the White and Black/Purple wire to the Arduino. White goes to GND and Black/Purple goes to the 220 Ohm Resistor.
From the resistor, go to 5v
Between the Black/Purple wire from the lever and the 220 Ohm resistor go to A0 (Analog input 0).
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.