Reliable 0
This commit is contained in:
parent
e7c927b96c
commit
b81af18555
@ -3,13 +3,15 @@
|
||||
const int pinData = 6;
|
||||
const int pinStatus = 7;
|
||||
|
||||
const int timerDelay = 545;
|
||||
|
||||
void setup(void)
|
||||
{
|
||||
pinMode(pinData, OUTPUT);
|
||||
//Timer1.initialize(60);
|
||||
//Timer1.attachInterrupt(clockCycle);
|
||||
|
||||
Timer1.initialize(1100/2);
|
||||
Timer1.initialize(timerDelay);
|
||||
Timer1.attachInterrupt(clockCycle);
|
||||
Timer1.stop();
|
||||
|
||||
@ -25,6 +27,8 @@ volatile int x = 0;
|
||||
volatile int dataWord = 0;
|
||||
volatile int dataState = 0;
|
||||
volatile int dataDelay = 0;
|
||||
volatile int packetDelay = 0;
|
||||
volatile int packetTail = 0;
|
||||
volatile int clkState = LOW;
|
||||
|
||||
void statusCycle() {
|
||||
@ -34,11 +38,14 @@ void statusCycle() {
|
||||
if (changeDiff >= 10) {
|
||||
lastStart = timeNow;
|
||||
|
||||
dataWord = ('1' + x) << 3;
|
||||
dataState = 10;
|
||||
dataDelay = 1;
|
||||
x = (x + 1) % 3;
|
||||
dataWord = (1 + x);
|
||||
dataState = 7;
|
||||
dataDelay = 0;
|
||||
packetDelay = 0;
|
||||
packetTail = 100;
|
||||
x = (x + 1) % 1;
|
||||
clkState = HIGH;
|
||||
Timer1.initialize(timerDelay);
|
||||
Timer1.start();
|
||||
}
|
||||
if (timeNow - lastStart >= 7 && changeDiff >= 2) {
|
||||
@ -55,14 +62,20 @@ void clockCycle(void)
|
||||
} else {
|
||||
clkState = LOW;
|
||||
}
|
||||
if (dataDelay > 0) {
|
||||
if (packetDelay > 0) {
|
||||
packetDelay--;
|
||||
} else if (dataDelay > 0) {
|
||||
dataDelay--;
|
||||
dataBit = LOW;
|
||||
} else if (dataState > 0) {
|
||||
int bitToSend = (dataWord >> (dataState - 1)) & 1;
|
||||
//int bitToSend = dataWord & 1;
|
||||
//dataWord = dataWord >> 1;
|
||||
dataBit = !bitToSend ? LOW : HIGH;
|
||||
dataState--;
|
||||
} else if (packetTail > 0) {
|
||||
packetTail--;
|
||||
dataBit = LOW;
|
||||
} else {
|
||||
//digitalWrite(pinData, HIGH);
|
||||
Timer1.stop();
|
||||
|
Loading…
Reference in New Issue
Block a user