![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Eindprogramma met alle functies
Dependencies: DS1307 EthernetInterface TextLCD WebSocketClient mbed-rtos mbed
Fork of Hoofdprogramma by
Hoofdprogramma.cpp@1:386b4ee674e3, 2014-11-27 (annotated)
- Committer:
- R0375604
- Date:
- Thu Nov 27 10:37:28 2014 +0000
- Revision:
- 1:386b4ee674e3
- Parent:
- 0:f99036b05ce9
- Child:
- 2:52f7cccebdea
Hoofdprogramma Versie 2
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
R0375604 | 0:f99036b05ce9 | 1 | #include "mbed.h" |
R0375604 | 0:f99036b05ce9 | 2 | #include "TextLCD.h" |
R0375604 | 0:f99036b05ce9 | 3 | |
R0375604 | 0:f99036b05ce9 | 4 | // Declaratie van de Pinnen & variabelen |
R0375604 | 0:f99036b05ce9 | 5 | AnalogIn Temp1(p20); |
R0375604 | 0:f99036b05ce9 | 6 | AnalogIn Temp2(p19); |
R0375604 | 0:f99036b05ce9 | 7 | AnalogIn Temp3(p18); |
R0375604 | 0:f99036b05ce9 | 8 | |
R0375604 | 0:f99036b05ce9 | 9 | DigitalIn Druk1(p11); // temp1 |
R0375604 | 0:f99036b05ce9 | 10 | DigitalIn Druk2(p12); // temp2 |
R0375604 | 0:f99036b05ce9 | 11 | DigitalIn Druk3(p13); // temp3 |
R0375604 | 0:f99036b05ce9 | 12 | DigitalIn Down(p14); // up |
R0375604 | 0:f99036b05ce9 | 13 | DigitalIn Up(p15); // down |
R0375604 | 0:f99036b05ce9 | 14 | |
R0375604 | 1:386b4ee674e3 | 15 | DigitalOut Relais(p29); // pin voor de Relais |
R0375604 | 0:f99036b05ce9 | 16 | |
R0375604 | 0:f99036b05ce9 | 17 | PwmOut Servo(p21); // servo motor |
R0375604 | 0:f99036b05ce9 | 18 | PwmOut R(p22); // RGB => Rood |
R0375604 | 0:f99036b05ce9 | 19 | PwmOut G(p23); // RGB => Groen |
R0375604 | 0:f99036b05ce9 | 20 | PwmOut B(p24); // RGB => Blauw |
R0375604 | 0:f99036b05ce9 | 21 | PwmOut LedB(p25); // Blauwe Led als relais Uit is (Te warm) |
R0375604 | 0:f99036b05ce9 | 22 | PwmOut LedG(p26); // Groene Led als relais Uit is (Temp GOED) |
R0375604 | 0:f99036b05ce9 | 23 | |
R0375604 | 0:f99036b05ce9 | 24 | TextLCD lcd(p5, p6, p7, p8, p9, p10); |
R0375604 | 0:f99036b05ce9 | 25 | |
R0375604 | 0:f99036b05ce9 | 26 | float InstelTemp1 = 22; // De Gewenste Temperatuur |
R0375604 | 0:f99036b05ce9 | 27 | float InstelTemp2 = 22; |
R0375604 | 0:f99036b05ce9 | 28 | float InstelTemp3 = 22; |
R0375604 | 0:f99036b05ce9 | 29 | |
R0375604 | 0:f99036b05ce9 | 30 | float temp1 = 0; |
R0375604 | 0:f99036b05ce9 | 31 | float temp2 = 0; |
R0375604 | 0:f99036b05ce9 | 32 | float temp3 = 0; |
R0375604 | 0:f99036b05ce9 | 33 | |
R0375604 | 0:f99036b05ce9 | 34 | int main() |
R0375604 | 0:f99036b05ce9 | 35 | { |
R0375604 | 0:f99036b05ce9 | 36 | R.period_ms(20.0f); // 20 msecond period |
R0375604 | 0:f99036b05ce9 | 37 | G.period_ms(20.0f); // 20 msecond period |
R0375604 | 0:f99036b05ce9 | 38 | B.period_ms(20.0f); // 20 msecond period |
R0375604 | 1:386b4ee674e3 | 39 | LedB.period_ms(20.0f); // 20 msecond period |
R0375604 | 0:f99036b05ce9 | 40 | LedG.period_ms(20.0f); // 20 msecond period |
R0375604 | 0:f99036b05ce9 | 41 | |
R0375604 | 0:f99036b05ce9 | 42 | lcd.cls(); // LCD Clearen |
R0375604 | 0:f99036b05ce9 | 43 | |
R0375604 | 0:f99036b05ce9 | 44 | while(1) |
R0375604 | 0:f99036b05ce9 | 45 | { |
R0375604 | 0:f99036b05ce9 | 46 | float temp1 = 0; |
R0375604 | 0:f99036b05ce9 | 47 | float temp2 = 0; |
R0375604 | 0:f99036b05ce9 | 48 | float temp3 = 0; |
R0375604 | 1:386b4ee674e3 | 49 | //------------- Gewenste TEMP instellen ------------------------------------ |
R0375604 | 0:f99036b05ce9 | 50 | while(Druk1) // Gewenste Temp1 Instellen |
R0375604 | 0:f99036b05ce9 | 51 | { |
R0375604 | 0:f99036b05ce9 | 52 | lcd.locate(0,0); |
R0375604 | 0:f99036b05ce9 | 53 | lcd.printf("Instel Temp1 = "); |
R0375604 | 0:f99036b05ce9 | 54 | lcd.locate(0,1); |
R0375604 | 0:f99036b05ce9 | 55 | lcd.printf("%4.1f C ",InstelTemp1); |
R0375604 | 0:f99036b05ce9 | 56 | if(Down) |
R0375604 | 0:f99036b05ce9 | 57 | { |
R0375604 | 0:f99036b05ce9 | 58 | InstelTemp1 += 0.5; |
R0375604 | 0:f99036b05ce9 | 59 | lcd.locate(0,0); |
R0375604 | 0:f99036b05ce9 | 60 | lcd.printf("Instel Temp1 = "); |
R0375604 | 0:f99036b05ce9 | 61 | lcd.locate(0,1); |
R0375604 | 0:f99036b05ce9 | 62 | lcd.printf("%4.1f C ",InstelTemp1); |
R0375604 | 0:f99036b05ce9 | 63 | wait(0.5); |
R0375604 | 0:f99036b05ce9 | 64 | } |
R0375604 | 0:f99036b05ce9 | 65 | else if(Up) |
R0375604 | 0:f99036b05ce9 | 66 | { |
R0375604 | 0:f99036b05ce9 | 67 | InstelTemp1 -= 0.5; |
R0375604 | 0:f99036b05ce9 | 68 | lcd.locate(0,0); |
R0375604 | 0:f99036b05ce9 | 69 | lcd.printf("Instel Temp1 = "); |
R0375604 | 0:f99036b05ce9 | 70 | lcd.locate(0,1); |
R0375604 | 0:f99036b05ce9 | 71 | lcd.printf("%4.1f C ",InstelTemp1); |
R0375604 | 0:f99036b05ce9 | 72 | wait(0.5); |
R0375604 | 0:f99036b05ce9 | 73 | } |
R0375604 | 0:f99036b05ce9 | 74 | } |
R0375604 | 0:f99036b05ce9 | 75 | lcd.cls(); // LCD Clearen |
R0375604 | 0:f99036b05ce9 | 76 | while(Druk2) // Gewenste Temp2 Instellen |
R0375604 | 0:f99036b05ce9 | 77 | { |
R0375604 | 0:f99036b05ce9 | 78 | lcd.locate(0,0); |
R0375604 | 0:f99036b05ce9 | 79 | lcd.printf("Instel Temp2 = "); |
R0375604 | 0:f99036b05ce9 | 80 | lcd.locate(0,1); |
R0375604 | 0:f99036b05ce9 | 81 | lcd.printf("%4.1f C ",InstelTemp2); |
R0375604 | 0:f99036b05ce9 | 82 | if(Down) |
R0375604 | 0:f99036b05ce9 | 83 | { |
R0375604 | 0:f99036b05ce9 | 84 | InstelTemp2 += 0.5; |
R0375604 | 0:f99036b05ce9 | 85 | lcd.locate(0,0); |
R0375604 | 0:f99036b05ce9 | 86 | lcd.printf("Instel Temp2 = "); |
R0375604 | 0:f99036b05ce9 | 87 | lcd.locate(0,1); |
R0375604 | 0:f99036b05ce9 | 88 | lcd.printf("%4.1f C ",InstelTemp2); |
R0375604 | 0:f99036b05ce9 | 89 | wait(0.5); |
R0375604 | 0:f99036b05ce9 | 90 | } |
R0375604 | 0:f99036b05ce9 | 91 | else if(Up) |
R0375604 | 0:f99036b05ce9 | 92 | { |
R0375604 | 0:f99036b05ce9 | 93 | InstelTemp2 -= 0.5; |
R0375604 | 0:f99036b05ce9 | 94 | lcd.locate(0,0); |
R0375604 | 0:f99036b05ce9 | 95 | lcd.printf("Instel Temp2 = "); |
R0375604 | 0:f99036b05ce9 | 96 | lcd.locate(0,1); |
R0375604 | 0:f99036b05ce9 | 97 | lcd.printf("%4.1f C ",InstelTemp2); |
R0375604 | 0:f99036b05ce9 | 98 | wait(0.5); |
R0375604 | 0:f99036b05ce9 | 99 | } |
R0375604 | 0:f99036b05ce9 | 100 | } |
R0375604 | 0:f99036b05ce9 | 101 | lcd.cls(); // LCD Clearen |
R0375604 | 0:f99036b05ce9 | 102 | while(Druk3) // Gewenste Temp3 Instellen |
R0375604 | 0:f99036b05ce9 | 103 | { |
R0375604 | 0:f99036b05ce9 | 104 | lcd.locate(0,0); |
R0375604 | 0:f99036b05ce9 | 105 | lcd.printf("Instel Temp3 = "); |
R0375604 | 0:f99036b05ce9 | 106 | lcd.locate(0,1); |
R0375604 | 0:f99036b05ce9 | 107 | lcd.printf("%4.1f C ",InstelTemp3); |
R0375604 | 0:f99036b05ce9 | 108 | if(Down) |
R0375604 | 0:f99036b05ce9 | 109 | { |
R0375604 | 0:f99036b05ce9 | 110 | InstelTemp3 += 0.5; |
R0375604 | 0:f99036b05ce9 | 111 | lcd.locate(0,0); |
R0375604 | 0:f99036b05ce9 | 112 | lcd.printf("Instel Temp3 = "); |
R0375604 | 0:f99036b05ce9 | 113 | lcd.locate(0,1); |
R0375604 | 0:f99036b05ce9 | 114 | lcd.printf("%4.1f C ",InstelTemp3); |
R0375604 | 0:f99036b05ce9 | 115 | wait(0.5); |
R0375604 | 0:f99036b05ce9 | 116 | } |
R0375604 | 0:f99036b05ce9 | 117 | else if(Up) |
R0375604 | 0:f99036b05ce9 | 118 | { |
R0375604 | 0:f99036b05ce9 | 119 | InstelTemp3 -= 0.5; |
R0375604 | 0:f99036b05ce9 | 120 | lcd.locate(0,0); |
R0375604 | 0:f99036b05ce9 | 121 | lcd.printf("Instel Temp3 = "); |
R0375604 | 0:f99036b05ce9 | 122 | lcd.locate(0,1); |
R0375604 | 0:f99036b05ce9 | 123 | lcd.printf("%4.1f C ",InstelTemp3); |
R0375604 | 0:f99036b05ce9 | 124 | wait(0.5); |
R0375604 | 0:f99036b05ce9 | 125 | } |
R0375604 | 0:f99036b05ce9 | 126 | } |
R0375604 | 1:386b4ee674e3 | 127 | //------------------------------------------------------------------------------------ |
R0375604 | 1:386b4ee674e3 | 128 | lcd.cls(); // LCD Clearen |
R0375604 | 0:f99036b05ce9 | 129 | for(int t=0; t<100; t++) // Inlezen van de Temperatuur |
R0375604 | 0:f99036b05ce9 | 130 | { |
R0375604 | 0:f99036b05ce9 | 131 | temp1 = temp1 +Temp1.read(); // Temp1 inlezen |
R0375604 | 0:f99036b05ce9 | 132 | temp2 = temp2 +Temp2.read(); // Temp2 inlezen |
R0375604 | 0:f99036b05ce9 | 133 | temp3 = temp3 +Temp3.read(); // Temp3 inlezen |
R0375604 | 0:f99036b05ce9 | 134 | } |
R0375604 | 0:f99036b05ce9 | 135 | |
R0375604 | 0:f99036b05ce9 | 136 | temp1 = (temp1*3.3) - 3; // Bewerking voor de Temp in graden te bekomen. |
R0375604 | 0:f99036b05ce9 | 137 | temp2 *= 3.3; |
R0375604 | 0:f99036b05ce9 | 138 | temp3 *= 3.3; |
R0375604 | 1:386b4ee674e3 | 139 | //-------------- LCD Printen---------------------------------------------------------- |
R0375604 | 0:f99036b05ce9 | 140 | lcd.locate(0,0); // De ingelezen Temperatuur op de LCD zetten |
R0375604 | 0:f99036b05ce9 | 141 | lcd.printf("Temperatuur 1 = "); |
R0375604 | 0:f99036b05ce9 | 142 | lcd.locate(0,1); |
R0375604 | 0:f99036b05ce9 | 143 | lcd.printf("%4.1f C ",temp1); |
R0375604 | 1:386b4ee674e3 | 144 | wait(1.5); |
R0375604 | 0:f99036b05ce9 | 145 | lcd.cls(); |
R0375604 | 0:f99036b05ce9 | 146 | lcd.locate(0,0); |
R0375604 | 0:f99036b05ce9 | 147 | lcd.printf("Temperatuur 2 = "); |
R0375604 | 0:f99036b05ce9 | 148 | lcd.locate(0,1); |
R0375604 | 0:f99036b05ce9 | 149 | lcd.printf("%4.1f C ",temp2); |
R0375604 | 1:386b4ee674e3 | 150 | wait(1.5); |
R0375604 | 0:f99036b05ce9 | 151 | lcd.cls(); |
R0375604 | 0:f99036b05ce9 | 152 | lcd.locate(0,0); |
R0375604 | 0:f99036b05ce9 | 153 | lcd.printf("Temperatuur 3 = "); |
R0375604 | 0:f99036b05ce9 | 154 | lcd.locate(0,1); |
R0375604 | 0:f99036b05ce9 | 155 | lcd.printf("%4.1f C ",temp3); |
R0375604 | 1:386b4ee674e3 | 156 | wait(1.5); |
R0375604 | 1:386b4ee674e3 | 157 | //-----------// RGB => Temperatuur 1// ------------------------------------------------------------ |
R0375604 | 0:f99036b05ce9 | 158 | if(temp1 > InstelTemp1 + 2) // Temp is te HOOG => Blauwe led |
R0375604 | 0:f99036b05ce9 | 159 | { |
R0375604 | 0:f99036b05ce9 | 160 | R.write(0.00f); // 0% duty cycle |
R0375604 | 0:f99036b05ce9 | 161 | G.write(0.00f); // 0% duty cycle |
R0375604 | 0:f99036b05ce9 | 162 | B.write(0.50f); // 50% duty cycle |
R0375604 | 0:f99036b05ce9 | 163 | } |
R0375604 | 0:f99036b05ce9 | 164 | else if (temp1 < InstelTemp1 - 2) // Temp is te LAAG => Rode led |
R0375604 | 0:f99036b05ce9 | 165 | { |
R0375604 | 0:f99036b05ce9 | 166 | R.write(0.50f); // 50% duty cycle |
R0375604 | 0:f99036b05ce9 | 167 | G.write(0.00f); // 0% duty cycle |
R0375604 | 0:f99036b05ce9 | 168 | B.write(0.00f); // 0% duty cycle |
R0375604 | 0:f99036b05ce9 | 169 | } |
R0375604 | 0:f99036b05ce9 | 170 | else // Temp is te GOED => Groene led |
R0375604 | 0:f99036b05ce9 | 171 | { |
R0375604 | 0:f99036b05ce9 | 172 | R.write(0.00f); // 0% duty cycle |
R0375604 | 0:f99036b05ce9 | 173 | G.write(0.50f); // 50% duty cycle |
R0375604 | 0:f99036b05ce9 | 174 | B.write(0.00f); // 0% duty cycle |
R0375604 | 1:386b4ee674e3 | 175 | } |
R0375604 | 1:386b4ee674e3 | 176 | //-----------// Relais => Temperatuur 2// ------------------------------------------------------------ |
R0375604 | 1:386b4ee674e3 | 177 | if(temp2 > InstelTemp2 + 2) // Temp is te HOOG => Blauwe led |
R0375604 | 1:386b4ee674e3 | 178 | { |
R0375604 | 1:386b4ee674e3 | 179 | Relais = 0; // Temp is te HOOG dus moet afkoelen (Niet verwarmen) |
R0375604 | 1:386b4ee674e3 | 180 | LedB.write(0.50f); // 50% duty cycle |
R0375604 | 1:386b4ee674e3 | 181 | LedG.write(0.00f); // 0% duty cycle |
R0375604 | 1:386b4ee674e3 | 182 | |
R0375604 | 1:386b4ee674e3 | 183 | } |
R0375604 | 1:386b4ee674e3 | 184 | else if (temp2 < InstelTemp2 - 2) // Temp is te LAAG => Blauwe led |
R0375604 | 1:386b4ee674e3 | 185 | { |
R0375604 | 1:386b4ee674e3 | 186 | Relais = 1; // Temp is te LAAG Dus verwarmen |
R0375604 | 1:386b4ee674e3 | 187 | } |
R0375604 | 1:386b4ee674e3 | 188 | else // Temp is te GOED => Groene led |
R0375604 | 1:386b4ee674e3 | 189 | { |
R0375604 | 1:386b4ee674e3 | 190 | Relais = 0; // Tem is GOED dus niets doen |
R0375604 | 1:386b4ee674e3 | 191 | LedB.write(0.00f); // 0% duty cycle |
R0375604 | 1:386b4ee674e3 | 192 | LedG.write(0.50f); // 50% duty cycle |
R0375604 | 1:386b4ee674e3 | 193 | } |
R0375604 | 1:386b4ee674e3 | 194 | //-----------// Servo => Temparatur 3 // ------------------------------------------------------------ |
R0375604 | 1:386b4ee674e3 | 195 | if(temp3 > InstelTemp3 + 2) // Temp is te HOOG => Servo Rechts |
R0375604 | 1:386b4ee674e3 | 196 | { |
R0375604 | 1:386b4ee674e3 | 197 | Servo = (170 * 0.000511 + 0.026); // rechts |
R0375604 | 1:386b4ee674e3 | 198 | wait(2); |
R0375604 | 1:386b4ee674e3 | 199 | } |
R0375604 | 1:386b4ee674e3 | 200 | else if (temp3 < InstelTemp3 - 2) // Temp is te LAAG => Servo Links |
R0375604 | 1:386b4ee674e3 | 201 | { |
R0375604 | 1:386b4ee674e3 | 202 | Servo = (7 * 0.000511 + 0.026); // links 7 |
R0375604 | 1:386b4ee674e3 | 203 | wait(2); |
R0375604 | 1:386b4ee674e3 | 204 | } |
R0375604 | 1:386b4ee674e3 | 205 | else // Temp is te GOED => Servo Midden |
R0375604 | 1:386b4ee674e3 | 206 | { |
R0375604 | 1:386b4ee674e3 | 207 | Servo = (90 * 0.000511 + 0.026); // rust |
R0375604 | 1:386b4ee674e3 | 208 | wait(2); |
R0375604 | 1:386b4ee674e3 | 209 | } |
R0375604 | 1:386b4ee674e3 | 210 | //------------------------------------------------------------------------------ |
R0375604 | 0:f99036b05ce9 | 211 | } |
R0375604 | 0:f99036b05ce9 | 212 | } |
R0375604 | 0:f99036b05ce9 | 213 | |
R0375604 | 0:f99036b05ce9 | 214 | |
R0375604 | 0:f99036b05ce9 | 215 | |
R0375604 | 0:f99036b05ce9 | 216 | |
R0375604 | 0:f99036b05ce9 | 217 | |
R0375604 | 0:f99036b05ce9 | 218 |