Reliable 20 symbols sent automatically
This commit is contained in:
parent
6cdcceefdd
commit
f43c10909e
@ -5,7 +5,7 @@ const int pinData = 6;
|
||||
const int pinStatus = 7;
|
||||
|
||||
// fixed values
|
||||
const int timerDelay = 500;
|
||||
const int timerDelay = 530;
|
||||
|
||||
void setup(void)
|
||||
{
|
||||
@ -29,27 +29,25 @@ volatile int dataState = 0;
|
||||
volatile int dataDelay = 0;
|
||||
volatile int packetDelay = 0;
|
||||
volatile int packetTail = 0;
|
||||
volatile int clkState = HIGH;
|
||||
|
||||
volatile bool nextKeyReady = false;
|
||||
volatile byte nextKey = 0;
|
||||
|
||||
void typeKey(byte key) {
|
||||
noInterrupts();
|
||||
nextKeyReady = true;
|
||||
//noInterrupts();
|
||||
nextKey = key;
|
||||
interrupts();
|
||||
nextKeyReady = true;
|
||||
//interrupts();
|
||||
}
|
||||
|
||||
void sendKey(byte key) {
|
||||
noInterrupts();
|
||||
//noInterrupts();
|
||||
dataWord = key;
|
||||
dataState = 8;
|
||||
dataDelay = 0;
|
||||
packetDelay = 0;
|
||||
packetTail = 10;
|
||||
clkState = HIGH;
|
||||
interrupts();
|
||||
packetTail = 15;
|
||||
//interrupts();
|
||||
Timer1.initialize(timerDelay);
|
||||
Timer1.start();
|
||||
}
|
||||
@ -59,19 +57,14 @@ void statusCycle() {
|
||||
long changeDiff = timeNow - lastChange;
|
||||
lastChange = timeNow;
|
||||
if (changeDiff >= 10 && nextKeyReady) {
|
||||
sendKey(nextKey);
|
||||
nextKeyReady = false;
|
||||
sendKey(nextKey);
|
||||
}
|
||||
}
|
||||
|
||||
void clockCycle(void)
|
||||
{
|
||||
int dataBit = HIGH;
|
||||
if (clkState == LOW) {
|
||||
clkState = HIGH;
|
||||
} else {
|
||||
clkState = LOW;
|
||||
}
|
||||
if (packetDelay > 0) {
|
||||
packetDelay--;
|
||||
} else if (dataDelay > 0) {
|
||||
@ -89,16 +82,18 @@ void clockCycle(void)
|
||||
}
|
||||
digitalWrite(pinData, dataBit);
|
||||
}
|
||||
|
||||
int xx = 0;
|
||||
void loop(void)
|
||||
{
|
||||
delay(50);
|
||||
delay(500);
|
||||
typeKey(44 + xx);
|
||||
xx = (xx+1) % 20;
|
||||
|
||||
if (Serial.available() > 0) {
|
||||
/*if (!nextKeyReady && Serial.available() > 0) {
|
||||
long key = Serial.parseInt(SKIP_ALL);
|
||||
if (key != 0) {
|
||||
typeKey(key);
|
||||
}
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user