daily pastebin goal
22%
SHARE
TWEET

Untitled

a guest Aug 16th, 2018 55 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <signal.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <wiringPi.h>
  5.  
  6. #define RED 13
  7. #define YELLOW 12
  8. #define GREEN 14
  9.  
  10. static void allLightsOff();
  11. static void interruptHandler(const int);
  12.  
  13. static void allLightsOff() {
  14.     digitalWrite(RED, LOW);
  15.     digitalWrite(YELLOW, LOW);
  16.     digitalWrite(GREEN, LOW);
  17. }
  18.  
  19. static void interruptHandler(const int signal) {
  20.     allLightsOff();
  21.     exit(0);
  22. }
  23.  
  24. int main(void) {
  25.     signal(SIGINT, interruptHandler);
  26.  
  27.     if (-1 == wiringPiSetup()) {
  28.         printf("Failed to setup Wiring Pi!\n");
  29.         return 1;
  30.     }
  31.  
  32.     pinMode(RED, OUTPUT);
  33.     pinMode(YELLOW, OUTPUT);
  34.     pinMode(GREEN, OUTPUT);
  35.  
  36.     allLightsOff();
  37.  
  38.     while(1) {
  39.         // Red
  40.         digitalWrite(RED, HIGH);
  41.         delay(3000);
  42.  
  43.         // Red and Yellow
  44.         digitalWrite(YELLOW, HIGH);
  45.         delay(1000);
  46.  
  47.         // Green
  48.         digitalWrite(RED, LOW);
  49.         digitalWrite(YELLOW, LOW);
  50.         digitalWrite(GREEN, HIGH);
  51.         delay(5000);
  52.  
  53.         // Yellow
  54.         digitalWrite(GREEN, LOW);
  55.         digitalWrite(YELLOW, HIGH);
  56.         delay(2000);
  57.  
  58.         // Yellow off
  59.         digitalWrite(YELLOW, LOW);
  60.     }
  61.  
  62.     // Never reached, keeps the compiler happy.
  63.     return 0;
  64. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top