Led-cpp BBB
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

33 lines
823 B

  1. /*OOP in C++ example for LEDs
  2. Gerardo Marx April/20/2020
  3. g++ main.cpp -o main LED.cpp*/
  4. #include<string>
  5. #include"led.h"
  6. using namespace std;
  7. int main(int argc, char* argv[]){
  8. if(argc!=2){
  9. cout << "The usage is main mkLed" << endl;
  10. cout << "mkLed is on, off flash or status" << endl;
  11. cout << "e.g. main on" << endl;
  12. return 2;
  13. }
  14. cout << "Starting program ..." << endl;
  15. string cmd(argv[1]);
  16. LED leds[4] = {LED(0), LED(1), LED(2), LED(3)};
  17. for(int i=0; i<=3; i++){
  18. if(cmd=="on")
  19. leds[i].turnOn();
  20. else if(cmd=="off")
  21. leds[i].turnOff();
  22. else if(cmd=="flash")
  23. leds[i].flash("100");
  24. else if(cmd=="status")
  25. leds[i].outputState();
  26. else
  27. cout << "invalid command, please type main" << endl;
  28. }
  29. cout << "Program done, Thanks." << endl;
  30. return 0;
  31. }