mag niet van hendrik D:
Dependencies: mbed MatrixMath QEI HIDScope Matrix biquadFilter MODSERIAL FastPWM
Diff: main.cpp
- Revision:
- 7:d307e31f7391
- Parent:
- 6:61618bf71a08
- Child:
- 8:d1794f225fff
diff -r 61618bf71a08 -r d307e31f7391 main.cpp --- a/main.cpp Fri Sep 13 11:00:52 2019 +0000 +++ b/main.cpp Sat Sep 14 10:09:53 2019 +0000 @@ -3,114 +3,34 @@ MODSERIAL pc(USBTX, USBRX); DigitalOut ledr(LED_RED); -DigitalOut ledg(LED_GREEN); -DigitalOut ledb(LED_BLUE); -Ticker RE; -Timer R; -Timer G; -Timer B; -volatile char Command; -enum states {red, green, blue}; - -states CurrentState = red; -bool StateChanged = true; - -void ES() -{ - Command = 'r'; -} - -void CheckCommandFromTerminal(void) -{ - Command = pc.getcNb(); -} - -void StateMachine(void) +class Counter { - switch(CurrentState) { - case red: - if (StateChanged) { - pc.printf("Initiating turning LED red\n\r"); - StateChanged= false; - ledr = 0; - ledg = 1; - ledb = 1; - R.start(); - pc.printf("LED is now red!\n\r"); - } - if (Command == 'g') { - R.stop(); - pc.printf("The LED has been red for %f seconds!\n\r", R.read()); - CurrentState= green; - StateChanged= true; - } - if (Command == 'b') { - R.stop(); - pc.printf("The LED has been red for %f seconds!\n\r", R.read()); - CurrentState= blue; - StateChanged= true; - } - else {} - break; - case green: - if (StateChanged) { - pc.printf("Initiating turning LED green\n\r"); - StateChanged= false; - ledr = 1; - ledg = 0; - ledb = 1; - G.start(); - pc.printf("LED is now green!\n\r"); - } - if (Command == 'r') { - G.stop(); - pc.printf("The LED has been green for %f seconds!\n\r", G.read()); - CurrentState= red; - StateChanged= true; - } - if (Command == 'b') { - G.stop(); - pc.printf("The LED has been green for %f seconds!\n\r", G.read()); - CurrentState= blue; - StateChanged= true; - } - else {} - break; - case blue: - if (StateChanged) { - pc.printf("Initiating turning LED blue\n\r"); - StateChanged= false; - ledr = 1; - ledg = 1; - ledb = 0; - B.start(); - pc.printf("LED is now blue!\n\r"); - } - if (Command == 'r') { - B.stop(); - pc.printf("The LED has been blue for %f seconds!\n\r", B.read()); - CurrentState= red; - StateChanged= true; - } - if (Command == 'g') { - B.stop(); - pc.printf("The LED has been blue for %f seconds!\n\r", B.read()); - CurrentState= green; - StateChanged= true; - } - else {} - break; - default: - pc.printf("Unknown or unimplemented state reached!\n"); - } -} +public: + Counter(PinName pin) : _interrupt(pin) // create the InterruptIn on the pin specified to Counter + { + _interrupt.rise(callback(this, &Counter::increment)); // attach increment function of this counter instance + } + + void increment() + { + _count++; + } + + int read() + { + return _count; + } +}; + +Counter counter(SW2); + int main() { pc.baud(115200); - RE.attach(ES,3); - while(true) { - CheckCommandFromTerminal(); - StateMachine(); + while(1) { + if _ + printf("Count so far: %d\n\r", counter.read()); + wait(2); } } \ No newline at end of file