Christian Weiß
/
TINF_Test_230418
TINF_Test_230418
main.cpp@0:fbb75c0396c7, 2018-11-15 (annotated)
- Committer:
- Wizo
- Date:
- Thu Nov 15 18:10:38 2018 +0000
- Revision:
- 0:fbb75c0396c7
TINF_Test_230418
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Wizo | 0:fbb75c0396c7 | 1 | #include "mbed.h" |
Wizo | 0:fbb75c0396c7 | 2 | |
Wizo | 0:fbb75c0396c7 | 3 | #include "C12832.h" |
Wizo | 0:fbb75c0396c7 | 4 | |
Wizo | 0:fbb75c0396c7 | 5 | // C12832 lcd(p5, p7, p6, p8, p11); |
Wizo | 0:fbb75c0396c7 | 6 | C12832 lcd(p5, p7, p6, p8, p11); |
Wizo | 0:fbb75c0396c7 | 7 | AnalogIn aiPoti1(p19); |
Wizo | 0:fbb75c0396c7 | 8 | AnalogIn aiPoti2(p20); // p20 oder p31 |
Wizo | 0:fbb75c0396c7 | 9 | |
Wizo | 0:fbb75c0396c7 | 10 | InterruptIn iiJsCenter(p14); |
Wizo | 0:fbb75c0396c7 | 11 | InterruptIn iiJsUp(p15); |
Wizo | 0:fbb75c0396c7 | 12 | InterruptIn iiJsDown(p12); |
Wizo | 0:fbb75c0396c7 | 13 | InterruptIn iiJsRight(p16); |
Wizo | 0:fbb75c0396c7 | 14 | InterruptIn iiJsLeft(p13); |
Wizo | 0:fbb75c0396c7 | 15 | |
Wizo | 0:fbb75c0396c7 | 16 | |
Wizo | 0:fbb75c0396c7 | 17 | int start = 0; |
Wizo | 0:fbb75c0396c7 | 18 | float poti1Wert; |
Wizo | 0:fbb75c0396c7 | 19 | float poti2Wert; |
Wizo | 0:fbb75c0396c7 | 20 | float summe; |
Wizo | 0:fbb75c0396c7 | 21 | |
Wizo | 0:fbb75c0396c7 | 22 | void lesen1() |
Wizo | 0:fbb75c0396c7 | 23 | { |
Wizo | 0:fbb75c0396c7 | 24 | poti1Wert = (aiPoti1.read()*100)-39; |
Wizo | 0:fbb75c0396c7 | 25 | } |
Wizo | 0:fbb75c0396c7 | 26 | |
Wizo | 0:fbb75c0396c7 | 27 | void lesen2() |
Wizo | 0:fbb75c0396c7 | 28 | { |
Wizo | 0:fbb75c0396c7 | 29 | poti2Wert = (aiPoti2.read()*19.5)+1.5; |
Wizo | 0:fbb75c0396c7 | 30 | } |
Wizo | 0:fbb75c0396c7 | 31 | |
Wizo | 0:fbb75c0396c7 | 32 | void go() |
Wizo | 0:fbb75c0396c7 | 33 | { |
Wizo | 0:fbb75c0396c7 | 34 | |
Wizo | 0:fbb75c0396c7 | 35 | if(start == 0) |
Wizo | 0:fbb75c0396c7 | 36 | { |
Wizo | 0:fbb75c0396c7 | 37 | lcd.locate(100,10); |
Wizo | 0:fbb75c0396c7 | 38 | lcd.printf("GO"); |
Wizo | 0:fbb75c0396c7 | 39 | start = 1; |
Wizo | 0:fbb75c0396c7 | 40 | } |
Wizo | 0:fbb75c0396c7 | 41 | } |
Wizo | 0:fbb75c0396c7 | 42 | |
Wizo | 0:fbb75c0396c7 | 43 | void addieren() |
Wizo | 0:fbb75c0396c7 | 44 | { |
Wizo | 0:fbb75c0396c7 | 45 | if(start == 1) |
Wizo | 0:fbb75c0396c7 | 46 | { |
Wizo | 0:fbb75c0396c7 | 47 | lesen1(); |
Wizo | 0:fbb75c0396c7 | 48 | lesen2(); |
Wizo | 0:fbb75c0396c7 | 49 | summe = poti1Wert + poti2Wert; |
Wizo | 0:fbb75c0396c7 | 50 | lcd.cls(); |
Wizo | 0:fbb75c0396c7 | 51 | lcd.locate(0,00); |
Wizo | 0:fbb75c0396c7 | 52 | lcd.printf("Poti1 = %.1f Poti2 = %.1f", poti1Wert, poti2Wert); |
Wizo | 0:fbb75c0396c7 | 53 | lcd.locate(0,10); |
Wizo | 0:fbb75c0396c7 | 54 | lcd.printf("Plus: %.1f ", summe); |
Wizo | 0:fbb75c0396c7 | 55 | } |
Wizo | 0:fbb75c0396c7 | 56 | } |
Wizo | 0:fbb75c0396c7 | 57 | |
Wizo | 0:fbb75c0396c7 | 58 | void subtrahieren() |
Wizo | 0:fbb75c0396c7 | 59 | { |
Wizo | 0:fbb75c0396c7 | 60 | if(start == 1) |
Wizo | 0:fbb75c0396c7 | 61 | { |
Wizo | 0:fbb75c0396c7 | 62 | lesen1(); |
Wizo | 0:fbb75c0396c7 | 63 | lesen2(); |
Wizo | 0:fbb75c0396c7 | 64 | summe = poti1Wert - poti2Wert; |
Wizo | 0:fbb75c0396c7 | 65 | lcd.cls(); |
Wizo | 0:fbb75c0396c7 | 66 | lcd.locate(0,00); |
Wizo | 0:fbb75c0396c7 | 67 | lcd.printf("Poti1 = %.1f Poti2 = %.1f", poti1Wert, poti2Wert); |
Wizo | 0:fbb75c0396c7 | 68 | lcd.locate(0,10); |
Wizo | 0:fbb75c0396c7 | 69 | lcd.printf("Minus: %.1f ", summe); |
Wizo | 0:fbb75c0396c7 | 70 | } |
Wizo | 0:fbb75c0396c7 | 71 | } |
Wizo | 0:fbb75c0396c7 | 72 | |
Wizo | 0:fbb75c0396c7 | 73 | void multiplizieren() |
Wizo | 0:fbb75c0396c7 | 74 | { |
Wizo | 0:fbb75c0396c7 | 75 | if(start == 1) |
Wizo | 0:fbb75c0396c7 | 76 | { |
Wizo | 0:fbb75c0396c7 | 77 | lesen1(); |
Wizo | 0:fbb75c0396c7 | 78 | lesen2(); |
Wizo | 0:fbb75c0396c7 | 79 | summe = poti1Wert * poti2Wert; |
Wizo | 0:fbb75c0396c7 | 80 | lcd.cls(); |
Wizo | 0:fbb75c0396c7 | 81 | lcd.locate(0,00); |
Wizo | 0:fbb75c0396c7 | 82 | lcd.printf("Poti1 = %.1f Poti2 = %.1f", poti1Wert, poti2Wert); |
Wizo | 0:fbb75c0396c7 | 83 | lcd.locate(0,10); |
Wizo | 0:fbb75c0396c7 | 84 | lcd.printf("Multiplizieren: %.1f ", summe); |
Wizo | 0:fbb75c0396c7 | 85 | } |
Wizo | 0:fbb75c0396c7 | 86 | } |
Wizo | 0:fbb75c0396c7 | 87 | |
Wizo | 0:fbb75c0396c7 | 88 | void dividieren() |
Wizo | 0:fbb75c0396c7 | 89 | { |
Wizo | 0:fbb75c0396c7 | 90 | if(start == 1) |
Wizo | 0:fbb75c0396c7 | 91 | { |
Wizo | 0:fbb75c0396c7 | 92 | lesen1(); |
Wizo | 0:fbb75c0396c7 | 93 | lesen2(); |
Wizo | 0:fbb75c0396c7 | 94 | summe = poti1Wert / poti2Wert; |
Wizo | 0:fbb75c0396c7 | 95 | lcd.cls(); |
Wizo | 0:fbb75c0396c7 | 96 | lcd.locate(0,00); |
Wizo | 0:fbb75c0396c7 | 97 | lcd.printf("Poti1 = %.1f Poti2 = %.1f", poti1Wert, poti2Wert); |
Wizo | 0:fbb75c0396c7 | 98 | lcd.locate(0,10); |
Wizo | 0:fbb75c0396c7 | 99 | lcd.printf("Division: %.1f ", summe); |
Wizo | 0:fbb75c0396c7 | 100 | } |
Wizo | 0:fbb75c0396c7 | 101 | } |
Wizo | 0:fbb75c0396c7 | 102 | |
Wizo | 0:fbb75c0396c7 | 103 | int main() { |
Wizo | 0:fbb75c0396c7 | 104 | |
Wizo | 0:fbb75c0396c7 | 105 | lcd.cls(); |
Wizo | 0:fbb75c0396c7 | 106 | lcd.locate(0,0); |
Wizo | 0:fbb75c0396c7 | 107 | lcd.printf("Poti-Calculator"); |
Wizo | 0:fbb75c0396c7 | 108 | lcd.locate(0,10); |
Wizo | 0:fbb75c0396c7 | 109 | lcd.printf("Christian Weiss"); |
Wizo | 0:fbb75c0396c7 | 110 | wait_ms(300); |
Wizo | 0:fbb75c0396c7 | 111 | |
Wizo | 0:fbb75c0396c7 | 112 | while(1) |
Wizo | 0:fbb75c0396c7 | 113 | { |
Wizo | 0:fbb75c0396c7 | 114 | iiJsCenter.rise(&go); |
Wizo | 0:fbb75c0396c7 | 115 | iiJsUp.rise(&addieren); |
Wizo | 0:fbb75c0396c7 | 116 | iiJsDown.rise(&subtrahieren); |
Wizo | 0:fbb75c0396c7 | 117 | iiJsRight.rise(&multiplizieren); |
Wizo | 0:fbb75c0396c7 | 118 | iiJsLeft.rise(&dividieren); |
Wizo | 0:fbb75c0396c7 | 119 | } |
Wizo | 0:fbb75c0396c7 | 120 | } |