Hi
I am trying to do the following:
Data line is held high until the button is pressed, once the button is pressed the following sequence is initiated.
-
A preamble is sent
-
First set of data is sent
3 Second set of data is sent
The button in tested again and if still pressed the second set of data is sent again, this second set of data is repeated until the button is released, where upon the flow of the program returns to the start and waits for the button to be pressed again.
I have placed an "if" at the end of the second set of data to test the state of the button, if the result is that the button is still pressed a "goto" sends the program flow to "subsequent:" at the start of the second set of data.........this is where the problem seems to lie......can a "goto" only work if the label is further forward in the program?
Should I be using a completley different approach?
When the button is pressed data is sent, but on releasing the button data continues to be sent.
delays have been included between the data sets so that I can see what is going on on my 'scope
The button is held "high" by a 10k resistor to +5V, pressing the button takes the pin low to 0V
Can you help please?
const int data = 12;
const int xfcbutton = 2;
int buttonState = 1;
// the setup routine runs once when you press reset:
void setup() {
// initialize the digital pin as an output.
pinMode(data, OUTPUT);
pinMode(xfcbutton, INPUT);
digitalWrite(data, HIGH); // sets data out to high initially
}
// Preamble = 0000000 followed by marker
// XFC data first time through = 0100 0 1000 0 0011 0 0010 0
// XFC data second time through = 0000 0 1000 0 0011 0 0010 0
void loop() {
xfcstart:
buttonState =digitalRead(xfcbutton);
if (buttonState ==HIGH) goto xfcstart;
digitalWrite(data, LOW); // Zero starts Preamble starts 0000000 marker
delayMicroseconds(190); //
digitalWrite(data, HIGH); //
delayMicroseconds(230); // Zero ends
// code removed so I can post this!!
digitalWrite(data, LOW); // marker starts
delayMicroseconds(190);
digitalWrite(data, HIGH); //
delayMicroseconds(795); // marker ends End of preamble
// first 20 bit data stream begins
delay(5);
digitalWrite(data, LOW); // Zero starts 0100
delayMicroseconds(190);
digitalWrite(data, HIGH);
delayMicroseconds(230); // Zero ends
//code removed so I can post this!!
digitalWrite(data, LOW); // Zero starts 0
delayMicroseconds(190);
digitalWrite(data, HIGH);
delayMicroseconds(230); // Zero ends
// First 20 bit data stream ends
// Second 20 bit data stream begins
subsequent:
delay(5);
digitalWrite(data, LOW); // Zero starts 0000
delayMicroseconds(190);
digitalWrite(data, HIGH);
delayMicroseconds(230); // Zero ends
// code removed so that I can post this on the forum!!
digitalWrite(data, LOW); // Zero starts 0
delayMicroseconds(190);
digitalWrite(data, HIGH);
delayMicroseconds(230); // Zero ends
// second pass through finishes
delay (10);
if(buttonState ==LOW) goto subsequent;
}