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