RTOS project

Dependencies:   C12832_lcd EthernetInterface LM75B NTPClient SimpleSMTPClient TextLCD beep mbed-rtos mbed

Fork of RTOS_Project by Akram khan

Description:

RTOS project : Connected and automated manufacturing plant model. The Goal of this project is to use most of the IO on the mbed application board in a RTOS project. This simulates a manufacturing plant where temperature, potentiometer, lever control are performed and depending on the input and stored values alerts are issues on COM port, buzzer and LEDS. The LCD display and Ethernet control is used to display and collect logs.

Motivation

Internet of Things (IoT) is the network of physical objects accessed through the Internet, as defined by technology analysts and visionaries. These objects contain embedded technology to interact with internal states or the external environment. In other words, when objects can sense and communicate, it changes how and where decisions are made, and who makes them

Background and Goals

MBED application board used to simulate the real world scenario of a manufacturing plant. Goal is to use most of the existing Input/output ports on the application board in project. Learn to program in C and build on this project for future embedded projects.

System overview

/media/uploads/Akramkhan78/factory.png

Features

Inputs

  • Lever control monitor
  • Temperature monitor
  • Potentiometer monitor
    • Outputs
  • Factory status on LCD
  • Emergency alerts on LEDs
  • Audio alerts on Buzzer
    • Control and logging
  • Serial port used to display logs
  • Ethernet port used to send logs and receive alerts.
    • Main Manufacturing plant controller

Software architecture

Libraries

#include "mbed.h"
#include "rtos.h"
#include "C12832_lcd.h"
#include "beep.h"  
#include "LM75B.h"
#include "EthernetInterface.h"
#include "NTPClient.h"
#include "SimpleSMTPClient.h"

Inputs/Outputs

DigitalOut   buzzer(p26) ;                            // Buzzer to alert the cooking stopped.
    LM75B       temperature(p28,p27);                // Temperature sensor
    C12832_LCD  lcd;                                 // LCD object from library.
    DigitalOut  led3(LED3);                          //  LED to display  cooking in progress
    DigitalOut  led2(LED2);                          //  LED to display  carousel turning
    AnalogIn pot1(p20);                              // Analog Potentiometer 1
    AnalogIn pot2(p19);                              // Analog Potentiometer 1
    Serial      pc(USBTX, USBRX);               // PuTTY terminal communication.

Interrupts used

    InterruptIn  InterJoyStickUp    (p15);          // joystick beat up pressed that will make controller stop
    InterruptIn  InterJoyStickDown  (p12);          // joystick beat up pressed that will make controller start
    InterruptIn  InterJoyStickLeft  (p13);          // joystick beat up pressed that will make clock time up.
    InterruptIn  InterJoyStickRight (p16);          // joystick beat up pressed that will make clock time down.
    InterruptIn  InterJoyStickCenter(p14);          //joystick beat up pressed that will make open close the door.
    InterruptIn  Interpotmeter1(p20);               // Potentiometer 1. 
    InterruptIn  Interpotmeter2(p19);               // Potentiometer 2.

ISR used

   void lcd_display();                         // Display on LCD.
    void int_ser_controller();                   // Ticker for MV.                
    void up_isr();                         // Stop the MV.
    void down_isr();                       // Start the MV.
    void right_rising_isr();               // Lower the clock.
    void left_rising_isr();                // Raise the clock.
    void default_isr();                    // reset
    void off_controller();                  // turn off blinker.
    void pot1_isr();                        // Potentiometer 1. 
    void pot2_isr();                        // Potentiometer 2.

Ticker used

    Ticker      tickercontroller;                // blinking LED.
    Ticker      tickerLCD;                      // display ticker.
    Timeout     timeoutDutyCycle;               // LED duty cycle delay.
    Timeout     timeoutcontroller;

Test cases

The main controller monitors various IO for changes and depending on the pre set values will send alerts to LEDs, LCD and Ethernet devices. Example: The Level 1 (potentiometer 1 ) is out of range. LED 2 is turned ON and the alert is send via ethernet and also displayed on LCD.

