testfase
Dependencies: TextLCD mbed DS1307 Servo
Diff: main.cpp
- Revision:
- 0:09e0c8d681a8
- Child:
- 1:83cbca2c2d86
diff -r 000000000000 -r 09e0c8d681a8 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Thu Nov 27 10:09:27 2014 +0000 @@ -0,0 +1,158 @@ +//Library's +#include "mbed.h" +#include "TextLCD.h" + +//Pin initialisatie +Serial pc(USBTX,USBRX); +AnalogIn temp1(p20); +AnalogIn temp2(p19); +DigitalIn knopUP(p5); +DigitalIn knopDOWN(p6); +DigitalIn knopINSTEL(p7); +DigitalIn knopBACK(p8); +DigitalOut myled1(LED1); +DigitalOut myled2(LED2); +DigitalOut myled3(LED3); +TextLCD lcd(p15, p16, p21, p22, p23, p24); // rs, e, d4-d7 +PwmOut Servo(p25); + +//variabelen declareren/initialiseren +float i = 0; +float j = 0; +int temperatuur = 20; +int counter = 0; +int teller = 0; + +//Main Programma +int main() +{ + pc.printf("\x1B\x48\x1B\x4A"); + pc.printf("Temperatuur"); + while(1) + { +/*------------------------------------------------------------------------*/ + //Seriele communicatie met pc + pc.printf("\x1B\x48"); + i=0; + j=0; +/*------------------------------------------------------------------------*/ + //Temperatuur inlezen + for(int t=0;t<100;t++) + { + i=i+temp1.read(); + + } + for(int k=0;k<100;k++) + { + j=j+temp2.read(); + } +/*------------------------------------------------------------------------*/ + //Motor aansturen + Servo.period_ms(20); + if(knopUP) + { + Servo = (90 * 0.000511 + 0.026); // rust + wait(1); + Servo = (7 * 0.000511 + 0.026); // links 7 + wait(1); + Servo = (90 * 0.000511 + 0.026); // rust + wait(1); + Servo = (170 * 0.000511 + 0.026); // rechts + wait(1); + } +/*------------------------------------------------------------------------*/ + //Menu Instellingen + if(knopINSTEL) + { + teller = 0; + wait(0.3); + lcd.cls(); + while(knopBACK == 0) + { + lcd.locate(0,0); + lcd.printf(" Instellen Temp"); + lcd.locate(0,1); + lcd.printf(" Temp = %iC", temperatuur); + if(knopUP) + { + temperatuur = temperatuur + 1; + if(temperatuur > 30) + { + temperatuur = 20; + } + if(temperatuur < 20) + { + temperatuur = 30; + } + lcd.cls(); + lcd.locate(0,0); + lcd.printf("Ingestelde Temp"); + lcd.locate(0,1); + lcd.printf(" %iC ", temperatuur); + wait(0.6); + lcd.cls(); + } + if(knopDOWN) + { + temperatuur = temperatuur - 1; + if(temperatuur == 30) + { + temperatuur = 20; + } + if(temperatuur < 20) + { + temperatuur = 30; + } + lcd.cls(); + lcd.locate(0,0); + lcd.printf("Ingestelde Temp"); + lcd.locate(0,1); + lcd.printf(" %iC ", temperatuur); + wait(0.6); + lcd.cls(); + } + } + } +/*------------------------------------------------------------------------*/ + //Temperatuur instellen + /*if(knopUP) + { + temperatuur = temperatuur + 1; + if(temperatuur == 30) + { + temperatuur = 24; + } + lcd.cls(); + lcd.locate(0,0); + lcd.printf("ingestelde temp"); + lcd.locate(0,1); + lcd.printf(" %iC ", temperatuur); + wait(1); + }*/ +/*------------------------------------------------------------------------*/ + /*Temperatuur: Wanneer temperatuur hoger wordt dan ingesteld + zal een ledje dit aangeven*/ + if((i*3.3)>= temperatuur) + { + myled1 = 1; + } + if((i*3.3) < temperatuur) + { + myled1 = 0; + } +/*------------------------------------------------------------------------*/ + //LCD uitschrijven + counter++; + if(counter == 250) + { + lcd.cls(); + lcd.locate(0,0); + lcd.printf("Temp 1:%4.1fC", i*3.3); + lcd.locate(0,1); + lcd.printf("Temp 2:%4.1fC", j*3.3); + pc.printf("\n\n\rTemperature1 %4.1f C ",i*3.3); + pc.printf("\n\rTemperature2 %4.1f C ",j*3.3); + counter = 0; + } + } +} \ No newline at end of file