|
|
- /*OOP in C++ example for LEDs
- Gerardo Marx April/20/2020
- g++ main.cpp -o main LED.cpp*/
- #include<string>
- #include"LED.h"
- using namespace std;
-
-
- int main(int argc, char* argv[]){
- if(argc!=2){
- cout << "The usage is main <command>" << endl;
- cout << "<command> is on, off flash or status" << endl;
- cout << "e.g. main on" << endl;
- return 2;
- }
- cout << "Starting program ..." << endl;
- string cmd(argv[1]);
- LED leds[4] = {LED(0), LED(1), LED(2), LED(3)};
- for(int i=0; i<=3; i++){
- if(cmd=="on")
- leds[i].turnOn();
- else if(cmd=="off")
- leds[i].turnOff();
- else if(cmd=="flash")
- leds[i].flash("100");
- else if(cmd=="status")
- leds[i].outputState();
- else
- cout << "invalid command, please type main" << endl;
- }
- cout << "Program done, Thanks." << endl;
- return 0;
- }
|