Cleanup. Stable 0..7

This commit is contained in:
Dejvino 2023-03-30 05:47:30 +02:00
parent 3ed2b30b1d
commit 2495c3b9d0

View File

@ -1,16 +1,16 @@
#include <TimerOne.h> #include <TimerOne.h>
// config:
const int pinData = 6; const int pinData = 6;
const int pinStatus = 7; const int pinStatus = 7;
// fixed values
const int timerDelay = 500; const int timerDelay = 500;
void setup(void) void setup(void)
{ {
pinMode(pinData, OUTPUT); pinMode(pinData, OUTPUT);
//Timer1.initialize(60);
//Timer1.attachInterrupt(clockCycle);
Timer1.initialize(timerDelay); Timer1.initialize(timerDelay);
Timer1.attachInterrupt(clockCycle); Timer1.attachInterrupt(clockCycle);
Timer1.stop(); Timer1.stop();
@ -22,7 +22,6 @@ void setup(void)
} }
volatile long lastChange = 0; volatile long lastChange = 0;
volatile long lastStart = 0;
volatile int x = 0; volatile int x = 0;
volatile int dataWord = 0; volatile int dataWord = 0;
volatile int dataState = 0; volatile int dataState = 0;
@ -36,8 +35,6 @@ void statusCycle() {
long changeDiff = timeNow - lastChange; long changeDiff = timeNow - lastChange;
lastChange = timeNow; lastChange = timeNow;
if (changeDiff >= 10) { if (changeDiff >= 10) {
lastStart = timeNow;
dataWord = (0 + x); dataWord = (0 + x);
dataState = 8; dataState = 8;
dataDelay = 0; dataDelay = 0;
@ -48,10 +45,6 @@ void statusCycle() {
Timer1.initialize(timerDelay); Timer1.initialize(timerDelay);
Timer1.start(); Timer1.start();
} }
if (timeNow - lastStart >= 7 && changeDiff >= 2) {
//dataWord = 0b1000000011 | (('A' + x) << 2);
}
} }
void clockCycle(void) void clockCycle(void)
@ -69,15 +62,12 @@ void clockCycle(void)
dataBit = LOW; dataBit = LOW;
} else if (dataState > 0) { } else if (dataState > 0) {
int bitToSend = (dataWord >> (dataState - 1)) & 1; int bitToSend = (dataWord >> (dataState - 1)) & 1;
//int bitToSend = dataWord & 1;
//dataWord = dataWord >> 1;
dataBit = !bitToSend ? LOW : HIGH; dataBit = !bitToSend ? LOW : HIGH;
dataState--; dataState--;
} else if (packetTail > 0) { } else if (packetTail > 0) {
packetTail--; packetTail--;
dataBit = LOW; dataBit = LOW;
} else { } else {
//digitalWrite(pinData, HIGH);
Timer1.stop(); Timer1.stop();
} }
digitalWrite(pinData, dataBit); digitalWrite(pinData, dataBit);