Junxiang Wu / Mbed 2 deprecated essay_experiment

Dependencies:   C12832 LM75B mbed

Fork of app-shield-LM75B by Chris Styles

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "LM75B.h"
00003 #include "C12832.h"
00004 
00005 DigitalOut red (LED_RED);
00006 DigitalOut green(LED_GREEN);
00007 DigitalOut blue(LED_BLUE);
00008 DigitalIn up(A2);
00009 DigitalIn down(A3);
00010 DigitalIn left(A4);
00011 DigitalIn right(A5);
00012 DigitalIn fire(D4);
00013 AnalogIn pot1 (A0);
00014 AnalogIn pot2 (A1);
00015 C12832 lcd(D11, D13, D12, D7, D10);
00016 LM75B sensor(D14,D15);
00017 PwmOut spkr(D6);
00018 void start(void);
00019 void menu(void);
00020 int ctrl=3;
00021 int main ()
00022 {
00023     red = 1;
00024     green = 1;
00025     blue = 1;
00026     lcd.cls();
00027     start();
00028     menu();
00029     while(1) {
00030         if (left == 1) {
00031             ctrl = 1;
00032         }
00033         if (right == 1) {
00034             ctrl = 2;
00035         }
00036         if (up == 1) {
00037             ctrl = 1;
00038         }
00039         if (down == 1) {
00040             ctrl = 2;
00041         }
00042         if (fire == 1){
00043             ctrl = 0;
00044             }
00045         switch (ctrl){
00046         case 0:
00047             menu();
00048             break;
00049         case 1:
00050             while(1) {
00051                 lcd.cls();
00052                 lcd.locate(0,3);
00053                 lcd.printf("Temp = %.1f\n", sensor.temp());
00054                 float i = 0.0;
00055                 i = sensor.temp();
00056                 if (i>28.0) {
00057                     blue =1;
00058                     green = 1;
00059                     red = 0;
00060                 lcd.locate(0,15);
00061                 lcd.printf("So Hot!");
00062                 } else if (i<18.0) {
00063                     red = 1;
00064                     green = 1;
00065                     blue = 0;
00066                 lcd.locate(0,15);
00067                 lcd.printf("Really Cold.....");
00068                 } else {
00069                     red = 1;
00070                     blue = 1;
00071                     green = 0;
00072                 lcd.locate(0,15);
00073                 lcd.printf("Comfortable!!!");
00074                 }
00075                 wait(1.0);
00076                 if(fire == 1) {
00077                     lcd.cls();
00078                     ctrl = 0;
00079                     red = 1;
00080                     green = 1;
00081                     blue = 1;
00082                     break;
00083                 }
00084             }
00085             break;
00086         case 2:
00087             while(1) {
00088                 lcd.cls();
00089                 lcd.locate(0,3);
00090                 lcd.printf("Pot 1 = %.2f", (float)pot1);
00091                 lcd.locate(0,14);
00092                 lcd.printf("Pot 2 = %.2f", (float)pot2);
00093                 wait(0.1);
00094                 spkr.period((float)pot1/(float)pot2);
00095                 spkr=0.8;
00096                 wait(0.02);
00097                 if(fire == 1) {
00098                     ctrl = 0;
00099                     spkr = 0;
00100                     lcd.cls();
00101                     break;
00102                 }
00103             }
00104             break;
00105         }
00106     }
00107 }
00108 void menu(void)
00109 {
00110     lcd.locate(0,3);
00111     lcd.printf("welcome to mbed world!");
00112 }
00113 
00114 void start(void)
00115 {
00116     int j=5;
00117     while(1) {
00118         lcd.locate(0,3);
00119         lcd.printf("reboot system please wait");
00120         lcd.locate(0,15);
00121         lcd.printf("time : %d",j);
00122         j--;
00123         wait(1.0);
00124         if(j==0) {
00125             break;
00126         }
00127     }
00128     lcd.cls();
00129 }
00130