![](/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
- Committer:
- R0375604
- Date:
- 2014-12-16
- Revision:
- 5:1c493bae26fc
- Parent:
- 4:15258c48d16f
- Child:
- 6:c95e2d561599
File content as of revision 5:1c493bae26fc:
// Pieter Essers & Bjorn Vranken GROEP5 // Digitale Temp Meting en aansturingen via // RGB LED // SERVO // RELAIS #include "mbed.h" #include "TextLCD.h" #include "ds1307.h" // Declaratie van de Pinnen & variabelen AnalogIn Temp1(p20); AnalogIn Temp2(p19); AnalogIn Temp3(p18); DigitalIn Druk1(p15); // temp1 DigitalIn Druk2(p11); // temp2 DigitalIn Druk3(p14); // temp3 DigitalIn Down(p13); // up DigitalIn Up(p12); // down DigitalOut Relais(p29); // pin voor de Relais PwmOut Servo(p21); // servo motor PwmOut R(p23); // RGB => Rood PwmOut G(p24); // RGB => Groen PwmOut B(p22); // RGB => Blauw PwmOut LedB(p25); // Blauwe Led als relais Uit is (Te warm) PwmOut LedG(p26); // Groene Led als relais Uit is (Temp GOED) TextLCD lcd(p5, p6, p7, p8, p9, p10); // LCD DS1307 my1307(p28,p27); // start DS1307 class and give it pins for connections of the DS1307 device int sec; int min; int hours; int day; int date; int month; int year; float InstelTemp1 = 21; // De Gewenste Temperatuur float InstelTemp2 = 21; float InstelTemp3 = 21; float temp1 = 0; float temp2 = 0; float temp3 = 0; //int teller = 0; // om een wachtlus te maken. void test_rw(int test) // Test voor de RTC { } int main() { lcd.cls(); // LCD Clearen R.period_ms(20.0f); // 20 msecond period (50Hz) G.period_ms(20.0f); // 20 msecond period (50Hz) B.period_ms(20.0f); // 20 msecond period LedB.period_ms(20.0f); // 20 msecond period LedG.period_ms(20.0f); // 20 msecond period lcd.cls(); // LCD Clearen while(1) { my1307.gettime( &sec, &min, &hours, &day, &date, &month, &year); float temp1 = 0; float temp2 = 0; float temp3 = 0; //------------- De Tijd op de LCD printen ------------------------------------ //------------- Enkel laten zien wanneer je op drukknop drukt----------------- while(Up) { my1307.gettime( &sec, &min, &hours, &day, &date, &month, &year); wait(0.5); lcd.cls(); lcd.locate(0,0); lcd.printf("%d:%d:%d",hours,min,sec); lcd.locate(0,1); lcd.printf("%d/%d/%d",date,month,year); } //------------- Gewenste TEMP instellen ------------------------------------ while(Druk1) // Gewenste Temp1 Instellen { lcd.locate(0,0); lcd.printf("Instel Temp1 = "); lcd.locate(0,1); lcd.printf("%4.1f C ",InstelTemp1); if(Down) { InstelTemp1 += 0.5; lcd.locate(0,0); lcd.printf("Instel Temp1 = "); lcd.locate(0,1); lcd.printf("%4.1f C ",InstelTemp1); wait(0.5); } else if(Up) { InstelTemp1 -= 0.5; lcd.locate(0,0); lcd.printf("Instel Temp1 = "); lcd.locate(0,1); lcd.printf("%4.1f C ",InstelTemp1); wait(0.5); } } lcd.cls(); // LCD Clearen while(Druk2) // Gewenste Temp2 Instellen { lcd.locate(0,0); lcd.printf("Instel Temp2 = "); lcd.locate(0,1); lcd.printf("%4.1f C ",InstelTemp2); if(Down) { InstelTemp2 += 0.5; lcd.locate(0,0); lcd.printf("Instel Temp2 = "); lcd.locate(0,1); lcd.printf("%4.1f C ",InstelTemp2); wait(0.5); } else if(Up) { InstelTemp2 -= 0.5; lcd.locate(0,0); lcd.printf("Instel Temp2 = "); lcd.locate(0,1); lcd.printf("%4.1f C ",InstelTemp2); wait(0.5); } } lcd.cls(); // LCD Clearen while(Druk3) // Gewenste Temp3 Instellen { lcd.locate(0,0); lcd.printf("Instel Temp3 = "); lcd.locate(0,1); lcd.printf("%4.1f C ",InstelTemp3); if(Down) { InstelTemp3 += 0.5; lcd.locate(0,0); lcd.printf("Instel Temp3 = "); lcd.locate(0,1); lcd.printf("%4.1f C ",InstelTemp3); wait(0.5); } else if(Up) { InstelTemp3 -= 0.5; lcd.locate(0,0); lcd.printf("Instel Temp3 = "); lcd.locate(0,1); lcd.printf("%4.1f C ",InstelTemp3); wait(0.5); } } //------------------------------------------------------------------------------------ for(int t=0; t<100; t++) // Inlezen van de Temperatuur { temp1 = temp1 +Temp1.read(); // Temp1 inlezen temp2 = temp2 +Temp2.read(); // Temp2 inlezen temp3 = temp3 +Temp3.read(); // Temp3 inlezen } temp1 = (temp1 *3.3) + 3; // Bewerking voor de Temp in graden te bekomen. temp2 = (temp2 *3.3) + 3; temp3 = (temp3 *3.3) + 3; //-------------- LCD Printen---------------------------------------------------------- lcd.locate(0,0); // De ingelezen Temperatuur op de LCD zetten lcd.printf("Temperatuur 1 = "); lcd.locate(0,1); lcd.printf("%4.1f C ",temp1); wait(1.5); lcd.cls(); lcd.locate(0,0); lcd.printf("Temperatuur 2 = "); lcd.locate(0,1); lcd.printf("%4.1f C ",temp2); wait(1.5); lcd.cls(); lcd.locate(0,0); lcd.printf("Temperatuur 3 = "); lcd.locate(0,1); lcd.printf("%4.1f C ",temp3); wait(1.5); //-----------// RGB => Temperatuur 1// WAARSCHUWIGS SIGNAAL-------------------------------------------------------- //------Naarmate temp verder van gewenste waarde zit een andre RGB kleur-------------- //------------------------Te warme Temp----------------------------------------------- if(InstelTemp1 + 1 < temp1 && temp1 <= InstelTemp1 + 2) { R.write(0.50f); // 50% duty cycle Geel G.write(0.50f); // 50% duty cycle B.write(0.00f); // 0% duty cycle } else if(InstelTemp1 + 2 < temp1 && temp1 <= InstelTemp1 + 3) { R.write(0.75f); // 50% duty cycle Oranje G.write(0.25f); // 25% duty cycle B.write(0.00f); // 0% duty cycle } else if(InstelTemp1 + 3 < temp1) { R.write(0.50f); // 50% duty cycle Rood G.write(0.00f); // 0% duty cycle B.write(0.00f); // 0% duty cycle } //---------------Te koude temp---------------------------------------------- else if(InstelTemp1 - 1 > temp1 && temp1 >= InstelTemp1 - 2) { R.write(0.00f); // 0% duty cycle Licht blauw G.write(0.50f); // 50% duty cycle B.write(0.50f); // 50% duty cycle } else if(InstelTemp1 - 2 > temp1 && temp1 >= InstelTemp1 - 3) { R.write(0.00f); // 0% duty cycle Paars G.write(0.25f); // 25% duty cycle B.write(0.75f); // 75% duty cycle } else if(InstelTemp1 - 4 > temp1) { R.write(0.00f); // 0% duty cycle Paars G.write(0.00f); // 0% duty cycle B.write(0.50f); // 50% duty cycle } //-------------Goede Temp------------------------------------------------- else // Temp is te GOED => Groene led { R.write(0.00f); // 0% duty cycle G.write(0.50f); // 50% duty cycle B.write(0.00f); // 0% duty cycle } //-----------// Relais => Temperatuur 2// Moet met een transistor---------------------------------- if(temp2 > InstelTemp2 + 2) // Temp is te HOOG => Blauwe led { Relais = 0; // Temp is te HOOG dus moet afkoelen (Niet verwarmen) LedB.write(0.50f); // 50% duty cycle LedG.write(0.00f); // 0% duty cycle } else if (temp2 < InstelTemp2 - 2) // Temp is te LAAG => Rode led { Relais = 1; // Temp is te LAAG Dus verwarmen wait(0.5); LedB.write(0.00f); // 0% duty cycle LedG.write(0.00f); // 0% duty cycle } else // Temp is te GOED => Groene led { Relais = 0; // Tem is GOED dus niets doen LedB.write(0.00f); // 0% duty cycle LedG.write(0.50f); // 100% duty cycle } //-----------// Servo => Temparatur 3 // ------------------------------------------------------------ //---------------------Stappen naar rechts -> Te WARM----------------------------------------------- if(InstelTemp3 + 1 < temp3 && temp3 <= InstelTemp3 + 2) { Servo = (120 * 0.000511 + 0.026); // rechts } else if(InstelTemp3 + 2 < temp3 && temp3 <= InstelTemp3 + 3) { Servo = (140 * 0.000511 + 0.026); // rechts } else if(InstelTemp3 + 3 < temp3 && temp3 <= InstelTemp3 + 4) { Servo = (160 * 0.000511 + 0.026); // rechts } else if(InstelTemp3 + 4 < temp3) { Servo = (170 * 0.000511 + 0.026); // rechts } //---------------------Stappen naar links -> Te KOUD----------------------------------------------- else if(InstelTemp3 - 1 > temp3 && temp3 >= InstelTemp3 - 2) { Servo = (80 * 0.000511 + 0.026); // links } else if(InstelTemp3 - 2 > temp3 && temp3 >= InstelTemp3 - 3) { Servo = (60 * 0.000511 + 0.026); // links } else if(InstelTemp3 - 3 > temp3 && temp3 >= InstelTemp3 - 4) { Servo = (40 * 0.000511 + 0.026); // links } else if(InstelTemp3 - 4 > temp3) { Servo = (7 * 0.000511 + 0.026); // links } //--------------Temp is goed------------------------------------------------------------ else // Temp is te GOED => Servo Midden { Servo = (90 * 0.000511 + 0.026); // rust } //-------------------------------------------------------------------------------------------------- } }