report

Dependencies:   C12832 LM75B mbed

Fork of app-shield-LM75B by Chris Styles

Committer:
jw574
Date:
Wed Jan 11 06:17:06 2017 +0000
Revision:
10:091f48cc6eaf
Parent:
8:e0f3f151c3cc
Report

Who changed what in which revision?

UserRevisionLine numberNew contents of line
okano 0:ce7a8546502b 1 #include "mbed.h"
chris 2:9e757151de9b 2 #include "LM75B.h"
chris 5:608f2bf4d3f7 3 #include "C12832.h"
okano 0:ce7a8546502b 4
jw574 10:091f48cc6eaf 5 DigitalOut red (LED_RED);
jw574 10:091f48cc6eaf 6 DigitalOut green(LED_GREEN);
jw574 10:091f48cc6eaf 7 DigitalOut blue(LED_BLUE);
jw574 10:091f48cc6eaf 8 DigitalIn up(A2);
jw574 10:091f48cc6eaf 9 DigitalIn down(A3);
jw574 10:091f48cc6eaf 10 DigitalIn left(A4);
jw574 10:091f48cc6eaf 11 DigitalIn right(A5);
jw574 10:091f48cc6eaf 12 DigitalIn fire(D4);
jw574 10:091f48cc6eaf 13 AnalogIn pot1 (A0);
jw574 10:091f48cc6eaf 14 AnalogIn pot2 (A1);
chris 6:bb84f3ab523d 15 C12832 lcd(D11, D13, D12, D7, D10);
chris 8:e0f3f151c3cc 16 LM75B sensor(D14,D15);
jw574 10:091f48cc6eaf 17 PwmOut spkr(D6);
jw574 10:091f48cc6eaf 18 void start(void);
jw574 10:091f48cc6eaf 19 void menu(void);
jw574 10:091f48cc6eaf 20 int ctrl=3;
chris 2:9e757151de9b 21 int main ()
okano 0:ce7a8546502b 22 {
jw574 10:091f48cc6eaf 23 red = 1;
jw574 10:091f48cc6eaf 24 green = 1;
jw574 10:091f48cc6eaf 25 blue = 1;
jw574 10:091f48cc6eaf 26 lcd.cls();
jw574 10:091f48cc6eaf 27 start();
jw574 10:091f48cc6eaf 28 menu();
jw574 10:091f48cc6eaf 29 while(1) {
jw574 10:091f48cc6eaf 30 if (left == 1) {
jw574 10:091f48cc6eaf 31 ctrl = 1;
jw574 10:091f48cc6eaf 32 }
jw574 10:091f48cc6eaf 33 if (right == 1) {
jw574 10:091f48cc6eaf 34 ctrl = 2;
jw574 10:091f48cc6eaf 35 }
jw574 10:091f48cc6eaf 36 if (up == 1) {
jw574 10:091f48cc6eaf 37 ctrl = 1;
jw574 10:091f48cc6eaf 38 }
jw574 10:091f48cc6eaf 39 if (down == 1) {
jw574 10:091f48cc6eaf 40 ctrl = 2;
jw574 10:091f48cc6eaf 41 }
jw574 10:091f48cc6eaf 42 if (fire == 1){
jw574 10:091f48cc6eaf 43 ctrl = 0;
jw574 10:091f48cc6eaf 44 }
jw574 10:091f48cc6eaf 45 switch (ctrl){
jw574 10:091f48cc6eaf 46 case 0:
jw574 10:091f48cc6eaf 47 menu();
jw574 10:091f48cc6eaf 48 break;
jw574 10:091f48cc6eaf 49 case 1:
jw574 10:091f48cc6eaf 50 while(1) {
jw574 10:091f48cc6eaf 51 lcd.cls();
jw574 10:091f48cc6eaf 52 lcd.locate(0,3);
jw574 10:091f48cc6eaf 53 lcd.printf("Temp = %.1f\n", sensor.temp());
jw574 10:091f48cc6eaf 54 float i = 0.0;
jw574 10:091f48cc6eaf 55 i = sensor.temp();
jw574 10:091f48cc6eaf 56 if (i>28.0) {
jw574 10:091f48cc6eaf 57 blue =1;
jw574 10:091f48cc6eaf 58 green = 1;
jw574 10:091f48cc6eaf 59 red = 0;
jw574 10:091f48cc6eaf 60 lcd.locate(0,15);
jw574 10:091f48cc6eaf 61 lcd.printf("So Hot!");
jw574 10:091f48cc6eaf 62 } else if (i<18.0) {
jw574 10:091f48cc6eaf 63 red = 1;
jw574 10:091f48cc6eaf 64 green = 1;
jw574 10:091f48cc6eaf 65 blue = 0;
jw574 10:091f48cc6eaf 66 lcd.locate(0,15);
jw574 10:091f48cc6eaf 67 lcd.printf("Really Cold.....");
jw574 10:091f48cc6eaf 68 } else {
jw574 10:091f48cc6eaf 69 red = 1;
jw574 10:091f48cc6eaf 70 blue = 1;
jw574 10:091f48cc6eaf 71 green = 0;
jw574 10:091f48cc6eaf 72 lcd.locate(0,15);
jw574 10:091f48cc6eaf 73 lcd.printf("Comfortable!!!");
jw574 10:091f48cc6eaf 74 }
jw574 10:091f48cc6eaf 75 wait(1.0);
jw574 10:091f48cc6eaf 76 if(fire == 1) {
jw574 10:091f48cc6eaf 77 lcd.cls();
jw574 10:091f48cc6eaf 78 ctrl = 0;
jw574 10:091f48cc6eaf 79 red = 1;
jw574 10:091f48cc6eaf 80 green = 1;
jw574 10:091f48cc6eaf 81 blue = 1;
jw574 10:091f48cc6eaf 82 break;
jw574 10:091f48cc6eaf 83 }
jw574 10:091f48cc6eaf 84 }
jw574 10:091f48cc6eaf 85 break;
jw574 10:091f48cc6eaf 86 case 2:
jw574 10:091f48cc6eaf 87 while(1) {
jw574 10:091f48cc6eaf 88 lcd.cls();
jw574 10:091f48cc6eaf 89 lcd.locate(0,3);
jw574 10:091f48cc6eaf 90 lcd.printf("Pot 1 = %.2f", (float)pot1);
jw574 10:091f48cc6eaf 91 lcd.locate(0,14);
jw574 10:091f48cc6eaf 92 lcd.printf("Pot 2 = %.2f", (float)pot2);
jw574 10:091f48cc6eaf 93 wait(0.1);
jw574 10:091f48cc6eaf 94 spkr.period((float)pot1/(float)pot2);
jw574 10:091f48cc6eaf 95 spkr=0.8;
jw574 10:091f48cc6eaf 96 wait(0.02);
jw574 10:091f48cc6eaf 97 if(fire == 1) {
jw574 10:091f48cc6eaf 98 ctrl = 0;
jw574 10:091f48cc6eaf 99 spkr = 0;
jw574 10:091f48cc6eaf 100 lcd.cls();
jw574 10:091f48cc6eaf 101 break;
jw574 10:091f48cc6eaf 102 }
jw574 10:091f48cc6eaf 103 }
jw574 10:091f48cc6eaf 104 break;
jw574 10:091f48cc6eaf 105 }
chris 2:9e757151de9b 106 }
okano 0:ce7a8546502b 107 }
jw574 10:091f48cc6eaf 108 void menu(void)
jw574 10:091f48cc6eaf 109 {
jw574 10:091f48cc6eaf 110 lcd.locate(0,3);
jw574 10:091f48cc6eaf 111 lcd.printf("welcome to mbed world!");
jw574 10:091f48cc6eaf 112 }
jw574 10:091f48cc6eaf 113
jw574 10:091f48cc6eaf 114 void start(void)
jw574 10:091f48cc6eaf 115 {
jw574 10:091f48cc6eaf 116 int j=5;
jw574 10:091f48cc6eaf 117 while(1) {
jw574 10:091f48cc6eaf 118 lcd.locate(0,3);
jw574 10:091f48cc6eaf 119 lcd.printf("reboot system please wait");
jw574 10:091f48cc6eaf 120 lcd.locate(0,15);
jw574 10:091f48cc6eaf 121 lcd.printf("time : %d",j);
jw574 10:091f48cc6eaf 122 j--;
jw574 10:091f48cc6eaf 123 wait(1.0);
jw574 10:091f48cc6eaf 124 if(j==0) {
jw574 10:091f48cc6eaf 125 break;
jw574 10:091f48cc6eaf 126 }
jw574 10:091f48cc6eaf 127 }
jw574 10:091f48cc6eaf 128 lcd.cls();
jw574 10:091f48cc6eaf 129 }
jw574 10:091f48cc6eaf 130