Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdlib>
- #include <csignal>
- #include <cstring>
- #include <wiringPi.h>
- using namespace std;
- void my_handler(int s){
- cout << endl << "Signal " << s << ", exit" << endl;
- digitalWrite(14, LOW);
- exit(1);
- }
- int main(int argc, char* argv[])
- {
- bool debug(false);
- for(int i(0); i < argc; i++)
- {
- if(strncmp(argv[i], "-d", 2) == 0)
- debug = true;
- }
- if(debug)
- cout << "[D] Setup.." << endl;
- if (wiringPiSetup() == -1)
- {
- cerr << "Erreur" << endl;
- return 1;
- }
- if(debug)
- cout << "[D] reg signal.." << endl;
- struct sigaction sigIntHandler;
- sigIntHandler.sa_handler = my_handler;
- sigemptyset(&sigIntHandler.sa_mask);
- sigIntHandler.sa_flags = 0;
- sigaction(SIGINT, &sigIntHandler, NULL);
- pinMode(14, OUTPUT);
- if(debug)
- cout << "[D] Input.." << endl;
- int delayValue(0);
- cout << "Entrez le délai (en ms): ";
- if (!(cin >> delayValue))
- {
- cout << "Valeur incorrecte, utilisation de 100ms" << endl;
- delayValue = 100;
- }
- if(debug)
- cout << "[D] Start.." << endl;
- while(true)
- {
- digitalWrite(14, LOW);
- if(debug)
- cout << "[D] LOW" << endl;
- delay(delayValue);
- digitalWrite(14, HIGH);
- if(debug)
- cout << "[D] HIGH" << endl;
- delay(delayValue);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment