#define relay_pin 3
#define sss_pin 12
const int buttonPin = 2; // the number of the pushbutton pin
// Variables will change:
//int ledState = HIGH; // the current state of the output
pin
int buttonState; // the current reading from the
input pin
int lastButtonState = LOW; // the previous reading from the input pin
// the following variables are
unsigned longs because the time, measured in
// milliseconds, will quickly become a
bigger number than can be stored in an int.
unsigned long lastDebounceTime =
0; // the last time the output pin was
toggled
unsigned long debounceDelay = 50; // the debounce time; increase if the
output flickers
void ini() {
lastButtonState = LOW;
lastDebounceTime = 0;
}
void setup() {
pinMode(relay_pin, OUTPUT);
pinMode(buttonPin, INPUT);
pinMode(sss_pin, OUTPUT);
Serial.begin(115200);
//設定UART
delay(1000);
Serial.print("atd0=()"); //清除畫面
while (Serial.read() != 'E') {}
//等待燈板完成動作
Serial.print("at2b=(0)"); //設定為覆蓋模式
while (Serial.read() != 'E') {}
//傳送指令終止的字元
} //end of setup()
void loop() {
// read the state of the switch into a local variable:
int reading = digitalRead(buttonPin);
// check to see if you just pressed the button
// (i.e. the input went from LOW to HIGH), and you've waited long
enough
// since the last press to ignore any noise:
// If the switch changed, due to noise or pressing:
if (reading != lastButtonState) {
// reset the debouncing timer
lastDebounceTime = millis();
}
if ((millis() - lastDebounceTime) > debounceDelay) {
// whatever the reading is at, it's been there for longer than the
debounce delay, so take it as the actual current state:
// if the button state has changed:
if (reading != buttonState) {
buttonState = reading;
// only toggle the LED if the new button state is HIGH
if (buttonState == HIGH) {
//Spin the wheel
digitalWrite(relay_pin, HIGH);
//Score counting
digitalWrite(sss_pin, HIGH);
//Time counting
//Serial.print("atef=(4)"); //設定文字顏色為綠色
//while (Serial.read() != 'E') {}
//Serial.print("at83=(1,0,Count:)"); //顯示8x16字型 Count: 字串
//while (Serial.read() != 'E') {}
Serial.print("atef=(32)"); //設定數字顏色為0:Black、3:B、4:G、32:R
while (Serial.read() != 'E') {}
for (int i = 120; i > 0; i--) {
Serial.print("atd0=()");
//清除畫面
while (Serial.read() != 'E') {} //等待燈板完成動作
Serial.print("at83=(1,3,"); //傳送部分指令
Serial.print((String)i); //傳送指令中變動的部分
Serial.write(')'); //傳送指令終止的字元
while (Serial.read() != 'E') {}
delay(950);
//Serial.print("atd0=()"); //清除畫面
//while (Serial.read() != 'E')
{} //等待燈板完成動作
} //end of for loop
digitalWrite(sss_pin, LOW);
digitalWrite(relay_pin, LOW);
} //end of if
} //end of if
} //end of if
// save the reading. Next time through the loop, it'll be the
lastButtonState:
lastButtonState = reading;
//ini();
} //end of loop()
|