Reliable 20 symbols sent automatically

This commit is contained in:
Dejvino 2023-03-30 15:58:00 +02:00
parent 6cdcceefdd
commit f43c10909e

View File

@ -5,7 +5,7 @@ const int pinData = 6;
const int pinStatus = 7; const int pinStatus = 7;
// fixed values // fixed values
const int timerDelay = 500; const int timerDelay = 530;
void setup(void) void setup(void)
{ {
@ -29,27 +29,25 @@ 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 = HIGH;
volatile bool nextKeyReady = false; volatile bool nextKeyReady = false;
volatile byte nextKey = 0; volatile byte nextKey = 0;
void typeKey(byte key) { void typeKey(byte key) {
noInterrupts(); //noInterrupts();
nextKeyReady = true;
nextKey = key; nextKey = key;
interrupts(); nextKeyReady = true;
//interrupts();
} }
void sendKey(byte key) { void sendKey(byte key) {
noInterrupts(); //noInterrupts();
dataWord = key; dataWord = key;
dataState = 8; dataState = 8;
dataDelay = 0; dataDelay = 0;
packetDelay = 0; packetDelay = 0;
packetTail = 10; packetTail = 15;
clkState = HIGH; //interrupts();
interrupts();
Timer1.initialize(timerDelay); Timer1.initialize(timerDelay);
Timer1.start(); Timer1.start();
} }
@ -59,19 +57,14 @@ void statusCycle() {
long changeDiff = timeNow - lastChange; long changeDiff = timeNow - lastChange;
lastChange = timeNow; lastChange = timeNow;
if (changeDiff >= 10 && nextKeyReady) { if (changeDiff >= 10 && nextKeyReady) {
sendKey(nextKey);
nextKeyReady = false; nextKeyReady = false;
sendKey(nextKey);
} }
} }
void clockCycle(void) void clockCycle(void)
{ {
int dataBit = HIGH; int dataBit = HIGH;
if (clkState == LOW) {
clkState = HIGH;
} else {
clkState = LOW;
}
if (packetDelay > 0) { if (packetDelay > 0) {
packetDelay--; packetDelay--;
} else if (dataDelay > 0) { } else if (dataDelay > 0) {
@ -89,16 +82,18 @@ void clockCycle(void)
} }
digitalWrite(pinData, dataBit); digitalWrite(pinData, dataBit);
} }
int xx = 0;
void loop(void) 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); long key = Serial.parseInt(SKIP_ALL);
if (key != 0) { if (key != 0) {
typeKey(key); typeKey(key);
} }
} }*/
} }