Microwave homework
Dependencies: C12832_lcd DebounceInterrupts LM75B mbed-rtos mbed
Revision 0:b3e2ffad2aab, committed 2014-03-16
- Comitter:
- bhakti08
- Date:
- Sun Mar 16 02:13:16 2014 +0000
- Commit message:
- Microwave homework-Partial
Changed in this revision
diff -r 000000000000 -r b3e2ffad2aab C12832_lcd.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/C12832_lcd.lib Sun Mar 16 02:13:16 2014 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/dreschpe/code/C12832_lcd/#468cdccff7af
diff -r 000000000000 -r b3e2ffad2aab DebounceInterrupts.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/DebounceInterrupts.lib Sun Mar 16 02:13:16 2014 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/bhakti08/code/DebounceInterrupts/#96a51b236ba0
diff -r 000000000000 -r b3e2ffad2aab DebouncedIn.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/DebouncedIn.cpp Sun Mar 16 02:13:16 2014 +0000 @@ -0,0 +1,93 @@ +#include "DebouncedIn.h" +#include "mbed.h" + +/* + * Constructor + */ +DebouncedIn::DebouncedIn(PinName in) + : _in(in) { + + // reset all the flags and counters + _samples = 0; + _output = 0; + _output_last = 0; + _rising_flag = 0; + _falling_flag = 0; + _state_counter = 0; + + // Attach ticker + _ticker.attach(this, &DebouncedIn::_sample, 0.005); +} + +void DebouncedIn::_sample() { + + // take a sample + _samples = _samples >> 1; // shift left + + if (_in) { + _samples |= 0x80; + } + + // examine the sample window, look for steady state + if (_samples == 0x00) { + _output = 0; + } + else if (_samples == 0xFF) { + _output = 1; + } + + + // Rising edge detection + if ((_output == 1) && (_output_last == 0)) { + _rising_flag++; + _state_counter = 0; + } + + // Falling edge detection + else if ((_output == 0) && (_output_last == 1)) { + _falling_flag++; + _state_counter = 0; + } + + // steady state + else { + _state_counter++; + } + + // update the output + _output_last = _output; + +} + + + +// return number of rising edges +int DebouncedIn::rising(void) { + int return_value = _rising_flag; + _rising_flag = 0; + return(return_value); +} + +// return number of falling edges +int DebouncedIn::falling(void) { + int return_value = _falling_flag; + _falling_flag = 0; + return(return_value); +} + +// return number of ticsk we've bene steady for +int DebouncedIn::steady(void) { +return(_state_counter); +} + +// return the debounced status +int DebouncedIn::read(void) { + return(_output); +} + +// shorthand for read() +DebouncedIn::operator int() { + return read(); +} + +
diff -r 000000000000 -r b3e2ffad2aab DebouncedIn.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/DebouncedIn.h Sun Mar 16 02:13:16 2014 +0000 @@ -0,0 +1,31 @@ +#include "mbed.h" + + class DebouncedIn { + public: + DebouncedIn(PinName in); + + int read (void); + operator int(); + + int rising(void); + int falling(void); + int steady(void); + + private : + // objects + DigitalIn _in; + Ticker _ticker; + + // function to take a sample, and update flags + void _sample(void); + + // counters and flags + int _samples; + int _output; + int _output_last; + int _rising_flag; + int _falling_flag; + int _state_counter; + + }; + \ No newline at end of file
diff -r 000000000000 -r b3e2ffad2aab LM75B.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LM75B.lib Sun Mar 16 02:13:16 2014 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/chris/code/LM75B/#6a70c9303bbe
diff -r 000000000000 -r b3e2ffad2aab main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Sun Mar 16 02:13:16 2014 +0000 @@ -0,0 +1,172 @@ +#include "mbed.h" +#include "LM75B.h" +#include "C12832_lcd.h" +#include "rtos.h" +#include "DebouncedIn.h" +#include "DebouncedInterrupt.h" +#include "Serial.h" + +//Serial pc(USBTX, USBRX); + +#define OPEN 1 +#define CLOSE 0 +#define ON 1 +#define OFF 0 +#define INTERRUPT + +DebouncedInterrupt increase_time(p13); +DebouncedInterrupt decrease_time(p16); +DebouncedInterrupt start (p12); +DebouncedInterrupt stop(p15); +DebouncedInterrupt door_status(p14); +DigitalOut door_signal(LED4); +//BusOut cook(LED4,LED3,LED2,LED1); + +LM75B in_temp(p28,p27); +C12832_LCD lcd; +DigitalOut cook_progress(LED1); +DigitalOut door_Signal(LED4); //This LED will be 1 if door is open +DigitalOut done_cooking(LED2); +PwmOut speaker(p26); +Timer ellapsed_cook_timer; + +int requested_cook_time = 120; +//float inside_temp; //Initial value of inside temp is room temperature +bool door_position = OPEN; //keep track if door is closed or open door_status = 0: close,1:open +bool cook_status = OFF; +bool speaker_signal; +float ellapsed_cook_time = 0; //Cooking should be stopped if door open + + +void open_door(); +void time_up(); +void time_down(); +void LED_blink (void const *args); +void sound_speaker (void const *args); +void start_cooking (); +void stop_cooking (); +void update_lcd(void const *args); +void check_ellapsed_cook_time (void const *args); + +Ticker LED_Blink_timer; + + +void open_door() +{ + door_position = !door_position; + { + if (door_position == OPEN) + { + door_Signal = 1; + } + else + { + door_Signal = 0; + } + } +} + +void time_up() +{ + + if (requested_cook_time < 180) + requested_cook_time = requested_cook_time + 60; + else + requested_cook_time = 180; +} + +void time_down() +{ + if (requested_cook_time > 0) + requested_cook_time = requested_cook_time - 60; + else + requested_cook_time = 0; +} + +void LED_blink () +{ + cook_progress= !cook_progress; +} + +void start_cooking () +{ + if (door_position == CLOSE) + { + speaker_signal = 1; + ellapsed_cook_timer.start(); + LED_Blink_timer.attach(&LED_blink,0.250); + } +} + +void stop_cooking () +{ + ellapsed_cook_timer.stop(); + cook_status = OFF; + LED_Blink_timer.detach(); + cook_progress = 0; + speaker_signal = 0; +} + +void start_speaker() +{ + speaker.period(1.0/5000); + while(door_position != OPEN && speaker_signal == 1){ + speaker = 0.5; + wait(0.1); + speaker = 0.0; + wait(0.1); + } + speaker_signal = 0; +} + +void update_lcd(void const *args) +{ + lcd.cls(); + while(true) + { + lcd.locate(0,0); + lcd.printf("Ellapsed time is %0.2f",ellapsed_cook_timer.read()/60); + lcd.locate(0,10); + lcd.printf("Set time is %d",requested_cook_time/60); + Thread::wait (1000); + } +} + + +void check_ellapsed_cook_time (void const *args) +{ + while (true) + { + if (ellapsed_cook_timer.read()/60 >= requested_cook_time/60 )//&& cook_status != OFF) + { + ellapsed_cook_timer.stop(); + ellapsed_cook_timer.reset(); + cook_status = OFF; + LED_Blink_timer.detach(); + start_speaker(); + } + Thread::wait(10); + } +} + + +int main() +{ + //printf("\nIn main"); + Thread lcd_display(update_lcd,NULL, osPriorityAboveNormal); + Thread track_ellapsed_cook_time(check_ellapsed_cook_time,NULL,osPriorityHigh); + increase_time.attach(&time_up); + decrease_time.attach(&time_down); + start.attach(&start_cooking); + stop.attach(&stop_cooking); + door_status.attach(&open_door); + door_Signal = door_position; + + + while (true) + { + if(door_Signal == OPEN )//|| stop == 1) + stop_cooking(); + Thread::wait(400); + } +} \ No newline at end of file
diff -r 000000000000 -r b3e2ffad2aab mbed-rtos.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed-rtos.lib Sun Mar 16 02:13:16 2014 +0000 @@ -0,0 +1,1 @@ +https://mbed.org/users/mbed_official/code/mbed-rtos/#f88660a9bed1
diff -r 000000000000 -r b3e2ffad2aab mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Sun Mar 16 02:13:16 2014 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/8e73be2a2ac1 \ No newline at end of file