Niclas Esterl
/
Thermometer_with_light_signal
Thermometer with light amplitude
main.cpp@0:cd2e365c7a90, 2016-05-24 (annotated)
- Committer:
- niclasesterl
- Date:
- Tue May 24 11:35:23 2016 +0000
- Revision:
- 0:cd2e365c7a90
You can use it to messure temperature
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
niclasesterl | 0:cd2e365c7a90 | 1 | #include "mbed.h" |
niclasesterl | 0:cd2e365c7a90 | 2 | #include "LM75B.h" |
niclasesterl | 0:cd2e365c7a90 | 3 | // ******** Definitionen ********** |
niclasesterl | 0:cd2e365c7a90 | 4 | Serial pc(USBTX, USBRX); |
niclasesterl | 0:cd2e365c7a90 | 5 | |
niclasesterl | 0:cd2e365c7a90 | 6 | // Definition der Taster (Switches) |
niclasesterl | 0:cd2e365c7a90 | 7 | DigitalIn sw1(P0_10); //SW1 |
niclasesterl | 0:cd2e365c7a90 | 8 | DigitalIn sw2(P0_15); //SW2 -> sein IO Pin ist laut Schaltplan der P0_15 |
niclasesterl | 0:cd2e365c7a90 | 9 | DigitalIn sw3(P0_23); //SW3 |
niclasesterl | 0:cd2e365c7a90 | 10 | DigitalIn sw4(P1_16); //SW4 |
niclasesterl | 0:cd2e365c7a90 | 11 | |
niclasesterl | 0:cd2e365c7a90 | 12 | // Definition der 12 LED's |
niclasesterl | 0:cd2e365c7a90 | 13 | DigitalOut ledD1(P1_8); |
niclasesterl | 0:cd2e365c7a90 | 14 | DigitalOut ledD2(P1_9); |
niclasesterl | 0:cd2e365c7a90 | 15 | DigitalOut ledD3(P1_10); |
niclasesterl | 0:cd2e365c7a90 | 16 | DigitalOut ledD4(P1_11); |
niclasesterl | 0:cd2e365c7a90 | 17 | DigitalOut ledD13(P1_0); |
niclasesterl | 0:cd2e365c7a90 | 18 | DigitalOut ledD14(P1_1); |
niclasesterl | 0:cd2e365c7a90 | 19 | DigitalOut ledD15(P1_3); |
niclasesterl | 0:cd2e365c7a90 | 20 | DigitalOut ledD16(P1_4); |
niclasesterl | 0:cd2e365c7a90 | 21 | DigitalOut ledD17(P1_6); |
niclasesterl | 0:cd2e365c7a90 | 22 | DigitalOut ledD18(P1_7); |
niclasesterl | 0:cd2e365c7a90 | 23 | DigitalOut ledD19(P1_12); |
niclasesterl | 0:cd2e365c7a90 | 24 | DigitalOut ledD20(P1_13); |
niclasesterl | 0:cd2e365c7a90 | 25 | |
niclasesterl | 0:cd2e365c7a90 | 26 | // RGB LED |
niclasesterl | 0:cd2e365c7a90 | 27 | DigitalOut ledRT(P0_9); // rote LED |
niclasesterl | 0:cd2e365c7a90 | 28 | DigitalOut ledGR(P1_15); // grüne LED |
niclasesterl | 0:cd2e365c7a90 | 29 | DigitalOut ledBL(P0_21); // blau LED |
niclasesterl | 0:cd2e365c7a90 | 30 | // LDR Input |
niclasesterl | 0:cd2e365c7a90 | 31 | AnalogIn LDR(P0_12); // Analoges einlesen des LDR |
niclasesterl | 0:cd2e365c7a90 | 32 | AnalogIn POTI (P0_11); // Analog in des POTI |
niclasesterl | 0:cd2e365c7a90 | 33 | //Create an LM75B object at the default address (ADDRESS_0) |
niclasesterl | 0:cd2e365c7a90 | 34 | LM75B sensor(p28, p27); //i²C Sensor Leitungen |
niclasesterl | 0:cd2e365c7a90 | 35 | |
niclasesterl | 0:cd2e365c7a90 | 36 | |
niclasesterl | 0:cd2e365c7a90 | 37 | void ledOn(int x); |
niclasesterl | 0:cd2e365c7a90 | 38 | int main(){ |
niclasesterl | 0:cd2e365c7a90 | 39 | while(1){ |
niclasesterl | 0:cd2e365c7a90 | 40 | int newSensor = sensor-5; |
niclasesterl | 0:cd2e365c7a90 | 41 | if(sw1==1){ |
niclasesterl | 0:cd2e365c7a90 | 42 | pc.printf("Temperatur = %d Grad\n\r", newSensor); |
niclasesterl | 0:cd2e365c7a90 | 43 | ledOn(newSensor); |
niclasesterl | 0:cd2e365c7a90 | 44 | } |
niclasesterl | 0:cd2e365c7a90 | 45 | wait(1); |
niclasesterl | 0:cd2e365c7a90 | 46 | |
niclasesterl | 0:cd2e365c7a90 | 47 | } |
niclasesterl | 0:cd2e365c7a90 | 48 | } |
niclasesterl | 0:cd2e365c7a90 | 49 | void ledOn(int x){ |
niclasesterl | 0:cd2e365c7a90 | 50 | |
niclasesterl | 0:cd2e365c7a90 | 51 | ledD1 = 0; |
niclasesterl | 0:cd2e365c7a90 | 52 | ledD2 = 0; |
niclasesterl | 0:cd2e365c7a90 | 53 | ledD3 = 0; |
niclasesterl | 0:cd2e365c7a90 | 54 | ledD4 = 0; |
niclasesterl | 0:cd2e365c7a90 | 55 | ledD13 = 0; |
niclasesterl | 0:cd2e365c7a90 | 56 | ledD14 = 0; |
niclasesterl | 0:cd2e365c7a90 | 57 | ledD15 = 0; |
niclasesterl | 0:cd2e365c7a90 | 58 | ledD16 = 0; |
niclasesterl | 0:cd2e365c7a90 | 59 | ledD17 = 0; |
niclasesterl | 0:cd2e365c7a90 | 60 | ledD18 = 0; |
niclasesterl | 0:cd2e365c7a90 | 61 | ledD19 = 0; |
niclasesterl | 0:cd2e365c7a90 | 62 | ledD20 = 0; |
niclasesterl | 0:cd2e365c7a90 | 63 | ledBL = 0; |
niclasesterl | 0:cd2e365c7a90 | 64 | ledGR = 0; |
niclasesterl | 0:cd2e365c7a90 | 65 | ledRT = 0; |
niclasesterl | 0:cd2e365c7a90 | 66 | |
niclasesterl | 0:cd2e365c7a90 | 67 | if (x < 25){ |
niclasesterl | 0:cd2e365c7a90 | 68 | ledRT = 0; |
niclasesterl | 0:cd2e365c7a90 | 69 | ledBL = 1; |
niclasesterl | 0:cd2e365c7a90 | 70 | ledGR = 0; |
niclasesterl | 0:cd2e365c7a90 | 71 | } |
niclasesterl | 0:cd2e365c7a90 | 72 | if(x > 25){ |
niclasesterl | 0:cd2e365c7a90 | 73 | ledBL = 0; |
niclasesterl | 0:cd2e365c7a90 | 74 | ledGR = 0; |
niclasesterl | 0:cd2e365c7a90 | 75 | ledRT = 1; |
niclasesterl | 0:cd2e365c7a90 | 76 | } |
niclasesterl | 0:cd2e365c7a90 | 77 | if (x == 20){ |
niclasesterl | 0:cd2e365c7a90 | 78 | ledD1 = 1; |
niclasesterl | 0:cd2e365c7a90 | 79 | } |
niclasesterl | 0:cd2e365c7a90 | 80 | if (x == 21){ |
niclasesterl | 0:cd2e365c7a90 | 81 | ledD1 = 1; |
niclasesterl | 0:cd2e365c7a90 | 82 | ledD2 = 1; |
niclasesterl | 0:cd2e365c7a90 | 83 | } |
niclasesterl | 0:cd2e365c7a90 | 84 | if (x == 22){ |
niclasesterl | 0:cd2e365c7a90 | 85 | ledD1 = 1; |
niclasesterl | 0:cd2e365c7a90 | 86 | ledD2 = 1; |
niclasesterl | 0:cd2e365c7a90 | 87 | ledD3 = 1; |
niclasesterl | 0:cd2e365c7a90 | 88 | } |
niclasesterl | 0:cd2e365c7a90 | 89 | if (x == 23){ |
niclasesterl | 0:cd2e365c7a90 | 90 | ledD1 = 1; |
niclasesterl | 0:cd2e365c7a90 | 91 | ledD2 = 1; |
niclasesterl | 0:cd2e365c7a90 | 92 | ledD3 = 1; |
niclasesterl | 0:cd2e365c7a90 | 93 | ledD4 = 1; |
niclasesterl | 0:cd2e365c7a90 | 94 | } |
niclasesterl | 0:cd2e365c7a90 | 95 | if (x == 24){ |
niclasesterl | 0:cd2e365c7a90 | 96 | ledD1 = 1; |
niclasesterl | 0:cd2e365c7a90 | 97 | ledD2 = 1; |
niclasesterl | 0:cd2e365c7a90 | 98 | ledD3 = 1; |
niclasesterl | 0:cd2e365c7a90 | 99 | ledD4 = 1; |
niclasesterl | 0:cd2e365c7a90 | 100 | ledD13 = 1; |
niclasesterl | 0:cd2e365c7a90 | 101 | } |
niclasesterl | 0:cd2e365c7a90 | 102 | |
niclasesterl | 0:cd2e365c7a90 | 103 | if (x == 25){ |
niclasesterl | 0:cd2e365c7a90 | 104 | ledD1 = 1; |
niclasesterl | 0:cd2e365c7a90 | 105 | ledD2 = 1; |
niclasesterl | 0:cd2e365c7a90 | 106 | ledD3 = 1; |
niclasesterl | 0:cd2e365c7a90 | 107 | ledD4 = 1; |
niclasesterl | 0:cd2e365c7a90 | 108 | ledD13 = 1; |
niclasesterl | 0:cd2e365c7a90 | 109 | ledD14 = 1; |
niclasesterl | 0:cd2e365c7a90 | 110 | ledGR = 1; |
niclasesterl | 0:cd2e365c7a90 | 111 | ledBL = 0; |
niclasesterl | 0:cd2e365c7a90 | 112 | ledRT = 0; |
niclasesterl | 0:cd2e365c7a90 | 113 | } |
niclasesterl | 0:cd2e365c7a90 | 114 | else if (x == 26){ |
niclasesterl | 0:cd2e365c7a90 | 115 | ledD1 = 1; |
niclasesterl | 0:cd2e365c7a90 | 116 | ledD2 = 1; |
niclasesterl | 0:cd2e365c7a90 | 117 | ledD3 = 1; |
niclasesterl | 0:cd2e365c7a90 | 118 | ledD4 = 1; |
niclasesterl | 0:cd2e365c7a90 | 119 | ledD13 = 1; |
niclasesterl | 0:cd2e365c7a90 | 120 | ledD14 = 1; |
niclasesterl | 0:cd2e365c7a90 | 121 | ledD15 = 1; |
niclasesterl | 0:cd2e365c7a90 | 122 | } |
niclasesterl | 0:cd2e365c7a90 | 123 | else if (x == 27){ |
niclasesterl | 0:cd2e365c7a90 | 124 | ledD1 = 1; |
niclasesterl | 0:cd2e365c7a90 | 125 | ledD2 = 1; |
niclasesterl | 0:cd2e365c7a90 | 126 | ledD3 = 1; |
niclasesterl | 0:cd2e365c7a90 | 127 | ledD4 = 1; |
niclasesterl | 0:cd2e365c7a90 | 128 | ledD13 = 1; |
niclasesterl | 0:cd2e365c7a90 | 129 | ledD14 = 1; |
niclasesterl | 0:cd2e365c7a90 | 130 | ledD15 = 1; |
niclasesterl | 0:cd2e365c7a90 | 131 | ledD16 = 1; |
niclasesterl | 0:cd2e365c7a90 | 132 | } |
niclasesterl | 0:cd2e365c7a90 | 133 | else if (x == 28){ |
niclasesterl | 0:cd2e365c7a90 | 134 | ledD1 = 1; |
niclasesterl | 0:cd2e365c7a90 | 135 | ledD2 = 1; |
niclasesterl | 0:cd2e365c7a90 | 136 | ledD3 = 1; |
niclasesterl | 0:cd2e365c7a90 | 137 | ledD4 = 1; |
niclasesterl | 0:cd2e365c7a90 | 138 | ledD13 = 1; |
niclasesterl | 0:cd2e365c7a90 | 139 | ledD14 = 1; |
niclasesterl | 0:cd2e365c7a90 | 140 | ledD15 = 1; |
niclasesterl | 0:cd2e365c7a90 | 141 | ledD16 = 1; |
niclasesterl | 0:cd2e365c7a90 | 142 | ledD17 = 1; |
niclasesterl | 0:cd2e365c7a90 | 143 | } |
niclasesterl | 0:cd2e365c7a90 | 144 | else if (x == 29){ |
niclasesterl | 0:cd2e365c7a90 | 145 | ledD1 = 1; |
niclasesterl | 0:cd2e365c7a90 | 146 | ledD2 = 1; |
niclasesterl | 0:cd2e365c7a90 | 147 | ledD3 = 1; |
niclasesterl | 0:cd2e365c7a90 | 148 | ledD4 = 1; |
niclasesterl | 0:cd2e365c7a90 | 149 | ledD13 = 1; |
niclasesterl | 0:cd2e365c7a90 | 150 | ledD14 = 1; |
niclasesterl | 0:cd2e365c7a90 | 151 | ledD15 = 1; |
niclasesterl | 0:cd2e365c7a90 | 152 | ledD16 = 1; |
niclasesterl | 0:cd2e365c7a90 | 153 | ledD17 = 1; |
niclasesterl | 0:cd2e365c7a90 | 154 | ledD18 = 1; |
niclasesterl | 0:cd2e365c7a90 | 155 | } |
niclasesterl | 0:cd2e365c7a90 | 156 | else if (x == 30){ |
niclasesterl | 0:cd2e365c7a90 | 157 | ledD1 = 1; |
niclasesterl | 0:cd2e365c7a90 | 158 | ledD2 = 1; |
niclasesterl | 0:cd2e365c7a90 | 159 | ledD3 = 1; |
niclasesterl | 0:cd2e365c7a90 | 160 | ledD4 = 1; |
niclasesterl | 0:cd2e365c7a90 | 161 | ledD13 = 1; |
niclasesterl | 0:cd2e365c7a90 | 162 | ledD14 = 1; |
niclasesterl | 0:cd2e365c7a90 | 163 | ledD15 = 1; |
niclasesterl | 0:cd2e365c7a90 | 164 | ledD16 = 1; |
niclasesterl | 0:cd2e365c7a90 | 165 | ledD17 = 1; |
niclasesterl | 0:cd2e365c7a90 | 166 | ledD18 = 1; |
niclasesterl | 0:cd2e365c7a90 | 167 | ledD19 = 1; |
niclasesterl | 0:cd2e365c7a90 | 168 | } |
niclasesterl | 0:cd2e365c7a90 | 169 | else if (x > 30){ |
niclasesterl | 0:cd2e365c7a90 | 170 | ledD1 = 1; |
niclasesterl | 0:cd2e365c7a90 | 171 | ledD2 = 1; |
niclasesterl | 0:cd2e365c7a90 | 172 | ledD3 = 1; |
niclasesterl | 0:cd2e365c7a90 | 173 | ledD4 = 1; |
niclasesterl | 0:cd2e365c7a90 | 174 | ledD13 = 1; |
niclasesterl | 0:cd2e365c7a90 | 175 | ledD14 = 1; |
niclasesterl | 0:cd2e365c7a90 | 176 | ledD15 = 1; |
niclasesterl | 0:cd2e365c7a90 | 177 | ledD16 = 1; |
niclasesterl | 0:cd2e365c7a90 | 178 | ledD17 = 1; |
niclasesterl | 0:cd2e365c7a90 | 179 | ledD18 = 1; |
niclasesterl | 0:cd2e365c7a90 | 180 | ledD19 = 1; |
niclasesterl | 0:cd2e365c7a90 | 181 | ledD20 = 1; |
niclasesterl | 0:cd2e365c7a90 | 182 | } |
niclasesterl | 0:cd2e365c7a90 | 183 | } |