Key typing over serial
This commit is contained in:
parent
2495c3b9d0
commit
6cdcceefdd
@ -10,6 +10,7 @@ const int timerDelay = 500;
|
|||||||
void setup(void)
|
void setup(void)
|
||||||
{
|
{
|
||||||
pinMode(pinData, OUTPUT);
|
pinMode(pinData, OUTPUT);
|
||||||
|
digitalWrite(pinData, HIGH);
|
||||||
|
|
||||||
Timer1.initialize(timerDelay);
|
Timer1.initialize(timerDelay);
|
||||||
Timer1.attachInterrupt(clockCycle);
|
Timer1.attachInterrupt(clockCycle);
|
||||||
@ -28,22 +29,38 @@ volatile int dataState = 0;
|
|||||||
volatile int dataDelay = 0;
|
volatile int dataDelay = 0;
|
||||||
volatile int packetDelay = 0;
|
volatile int packetDelay = 0;
|
||||||
volatile int packetTail = 0;
|
volatile int packetTail = 0;
|
||||||
volatile int clkState = LOW;
|
volatile int clkState = HIGH;
|
||||||
|
|
||||||
|
volatile bool nextKeyReady = false;
|
||||||
|
volatile byte nextKey = 0;
|
||||||
|
|
||||||
|
void typeKey(byte key) {
|
||||||
|
noInterrupts();
|
||||||
|
nextKeyReady = true;
|
||||||
|
nextKey = key;
|
||||||
|
interrupts();
|
||||||
|
}
|
||||||
|
|
||||||
|
void sendKey(byte key) {
|
||||||
|
noInterrupts();
|
||||||
|
dataWord = key;
|
||||||
|
dataState = 8;
|
||||||
|
dataDelay = 0;
|
||||||
|
packetDelay = 0;
|
||||||
|
packetTail = 10;
|
||||||
|
clkState = HIGH;
|
||||||
|
interrupts();
|
||||||
|
Timer1.initialize(timerDelay);
|
||||||
|
Timer1.start();
|
||||||
|
}
|
||||||
|
|
||||||
void statusCycle() {
|
void statusCycle() {
|
||||||
long timeNow = millis();
|
long timeNow = millis();
|
||||||
long changeDiff = timeNow - lastChange;
|
long changeDiff = timeNow - lastChange;
|
||||||
lastChange = timeNow;
|
lastChange = timeNow;
|
||||||
if (changeDiff >= 10) {
|
if (changeDiff >= 10 && nextKeyReady) {
|
||||||
dataWord = (0 + x);
|
sendKey(nextKey);
|
||||||
dataState = 8;
|
nextKeyReady = false;
|
||||||
dataDelay = 0;
|
|
||||||
packetDelay = 0;
|
|
||||||
packetTail = 100;
|
|
||||||
x = (x + 1) % 8;
|
|
||||||
clkState = HIGH;
|
|
||||||
Timer1.initialize(timerDelay);
|
|
||||||
Timer1.start();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -75,11 +92,13 @@ void clockCycle(void)
|
|||||||
|
|
||||||
void loop(void)
|
void loop(void)
|
||||||
{
|
{
|
||||||
delay(500);
|
delay(50);
|
||||||
|
|
||||||
/*noInterrupts();
|
if (Serial.available() > 0) {
|
||||||
dataWord = 0b1000000011 | (('A' + x) << 2);
|
long key = Serial.parseInt(SKIP_ALL);
|
||||||
dataState = 16;
|
if (key != 0) {
|
||||||
x = (x + 1) % 30;
|
typeKey(key);
|
||||||
interrupts();*/
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user