Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: 4DGL-uLCD-SE PinDetect SDFileSystem mbed
Fork of mymbedthermostat by
main.cpp
00001 // skeleton code for ECE 2036 thermostat lab 00002 // code must be added by students 00003 #include "mbed.h" 00004 #include "TMP36.h" 00005 #include "SDFileSystem.h" 00006 #include "uLCD_4DGL.h" 00007 #include "PinDetect.h" 00008 #include "Speaker.h" 00009 // must add your new class code to the project file Shiftbrite.h 00010 #include "Shiftbrite.h" 00011 00012 // use class to setup temperature sensor pins 00013 TMP36 myTMP36(p15); //Analog in 00014 00015 // use class to setup microSD card filesystem 00016 SDFileSystem sd(p5, p6, p7, p8, "sd"); 00017 00018 // use class to setup the Color LCD 00019 uLCD_4DGL uLCD(p28, p27, p29); // create a global uLCD object 00020 00021 // use class to setup pushbuttons pins 00022 PinDetect pb1(p23); 00023 PinDetect pb2(p24); 00024 PinDetect pb3(p25); 00025 00026 // use class to setup speaker pin 00027 Speaker mySpeaker(p21); //PWM out 00028 00029 // use class to setup Shiftbrite pins 00030 Shiftbrite myShiftbrite(p9, p10, p11, p12, p13);// ei li di n/c ci 00031 00032 // use class to setup Mbed's four on-board LEDs 00033 DigitalOut myLED1(LED1); 00034 DigitalOut myLED2(LED2); 00035 DigitalOut myLED3(LED3); 00036 DigitalOut myLED4(LED4); 00037 00038 00039 00040 //also setting any unused analog input pins to digital outputs reduces A/D noise a bit 00041 //see http://mbed.org/users/chris/notebook/Getting-best-ADC-performance/ 00042 DigitalOut P16(p16); 00043 DigitalOut P17(p17); 00044 DigitalOut P18(p18); 00045 DigitalOut P19(p19); 00046 DigitalOut P20(p20); 00047 00048 00049 00050 00051 // Global variables used in callbacks and main program 00052 // C variables in interrupt routines should use volatile keyword 00053 int volatile heat_setting=78; // heat to temp 00054 int volatile cool_setting=68; // cool to temp 00055 bool volatile mode=false; // heat or cool mode 00056 00057 // Callback routine is interrupt activated by a debounced pb1 hit 00058 void pb1_hit_callback (void) 00059 { 00060 // ADD CODE HERE 00061 } 00062 // Callback routine is interrupt activated by a debounced pb2 hit 00063 void pb2_hit_callback (void) 00064 { 00065 // ADD CODE HERE 00066 } 00067 // Callback routine is interrupt activated by a debounced pb3 hit 00068 void pb3_hit_callback (void) 00069 { 00070 // ADD CODE HERE 00071 } 00072 00073 00074 int main() 00075 { 00076 float Current_temp=0.0; 00077 00078 // Use internal pullups for the three pushbuttons 00079 pb1.mode(PullUp); 00080 pb2.mode(PullUp); 00081 pb3.mode(PullUp); 00082 // Delay for initial pullup to take effect 00083 wait(.01); 00084 // Setup Interrupt callback functions for a pb hit 00085 pb1.attach_deasserted(&pb1_hit_callback); 00086 pb2.attach_deasserted(&pb2_hit_callback); 00087 pb3.attach_deasserted(&pb3_hit_callback); 00088 // Start sampling pb inputs using interrupts 00089 pb1.setSampleFrequency(); 00090 pb2.setSampleFrequency(); 00091 pb3.setSampleFrequency(); 00092 // pushbuttons now setup and running 00093 00094 00095 // start I/O examples - DELETE THIS IN YOUR CODE..BUT WILL USE THESE I/O IDEAS ELSEWHERE 00096 // since all this compiles - the needed *.h files for these are in the project 00097 // 00098 Current_temp = myTMP36; //Read temp sensor 00099 printf("Hello PC World\n\r"); // need terminal application running on PC to see this output 00100 uLCD.printf("\n\rHello LCD World\n\r"); // LCD 00101 mySpeaker.PlayNote(500.0, 1.0, 1.0); // Speaker buzz 00102 myShiftbrite.write( 0, 50 ,0); // Green RGB LED 00103 // SD card write file example - prints error message on PC when running until SD card hooked up 00104 // Delete to avoid run time error 00105 mkdir("/sd/mydir", 0777); // set up directory and permissions 00106 FILE *fp = fopen("/sd/mydir/sdtest.txt", "w"); //open SD 00107 if(fp == NULL) { 00108 error("Could not open file for write\n"); 00109 } 00110 fprintf(fp, "Hello SD Card World!"); // write SD 00111 fclose(fp); // close SD card 00112 // 00113 // end I/O examples 00114 00115 00116 00117 00118 // State machine code below will need changes and additions 00119 while (1) { 00120 { 00121 enum Statetype { Heat_off = 0, Heat_on }; 00122 Statetype state = Heat_off; 00123 while(1) { 00124 switch (state) { 00125 case Heat_off: 00126 myLED4 = 0; 00127 state = Heat_on; 00128 break; 00129 case Heat_on: 00130 myLED4 = 1; 00131 state = Heat_off; 00132 break; 00133 } 00134 wait(0.33); 00135 // heartbeat LED - common debug tool 00136 // blinks as long as code is running and not locked up 00137 myLED1=!myLED1; 00138 } 00139 } 00140 } 00141 }
Generated on Wed Jul 13 2022 06:10:48 by
1.7.2
