-
-
Save ilsubyeega/bb2890a2d15fb1c2fb12575b8b955bae to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const int LED1 = PA1; // interrupt | |
| const int LED2 = PA2; // 상시-주기적 toggling LED | |
| const int BTN_LED = PB12; // -> LED1 | |
| const int BTN_MOTOR = PB13; // MOTOR_{A,B} | |
| const int MOTOR_A = PA6; | |
| const int MOTOR_B = PA7; | |
| void handleLedISR() { | |
| digitalWrite(LED1, digitalRead(BTN_LED)); | |
| } | |
| void setup() { | |
| pinMode(LED1, OUTPUT); pinMode(LED2, OUTPUT); | |
| pinMode(MOTOR_A, OUTPUT); pinMode(MOTOR_B, OUTPUT); | |
| pinMode(BTN_LED, INPUT_PULLUP); pinMode(BTN_MOTOR, INPUT_PULLUP); | |
| attachInterrupt(digitalPinToInterrupt(BTN_INT), handleLedISR, CHANGE); | |
| digitalWrite(LED1, LOW); digitalWrite(LED2, LOW); | |
| } | |
| bool ledState = false; | |
| unsigned long prevMillis = 0; | |
| void loop() { | |
| unsigned long currentMillis = millis(); | |
| if (currentMillis - prevMillis >= 500) { | |
| prevMillis = currentMillis; | |
| ledState = !ledState; | |
| digitalWrite(LED2, ledState ? HIGH : LOW); | |
| } | |
| digitalWrite(MOTOR_A, digitalRead(BTN_MOTOR) == LOW ? HIGH : LOW); | |
| digitalWrite(MOTOR_B, LOW); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment