tim003 tim003
/
LV2_Grupa1_Tim003_Zadatak2
Irma Jakić Tarik Demirović
main.cpp@0:d515d96c18e3, 2014-03-10 (annotated)
- Committer:
- tim003
- Date:
- Mon Mar 10 07:59:29 2014 +0000
- Revision:
- 0:d515d96c18e3
LV2 - PAI - Grupa1 - Tim003
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
tim003 | 0:d515d96c18e3 | 1 | #include "mbed.h" |
tim003 | 0:d515d96c18e3 | 2 | |
tim003 | 0:d515d96c18e3 | 3 | BusOut leds(dp23, dp24, dp25, dp26, dp27, dp5, dp6, dp28); |
tim003 | 0:d515d96c18e3 | 4 | DigitalOut enable(dp14); |
tim003 | 0:d515d96c18e3 | 5 | DigitalIn taster1(dp1); |
tim003 | 0:d515d96c18e3 | 6 | DigitalIn taster2(dp2); |
tim003 | 0:d515d96c18e3 | 7 | |
tim003 | 0:d515d96c18e3 | 8 | bool pressed1() |
tim003 | 0:d515d96c18e3 | 9 | { |
tim003 | 0:d515d96c18e3 | 10 | int j = 0; |
tim003 | 0:d515d96c18e3 | 11 | while(taster1) |
tim003 | 0:d515d96c18e3 | 12 | { |
tim003 | 0:d515d96c18e3 | 13 | j++; |
tim003 | 0:d515d96c18e3 | 14 | if(j > 1000) |
tim003 | 0:d515d96c18e3 | 15 | { |
tim003 | 0:d515d96c18e3 | 16 | return true; |
tim003 | 0:d515d96c18e3 | 17 | } |
tim003 | 0:d515d96c18e3 | 18 | } |
tim003 | 0:d515d96c18e3 | 19 | j = 0; |
tim003 | 0:d515d96c18e3 | 20 | return false; |
tim003 | 0:d515d96c18e3 | 21 | } |
tim003 | 0:d515d96c18e3 | 22 | |
tim003 | 0:d515d96c18e3 | 23 | bool pressed2() |
tim003 | 0:d515d96c18e3 | 24 | { |
tim003 | 0:d515d96c18e3 | 25 | int j = 0; |
tim003 | 0:d515d96c18e3 | 26 | while(taster2) |
tim003 | 0:d515d96c18e3 | 27 | { |
tim003 | 0:d515d96c18e3 | 28 | j++; |
tim003 | 0:d515d96c18e3 | 29 | if(j > 1000) |
tim003 | 0:d515d96c18e3 | 30 | { |
tim003 | 0:d515d96c18e3 | 31 | return true; |
tim003 | 0:d515d96c18e3 | 32 | } |
tim003 | 0:d515d96c18e3 | 33 | } |
tim003 | 0:d515d96c18e3 | 34 | j = 0; |
tim003 | 0:d515d96c18e3 | 35 | return false; |
tim003 | 0:d515d96c18e3 | 36 | } |
tim003 | 0:d515d96c18e3 | 37 | |
tim003 | 0:d515d96c18e3 | 38 | int main() { |
tim003 | 0:d515d96c18e3 | 39 | enable = 0; |
tim003 | 0:d515d96c18e3 | 40 | leds = 0; |
tim003 | 0:d515d96c18e3 | 41 | int i = 0; |
tim003 | 0:d515d96c18e3 | 42 | while(1) { |
tim003 | 0:d515d96c18e3 | 43 | if(pressed1()) |
tim003 | 0:d515d96c18e3 | 44 | { |
tim003 | 0:d515d96c18e3 | 45 | if(i == 256) |
tim003 | 0:d515d96c18e3 | 46 | { |
tim003 | 0:d515d96c18e3 | 47 | i = 0; |
tim003 | 0:d515d96c18e3 | 48 | } |
tim003 | 0:d515d96c18e3 | 49 | i++; |
tim003 | 0:d515d96c18e3 | 50 | leds = i; |
tim003 | 0:d515d96c18e3 | 51 | while(taster1){} |
tim003 | 0:d515d96c18e3 | 52 | |
tim003 | 0:d515d96c18e3 | 53 | } |
tim003 | 0:d515d96c18e3 | 54 | if(pressed2()) |
tim003 | 0:d515d96c18e3 | 55 | { |
tim003 | 0:d515d96c18e3 | 56 | if(i == 0) |
tim003 | 0:d515d96c18e3 | 57 | { |
tim003 | 0:d515d96c18e3 | 58 | i = 257; |
tim003 | 0:d515d96c18e3 | 59 | } |
tim003 | 0:d515d96c18e3 | 60 | i--; |
tim003 | 0:d515d96c18e3 | 61 | leds = i; |
tim003 | 0:d515d96c18e3 | 62 | while(taster2) {} |
tim003 | 0:d515d96c18e3 | 63 | } |
tim003 | 0:d515d96c18e3 | 64 | |
tim003 | 0:d515d96c18e3 | 65 | } |
tim003 | 0:d515d96c18e3 | 66 | } |