![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
after pressing button ten times led will light up
counter.cpp@0:7a1c2b296ffe, 2017-10-04 (annotated)
- Committer:
- jakebonney10
- Date:
- Wed Oct 04 21:45:58 2017 +0000
- Revision:
- 0:7a1c2b296ffe
trying without switch in;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jakebonney10 | 0:7a1c2b296ffe | 1 | #include "mbed.h" |
jakebonney10 | 0:7a1c2b296ffe | 2 | |
jakebonney10 | 0:7a1c2b296ffe | 3 | //Assignment1 |
jakebonney10 | 0:7a1c2b296ffe | 4 | //Jake_Bonney |
jakebonney10 | 0:7a1c2b296ffe | 5 | //OCE 360 |
jakebonney10 | 0:7a1c2b296ffe | 6 | //count_10_redled_on_greenled_off |
jakebonney10 | 0:7a1c2b296ffe | 7 | //led_switches@10count |
jakebonney10 | 0:7a1c2b296ffe | 8 | |
jakebonney10 | 0:7a1c2b296ffe | 9 | DigitalOut redled(p5); |
jakebonney10 | 0:7a1c2b296ffe | 10 | DigitalOut greenled(p6); |
jakebonney10 | 0:7a1c2b296ffe | 11 | DigitalIn button(p7); |
jakebonney10 | 0:7a1c2b296ffe | 12 | |
jakebonney10 | 0:7a1c2b296ffe | 13 | int main() { |
jakebonney10 | 0:7a1c2b296ffe | 14 | |
jakebonney10 | 0:7a1c2b296ffe | 15 | int count = 0; |
jakebonney10 | 0:7a1c2b296ffe | 16 | redled = 1; |
jakebonney10 | 0:7a1c2b296ffe | 17 | greenled = 0; |
jakebonney10 | 0:7a1c2b296ffe | 18 | |
jakebonney10 | 0:7a1c2b296ffe | 19 | while(count < 10) { |
jakebonney10 | 0:7a1c2b296ffe | 20 | if(button == 1){ |
jakebonney10 | 0:7a1c2b296ffe | 21 | int check_value = button; |
jakebonney10 | 0:7a1c2b296ffe | 22 | |
jakebonney10 | 0:7a1c2b296ffe | 23 | wait(0.005); // so it doesnt bounce when button is being pressed down |
jakebonney10 | 0:7a1c2b296ffe | 24 | |
jakebonney10 | 0:7a1c2b296ffe | 25 | while(check_value){ |
jakebonney10 | 0:7a1c2b296ffe | 26 | if(check_value - button == 1){ |
jakebonney10 | 0:7a1c2b296ffe | 27 | count++; |
jakebonney10 | 0:7a1c2b296ffe | 28 | check_value = 0; |
jakebonney10 | 0:7a1c2b296ffe | 29 | } |
jakebonney10 | 0:7a1c2b296ffe | 30 | } |
jakebonney10 | 0:7a1c2b296ffe | 31 | } |
jakebonney10 | 0:7a1c2b296ffe | 32 | } |
jakebonney10 | 0:7a1c2b296ffe | 33 | |
jakebonney10 | 0:7a1c2b296ffe | 34 | redled = 0; |
jakebonney10 | 0:7a1c2b296ffe | 35 | greenled = 1; |
jakebonney10 | 0:7a1c2b296ffe | 36 | |
jakebonney10 | 0:7a1c2b296ffe | 37 | } |