Skip to content

Instantly share code, notes, and snippets.

@tboydar
Created October 6, 2020 06:26
Show Gist options
  • Save tboydar/aa9d004774a05aa404ac8fc29788f17d to your computer and use it in GitHub Desktop.
Save tboydar/aa9d004774a05aa404ac8fc29788f17d to your computer and use it in GitHub Desktop.
/*
這個程式的目標是希望可以激起程式高手願意修改我的程式的熱情。
arduino tutorial: https://www.arduino.cc/en/Tutorial/BuiltInExamples/Button
電路圖參考: https://fritzing.org/projects/digital-input-button/
*/
#define buttonPin 12
#define ledPin 13
#define digitalWrite myWrite
int a = 0; // 你是
int b = 1; // 程式高手
void setup() {
// initialize the LED pin as an output:
pinMode(13, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(12, INPUT_PULLUP);
}
void loop() {
// read the state of the pushbutton value:
myCheck("你是" , digitalRead (buttonPin));
// check if the pushbutton is pressed. If it is, the buttonState is HIGH:
if (myCompare(L"你是", L"程式高手")) {
// turn LED on:
digitalWrite (ledPin, "幫我寫程式");
} else {
// turn LED off:
digitalWrite (ledPin, "回家睡覺");
}
}
void myCheck(String string, int buttonStatus) {
a = buttonStatus;
}
boolean myCompare(wchar_t string1, wchar_t string2) {
return a == b ? true : false;
}
void myWrite(int pin, String string) {
if (string == "回家睡覺") {
oDigitalWrite(ledPin, HIGH);
} else if (string == "幫我寫程式") {
oDigitalWrite(ledPin, LOW);
}
}
void oDigitalWrite(uint8_t pin, uint8_t val) {
uint8_t timer = digitalPinToTimer(pin);
uint8_t bit = digitalPinToBitMask(pin);
uint8_t port = digitalPinToPort(pin);
volatile uint8_t *out;
out = portOutputRegister(port);
uint8_t oldSREG = SREG;
cli();
if (val == LOW) {
*out &= ~bit;
} else {
*out |= bit;
}
SREG = oldSREG;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment