vjezba5
Dependencies: mbed
main.cpp@0:878ef2de4ada, 2015-05-08 (annotated)
- Committer:
- mvucina
- Date:
- Fri May 08 17:05:39 2015 +0000
- Revision:
- 0:878ef2de4ada
Vje?ba 5: Napravite sustav koji broji koliko puta je digitalni prekida? pritisnut (tj.; promijenjen mu je polo?aj), a nakon ?to izbroji 10 puta, pali se LED dioda.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mvucina | 0:878ef2de4ada | 1 | #include "mbed.h" |
mvucina | 0:878ef2de4ada | 2 | DigitalOut redled(p5); |
mvucina | 0:878ef2de4ada | 3 | DigitalOut greenled(p6); |
mvucina | 0:878ef2de4ada | 4 | DigitalIn sw1(p7); |
mvucina | 0:878ef2de4ada | 5 | int n=0; |
mvucina | 0:878ef2de4ada | 6 | bool b= false; |
mvucina | 0:878ef2de4ada | 7 | int main() { |
mvucina | 0:878ef2de4ada | 8 | while(1) { |
mvucina | 0:878ef2de4ada | 9 | |
mvucina | 0:878ef2de4ada | 10 | if (sw1!=b){ |
mvucina | 0:878ef2de4ada | 11 | wait(0.1); |
mvucina | 0:878ef2de4ada | 12 | if(sw1==1){ |
mvucina | 0:878ef2de4ada | 13 | n++; } |
mvucina | 0:878ef2de4ada | 14 | b = sw1; |
mvucina | 0:878ef2de4ada | 15 | |
mvucina | 0:878ef2de4ada | 16 | } |
mvucina | 0:878ef2de4ada | 17 | |
mvucina | 0:878ef2de4ada | 18 | if (n>=10){ |
mvucina | 0:878ef2de4ada | 19 | redled = 1; |
mvucina | 0:878ef2de4ada | 20 | } |
mvucina | 0:878ef2de4ada | 21 | |
mvucina | 0:878ef2de4ada | 22 | } |
mvucina | 0:878ef2de4ada | 23 | } |