Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Turn off LED on SIGINT #40

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion Code/C_Code/01.1.1_Blink/Blink.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,29 @@
**********************************************************************/
#include <wiringPi.h>
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>

#define ledPin 0 //define the led pin number

// Signal handler function
// Handle interrupt, set LED to LOW
void handle_interrupt(int signal) {
printf("Interrupt signal caught. Exiting...\n");

digitalWrite(ledPin, LOW);

exit(0);
}

void main(void)
{
printf("Program is starting ... \n");

wiringPiSetup(); //Initialize wiringPi.


signal(SIGINT, handle_interrupt);

pinMode(ledPin, OUTPUT);//Set the pin mode
printf("Using pin%d\n",ledPin); //Output information on terminal
while(1){
Expand Down
1 change: 1 addition & 0 deletions Code/Python_Code/01.1.1_Blink/Blink.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def loop():
time.sleep(1) # Wait for 1 second

def destroy():
GPIO.output(ledPin, GPIO.LOW)
GPIO.cleanup() # Release all GPIO

if __name__ == '__main__': # Program entrance
Expand Down