Committer:
Akramkhan78
Date:
Thu Sep 19 23:38:56 2013 +0000
Revision:
1:fbedd4d685c0
Parent:
0:89c1a68c483b
clean up

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Akramkhan78 0:89c1a68c483b 1 /*
Akramkhan78 0:89c1a68c483b 2 Author : Akram khan
Akramkhan78 0:89c1a68c483b 3 RTOS: : project
Akramkhan78 0:89c1a68c483b 4 file : main.cpp
Akramkhan78 0:89c1a68c483b 5 library inculded :mbed.h, C12832_lcd.h, mbed-rtos.h
Akramkhan78 1:fbedd4d685c0 6 Description: RTOS project connected and automated manufacturing plant.
Akramkhan78 1:fbedd4d685c0 7 The Goal of this project is to use most of the IO on the mbed application board in a RTOS project.
Akramkhan78 1:fbedd4d685c0 8
Akramkhan78 1:fbedd4d685c0 9 This simulates a manufacturing plant where temperature, speed, potentiometer,
Akramkhan78 1:fbedd4d685c0 10 lever control are performed and depending on the input and stored
Akramkhan78 1:fbedd4d685c0 11 values alerts are issues on COM port, buzzer and LEDS.
Akramkhan78 1:fbedd4d685c0 12 The LCD display and Ethernet control is used to display and collect logs.
Akramkhan78 1:fbedd4d685c0 13
Akramkhan78 0:89c1a68c483b 14 */
Akramkhan78 0:89c1a68c483b 15 #include "mbed.h"
Akramkhan78 0:89c1a68c483b 16 #include "rtos.h"
Akramkhan78 0:89c1a68c483b 17 #include "C12832_lcd.h"
Akramkhan78 0:89c1a68c483b 18 #include "beep.h"
Akramkhan78 0:89c1a68c483b 19 #include "LM75B.h"
Akramkhan78 0:89c1a68c483b 20 #include "EthernetInterface.h"
Akramkhan78 0:89c1a68c483b 21 #include "NTPClient.h"
Akramkhan78 0:89c1a68c483b 22 #include "SimpleSMTPClient.h"
Akramkhan78 1:fbedd4d685c0 23
Akramkhan78 0:89c1a68c483b 24 //----------------------------------------------------------------------------
Akramkhan78 0:89c1a68c483b 25 #define LCD1 lcd.locate(0, 0); // LCD line 1.
Akramkhan78 0:89c1a68c483b 26 #define LCD2 lcd.locate(0,11); // LCD line 2.
Akramkhan78 0:89c1a68c483b 27 #define LCD3 lcd.locate(0,22); // LCD line 3.
Akramkhan78 0:89c1a68c483b 28 //----------------------------------------------------------------------------
Akramkhan78 0:89c1a68c483b 29
Akramkhan78 0:89c1a68c483b 30 #define MetroDuration 60.0 // controller duration for on-time in seconds.
Akramkhan78 0:89c1a68c483b 31 #define LCD_refresh 0.1 // how often to redraw the LCD.
Akramkhan78 0:89c1a68c483b 32 #define Delay 1 // how long the LED-on-time is.
Akramkhan78 0:89c1a68c483b 33
Akramkhan78 0:89c1a68c483b 34
Akramkhan78 0:89c1a68c483b 35
Akramkhan78 0:89c1a68c483b 36
Akramkhan78 0:89c1a68c483b 37 #define DOMAIN "comcast.net"
Akramkhan78 0:89c1a68c483b 38 #define SERVER "smtp.comcast.net"
Akramkhan78 0:89c1a68c483b 39 #define PORT "587" //25 or 587,465(OutBound Port25 Blocking )
Akramkhan78 0:89c1a68c483b 40 #define USER "rtos_test"
Akramkhan78 0:89c1a68c483b 41 #define PWD "test"
Akramkhan78 0:89c1a68c483b 42 #define FROM_ADDRESS "rtos_test@comcast.net"
Akramkhan78 0:89c1a68c483b 43 // TO_ADDRESS (Of some address is possible.)
Akramkhan78 0:89c1a68c483b 44 // to-user1@domain, to-user2@domain, to-user3@domain ....
Akramkhan78 0:89c1a68c483b 45 // The TO_ADDRESS are less than 128 characters.
Akramkhan78 0:89c1a68c483b 46 #define TO_ADDRESS "rtos_test@comcast.net"
Akramkhan78 0:89c1a68c483b 47
Akramkhan78 0:89c1a68c483b 48 #define SUBJECT "Test Mail"
Akramkhan78 0:89c1a68c483b 49
Akramkhan78 0:89c1a68c483b 50
Akramkhan78 0:89c1a68c483b 51
Akramkhan78 0:89c1a68c483b 52 //----------------------------------------------------------------------------
Akramkhan78 0:89c1a68c483b 53 // TextLCD lcd(p24, p26, p27, p28, p29, p30);
Akramkhan78 0:89c1a68c483b 54 DigitalOut buzzer(p26) ; // Buzzer to alert the cooking stopped.
Akramkhan78 0:89c1a68c483b 55 LM75B temperature(p28,p27); // Temperature sensor
Akramkhan78 0:89c1a68c483b 56 C12832_LCD lcd; // LCD object from library.
Akramkhan78 0:89c1a68c483b 57 DigitalOut led3(LED3); // LED to display cooking in progress
Akramkhan78 0:89c1a68c483b 58 DigitalOut led2(LED2); // LED to display carousel turning
Akramkhan78 0:89c1a68c483b 59 AnalogIn pot1(p20); // Analog Potentiometer 1
Akramkhan78 0:89c1a68c483b 60 AnalogIn pot2(p19); // Analog Potentiometer 1
Akramkhan78 0:89c1a68c483b 61 Serial pc(USBTX, USBRX); // PuTTY terminal communication.
Akramkhan78 0:89c1a68c483b 62 //---------------- Interrupts------------------------------------------------------------
Akramkhan78 0:89c1a68c483b 63 InterruptIn InterJoyStickUp (p15); // joystick beat up pressed that will make controller stop
Akramkhan78 0:89c1a68c483b 64 InterruptIn InterJoyStickDown (p12); // joystick beat up pressed that will make controller start
Akramkhan78 0:89c1a68c483b 65 InterruptIn InterJoyStickLeft (p13); // joystick beat up pressed that will make clock time up.
Akramkhan78 0:89c1a68c483b 66 InterruptIn InterJoyStickRight (p16); // joystick beat up pressed that will make clock time down.
Akramkhan78 0:89c1a68c483b 67 InterruptIn InterJoyStickCenter(p14); //joystick beat up pressed that will make open close the door.
Akramkhan78 0:89c1a68c483b 68 InterruptIn Interpotmeter1(p20); // Potentiometer 1.
Akramkhan78 0:89c1a68c483b 69 InterruptIn Interpotmeter2(p19); // Potentiometer 2.
Akramkhan78 0:89c1a68c483b 70
Akramkhan78 0:89c1a68c483b 71 //----------------------------------------------------------------------------
Akramkhan78 0:89c1a68c483b 72
Akramkhan78 0:89c1a68c483b 73 Ticker tickercontroller; // blinking LED.
Akramkhan78 0:89c1a68c483b 74 Ticker tickerLCD; // display ticker.
Akramkhan78 0:89c1a68c483b 75 Timeout timeoutDutyCycle; // LED duty cycle delay.
Akramkhan78 0:89c1a68c483b 76 Timeout timeoutcontroller;
Akramkhan78 0:89c1a68c483b 77 //----------------------------------------------------------------------------
Akramkhan78 0:89c1a68c483b 78 void lcd_display(); // Display on LCD.
Akramkhan78 0:89c1a68c483b 79 void int_ser_controller(); // Ticker for MV.
Akramkhan78 0:89c1a68c483b 80 void up_isr(); // Stop the MV.
Akramkhan78 0:89c1a68c483b 81 void down_isr(); // Start the MV.
Akramkhan78 0:89c1a68c483b 82 void right_rising_isr(); // Lower the clock.
Akramkhan78 0:89c1a68c483b 83 void left_rising_isr(); // Raise the clock.
Akramkhan78 0:89c1a68c483b 84 void default_isr(); // reset
Akramkhan78 0:89c1a68c483b 85 void off_controller(); // turn off blinker.
Akramkhan78 0:89c1a68c483b 86 void pot1_isr(); // Potentiometer 1.
Akramkhan78 0:89c1a68c483b 87 void pot2_isr(); // Potentiometer 2.
Akramkhan78 0:89c1a68c483b 88 //----------------------------------------------------------------------------
Akramkhan78 0:89c1a68c483b 89 float potmeter1 ; // intial Potentiometer 1
Akramkhan78 0:89c1a68c483b 90 float potmeter2 ; // intial Potentiometer 2
Akramkhan78 0:89c1a68c483b 91 float temp ; // intial temperature of controller
Akramkhan78 0:89c1a68c483b 92 char controller_is_ON; // to check if LED should blink.
Akramkhan78 0:89c1a68c483b 93 //--------------------Start of Main--------------------------------------------------------
Akramkhan78 0:89c1a68c483b 94 int main(void)
Akramkhan78 0:89c1a68c483b 95 {
Akramkhan78 0:89c1a68c483b 96 temp = temperature.read(); // read the temperature.
Akramkhan78 0:89c1a68c483b 97 potmeter1= pot1.read() ; // read the Potentiometer 1
Akramkhan78 0:89c1a68c483b 98 potmeter2= pot2.read() ; // read the Potentiometer 2
Akramkhan78 0:89c1a68c483b 99
Akramkhan78 0:89c1a68c483b 100 //----------------------------------------------------------------------------
Akramkhan78 0:89c1a68c483b 101 Interpotmeter1.rise (&pot1_isr); // Change the potentiometer 1 control.
Akramkhan78 0:89c1a68c483b 102 Interpotmeter2.rise (&pot2_isr); // Change the potentiometer 2 control.
Akramkhan78 0:89c1a68c483b 103 InterJoyStickDown.rise (&down_isr); // Start the controller.
Akramkhan78 0:89c1a68c483b 104 InterJoyStickUp.rise (&up_isr); // Stop the controller.
Akramkhan78 0:89c1a68c483b 105 InterJoyStickRight.rise(&right_rising_isr); // Lower the clock time.
Akramkhan78 0:89c1a68c483b 106 InterJoyStickLeft.rise (&left_rising_isr); // Raise the clock time .
Akramkhan78 0:89c1a68c483b 107 InterJoyStickCenter.rise(&default_isr); // Reset the controller to deafult value .
Akramkhan78 0:89c1a68c483b 108 //----------------------------------------------------------------------------
Akramkhan78 0:89c1a68c483b 109 tickercontroller.attach(&int_ser_controller,Delay); //Ticker for Interuppt for the service
Akramkhan78 0:89c1a68c483b 110 tickerLCD.attach(&lcd_display,LCD_refresh); // Ticker for display on LCD.
Akramkhan78 0:89c1a68c483b 111 //----------------------------------------------------------------------------
Akramkhan78 0:89c1a68c483b 112 /*while(1)
Akramkhan78 0:89c1a68c483b 113 {
Akramkhan78 0:89c1a68c483b 114 wait(20.0);
Akramkhan78 0:89c1a68c483b 115 } */
Akramkhan78 0:89c1a68c483b 116 EthernetInterface eth;
Akramkhan78 0:89c1a68c483b 117 char strTimeMsg[16];
Akramkhan78 0:89c1a68c483b 118 lcd.cls();
Akramkhan78 0:89c1a68c483b 119 printf("\n\n/* SimpleMTPClient library demonstration */\n");
Akramkhan78 0:89c1a68c483b 120
Akramkhan78 0:89c1a68c483b 121 printf("Setting up ...\n");
Akramkhan78 0:89c1a68c483b 122 eth.init();
Akramkhan78 0:89c1a68c483b 123 eth.connect();
Akramkhan78 0:89c1a68c483b 124 printf("Connected OK\n");
Akramkhan78 0:89c1a68c483b 125
Akramkhan78 0:89c1a68c483b 126 // IP Address
Akramkhan78 0:89c1a68c483b 127 printf("IP Address is %s\n", eth.getIPAddress());
Akramkhan78 0:89c1a68c483b 128 lcd.locate(0,1);
Akramkhan78 0:89c1a68c483b 129 lcd.printf("%s", eth.getIPAddress());
Akramkhan78 0:89c1a68c483b 130
Akramkhan78 0:89c1a68c483b 131 // NTP Client
Akramkhan78 0:89c1a68c483b 132 printf("NTP setTime...\n");
Akramkhan78 0:89c1a68c483b 133 NTPClient ntp;
Akramkhan78 0:89c1a68c483b 134 ntp.setTime("pool.ntp.org");
Akramkhan78 0:89c1a68c483b 135
Akramkhan78 0:89c1a68c483b 136 time_t ctTime = time(NULL)+32400; // JST
Akramkhan78 0:89c1a68c483b 137 printf("\nTime is now (JST): %d %s\n", ctTime, ctime(&ctTime));
Akramkhan78 0:89c1a68c483b 138 strftime(strTimeMsg,16,"%y/%m/%d %H:%M",localtime(&ctTime));
Akramkhan78 0:89c1a68c483b 139
Akramkhan78 0:89c1a68c483b 140 lcd.locate(0,0);
Akramkhan78 0:89c1a68c483b 141 lcd.printf("[%s]",strTimeMsg);
Akramkhan78 0:89c1a68c483b 142
Akramkhan78 0:89c1a68c483b 143
Akramkhan78 0:89c1a68c483b 144 SimpleSMTPClient smtp;
Akramkhan78 0:89c1a68c483b 145 int ret;
Akramkhan78 0:89c1a68c483b 146 char msg[]="Hello SimpleSMTPClient ";
Akramkhan78 0:89c1a68c483b 147
Akramkhan78 0:89c1a68c483b 148 smtp.setFromAddress(FROM_ADDRESS);
Akramkhan78 0:89c1a68c483b 149 smtp.setToAddress(TO_ADDRESS);
Akramkhan78 0:89c1a68c483b 150 smtp.setMessage(SUBJECT,msg);
Akramkhan78 0:89c1a68c483b 151 smtp.addMessage("TEST TEST TEST\r\n");
Akramkhan78 0:89c1a68c483b 152
Akramkhan78 0:89c1a68c483b 153 ret = smtp.sendmail(SERVER, USER, PWD, DOMAIN,PORT,SMTP_AUTH_PLAIN);
Akramkhan78 0:89c1a68c483b 154
Akramkhan78 0:89c1a68c483b 155 if (ret) {
Akramkhan78 0:89c1a68c483b 156 printf("E-mail Transmission Error\r\n");
Akramkhan78 0:89c1a68c483b 157 } else {
Akramkhan78 0:89c1a68c483b 158 printf("E-mail Transmission OK\r\n");
Akramkhan78 0:89c1a68c483b 159 }
Akramkhan78 0:89c1a68c483b 160
Akramkhan78 0:89c1a68c483b 161 //
Akramkhan78 0:89c1a68c483b 162 // send as SMS text
Akramkhan78 0:89c1a68c483b 163 //
Akramkhan78 0:89c1a68c483b 164
Akramkhan78 0:89c1a68c483b 165 smtp.setFromAddress(FROM_ADDRESS);
Akramkhan78 0:89c1a68c483b 166 smtp.setToAddress("5105794214@txt.att.net"); // MODIFY for carrier
Akramkhan78 0:89c1a68c483b 167 smtp.setMessage(SUBJECT,msg);
Akramkhan78 0:89c1a68c483b 168 smtp.addMessage("TEST TEST TEST\r\n");
Akramkhan78 0:89c1a68c483b 169
Akramkhan78 0:89c1a68c483b 170 ret = smtp.sendmail(SERVER, USER, PWD, DOMAIN,PORT,SMTP_AUTH_PLAIN);
Akramkhan78 0:89c1a68c483b 171
Akramkhan78 0:89c1a68c483b 172 if (ret) {
Akramkhan78 0:89c1a68c483b 173 printf("SMS Transmission Error\r\n");
Akramkhan78 0:89c1a68c483b 174 } else {
Akramkhan78 0:89c1a68c483b 175 printf("SMS Transmission OK\r\n");
Akramkhan78 0:89c1a68c483b 176 }
Akramkhan78 0:89c1a68c483b 177
Akramkhan78 0:89c1a68c483b 178 return 0;
Akramkhan78 0:89c1a68c483b 179 }
Akramkhan78 0:89c1a68c483b 180
Akramkhan78 0:89c1a68c483b 181 //------------End of main ----------------------------------------------------------------
Akramkhan78 0:89c1a68c483b 182
Akramkhan78 0:89c1a68c483b 183 //------------------ Start of ISRs----------------------------------------------------------
Akramkhan78 0:89c1a68c483b 184 void pot1_isr(void) // Change the potentiometer 1 control
Akramkhan78 0:89c1a68c483b 185 {
Akramkhan78 0:89c1a68c483b 186 controller_is_ON = 0;
Akramkhan78 0:89c1a68c483b 187 }
Akramkhan78 0:89c1a68c483b 188 //----------------------------------------------------------------------------
Akramkhan78 0:89c1a68c483b 189 void pot2_isr(void) // Change the potentiometer 2 control
Akramkhan78 0:89c1a68c483b 190 {
Akramkhan78 0:89c1a68c483b 191 controller_is_ON = 0;
Akramkhan78 0:89c1a68c483b 192 }
Akramkhan78 0:89c1a68c483b 193 //----------------------------------------------------------------------------
Akramkhan78 0:89c1a68c483b 194 void down_isr(void) // Turn on the controller with timeout of 3 mintues.
Akramkhan78 0:89c1a68c483b 195 {
Akramkhan78 0:89c1a68c483b 196 controller_is_ON = 1;
Akramkhan78 0:89c1a68c483b 197 timeoutcontroller.detach();
Akramkhan78 0:89c1a68c483b 198 timeoutcontroller.attach(&off_controller,MetroDuration);
Akramkhan78 0:89c1a68c483b 199 }
Akramkhan78 0:89c1a68c483b 200 //----------------------------------------------//----------------------------
Akramkhan78 0:89c1a68c483b 201
Akramkhan78 0:89c1a68c483b 202 void up_isr(void) // Up presssed tun off the controller.
Akramkhan78 0:89c1a68c483b 203 {
Akramkhan78 0:89c1a68c483b 204 controller_is_ON = 0;
Akramkhan78 0:89c1a68c483b 205 }
Akramkhan78 0:89c1a68c483b 206 //----------------------------------------------//----------------------------
Akramkhan78 0:89c1a68c483b 207
Akramkhan78 0:89c1a68c483b 208 void left_rising_isr(void) // Left button pressed, increase the clock time .
Akramkhan78 0:89c1a68c483b 209 {
Akramkhan78 0:89c1a68c483b 210 __disable_irq();
Akramkhan78 0:89c1a68c483b 211
Akramkhan78 0:89c1a68c483b 212 temp = temp + 0.10;
Akramkhan78 0:89c1a68c483b 213
Akramkhan78 0:89c1a68c483b 214
Akramkhan78 0:89c1a68c483b 215 __enable_irq();
Akramkhan78 0:89c1a68c483b 216 }
Akramkhan78 0:89c1a68c483b 217
Akramkhan78 0:89c1a68c483b 218
Akramkhan78 0:89c1a68c483b 219
Akramkhan78 0:89c1a68c483b 220
Akramkhan78 0:89c1a68c483b 221 void right_rising_isr(void) // Right button pressed, decrease the clock time .
Akramkhan78 0:89c1a68c483b 222 {
Akramkhan78 0:89c1a68c483b 223 __disable_irq();
Akramkhan78 0:89c1a68c483b 224
Akramkhan78 0:89c1a68c483b 225 temp = temp - 0.10; // decrease BPM.
Akramkhan78 0:89c1a68c483b 226
Akramkhan78 0:89c1a68c483b 227 __enable_irq(); // safe by now.
Akramkhan78 0:89c1a68c483b 228
Akramkhan78 0:89c1a68c483b 229 }
Akramkhan78 0:89c1a68c483b 230
Akramkhan78 0:89c1a68c483b 231
Akramkhan78 0:89c1a68c483b 232
Akramkhan78 0:89c1a68c483b 233
Akramkhan78 0:89c1a68c483b 234 void default_isr(void) // Center button pressed and set to pause the MV.
Akramkhan78 0:89c1a68c483b 235 {
Akramkhan78 0:89c1a68c483b 236
Akramkhan78 0:89c1a68c483b 237 tickercontroller.detach();
Akramkhan78 0:89c1a68c483b 238 timeoutcontroller.attach(&off_controller,MetroDuration);
Akramkhan78 0:89c1a68c483b 239 }
Akramkhan78 0:89c1a68c483b 240 //----------------------------------------------//----------------------------//
Akramkhan78 0:89c1a68c483b 241 void lcd_display(void) // Display the state of controller and temperature.
Akramkhan78 0:89c1a68c483b 242 {
Akramkhan78 0:89c1a68c483b 243 lcd.cls(); // clear LCD display.
Akramkhan78 0:89c1a68c483b 244
Akramkhan78 0:89c1a68c483b 245 LCD1; // line 1.
Akramkhan78 0:89c1a68c483b 246 if ( controller_is_ON ){
Akramkhan78 0:89c1a68c483b 247
Akramkhan78 0:89c1a68c483b 248 LCD1;
Akramkhan78 0:89c1a68c483b 249 lcd.printf(" controller RUNNING");
Akramkhan78 0:89c1a68c483b 250 LCD2; // line 2.
Akramkhan78 0:89c1a68c483b 251 lcd.printf(" temp =%i\r\r",temp);
Akramkhan78 0:89c1a68c483b 252 led2 = 0;
Akramkhan78 0:89c1a68c483b 253 buzzer = 1; } // buzzer to indicate cooking done
Akramkhan78 0:89c1a68c483b 254 else {
Akramkhan78 0:89c1a68c483b 255 led2 = 1;
Akramkhan78 0:89c1a68c483b 256 LCD1;
Akramkhan78 0:89c1a68c483b 257 lcd.printf(" controller STOPPED");
Akramkhan78 0:89c1a68c483b 258 LCD2; // line 2.
Akramkhan78 0:89c1a68c483b 259 lcd.printf(" temp =%i\r\r",temp);
Akramkhan78 0:89c1a68c483b 260 buzzer = 0; // turn off the buzzer to indicate the cooking done.
Akramkhan78 0:89c1a68c483b 261 }
Akramkhan78 0:89c1a68c483b 262
Akramkhan78 0:89c1a68c483b 263 }
Akramkhan78 0:89c1a68c483b 264 //----------------------------------------------//----------------------------
Akramkhan78 0:89c1a68c483b 265 void int_ser_controller() // Ticker for controller.
Akramkhan78 0:89c1a68c483b 266 {
Akramkhan78 0:89c1a68c483b 267 if (controller_is_ON)
Akramkhan78 0:89c1a68c483b 268 {
Akramkhan78 0:89c1a68c483b 269 tickercontroller.detach();
Akramkhan78 0:89c1a68c483b 270 tickercontroller.attach(&int_ser_controller,Delay);
Akramkhan78 0:89c1a68c483b 271 led3 = 1;
Akramkhan78 0:89c1a68c483b 272 } else
Akramkhan78 0:89c1a68c483b 273 led3 = 0;
Akramkhan78 0:89c1a68c483b 274 }
Akramkhan78 0:89c1a68c483b 275 //----------------------------------------------//----------------------------
Akramkhan78 0:89c1a68c483b 276 void off_controller(void) // Stop the controller.
Akramkhan78 0:89c1a68c483b 277 {
Akramkhan78 0:89c1a68c483b 278 controller_is_ON=0;
Akramkhan78 0:89c1a68c483b 279
Akramkhan78 0:89c1a68c483b 280
Akramkhan78 0:89c1a68c483b 281 }
Akramkhan78 0:89c1a68c483b 282
Akramkhan78 0:89c1a68c483b 283
Akramkhan78 0:89c1a68c483b 284 /* Test cases
Akramkhan78 0:89c1a68c483b 285 Move the Joystick down and notice the controller will start
Akramkhan78 0:89c1a68c483b 286 Move the Joystick up and notice the controller will stop
Akramkhan78 0:89c1a68c483b 287 Move the Joystick left and notice the controller clock will increaase and the LCD display wil show the display.
Akramkhan78 0:89c1a68c483b 288 Move the joystick right and notice the controller clock will decrease and the LCD display will show the display.
Akramkhan78 0:89c1a68c483b 289 When the maximun time of the clock is reached the clock will set to default.
Akramkhan78 0:89c1a68c483b 290 The LCD will also show the temperature of the controller and will be increamented based on the joystick
Akramkhan78 0:89c1a68c483b 291 The joystick can be pressed in center position to open the door and pause the cooking.
Akramkhan78 0:89c1a68c483b 292 The LED will also show running and stopped as status of the controller.
Akramkhan78 0:89c1a68c483b 293 LED2 will show the status of the door.
Akramkhan78 0:89c1a68c483b 294 */