ser_project
Dependencies: 4DGL-uLCD-SE C12832 LM75B mbed-rtos mbed
main.cpp@0:7677c6736b9f, 2016-05-19 (annotated)
- Committer:
- kvothe345
- Date:
- Thu May 19 10:36:23 2016 +0000
- Revision:
- 0:7677c6736b9f
ola
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
kvothe345 | 0:7677c6736b9f | 1 | #include "mbed.h" |
kvothe345 | 0:7677c6736b9f | 2 | #include "C12832.h" |
kvothe345 | 0:7677c6736b9f | 3 | #include "LM75B.h" |
kvothe345 | 0:7677c6736b9f | 4 | |
kvothe345 | 0:7677c6736b9f | 5 | |
kvothe345 | 0:7677c6736b9f | 6 | |
kvothe345 | 0:7677c6736b9f | 7 | //------------------------------------------------------------------------// |
kvothe345 | 0:7677c6736b9f | 8 | // Hardware Variables // |
kvothe345 | 0:7677c6736b9f | 9 | //------------------------------------------------------------------------// |
kvothe345 | 0:7677c6736b9f | 10 | Serial rn41 (p9,p10); |
kvothe345 | 0:7677c6736b9f | 11 | Serial pc (USBTX,USBRX); |
kvothe345 | 0:7677c6736b9f | 12 | C12832 lcd (p5, p7, p6, p8, p11); |
kvothe345 | 0:7677c6736b9f | 13 | LM75B sensor (p28,p27); |
kvothe345 | 0:7677c6736b9f | 14 | //BusOut led (LED4,LED3,LED2,LED1); |
kvothe345 | 0:7677c6736b9f | 15 | DigitalOut led1 (LED1); |
kvothe345 | 0:7677c6736b9f | 16 | DigitalOut led2 (LED2); |
kvothe345 | 0:7677c6736b9f | 17 | DigitalOut led3 (LED3); |
kvothe345 | 0:7677c6736b9f | 18 | DigitalOut led4 (LED4); |
kvothe345 | 0:7677c6736b9f | 19 | AnalogIn pot(p19); |
kvothe345 | 0:7677c6736b9f | 20 | AnalogIn pot2(p20); |
kvothe345 | 0:7677c6736b9f | 21 | |
kvothe345 | 0:7677c6736b9f | 22 | |
kvothe345 | 0:7677c6736b9f | 23 | //------------------------------------------------------------------------// |
kvothe345 | 0:7677c6736b9f | 24 | // Function Headears // |
kvothe345 | 0:7677c6736b9f | 25 | //------------------------------------------------------------------------// |
kvothe345 | 0:7677c6736b9f | 26 | void bluetoothReceive (); |
kvothe345 | 0:7677c6736b9f | 27 | void setupBluetooth (); |
kvothe345 | 0:7677c6736b9f | 28 | |
kvothe345 | 0:7677c6736b9f | 29 | |
kvothe345 | 0:7677c6736b9f | 30 | char buff[100]; |
kvothe345 | 0:7677c6736b9f | 31 | |
kvothe345 | 0:7677c6736b9f | 32 | //------------------------------------------------------------------------// |
kvothe345 | 0:7677c6736b9f | 33 | // Functions // |
kvothe345 | 0:7677c6736b9f | 34 | //------------------------------------------------------------------------// |
kvothe345 | 0:7677c6736b9f | 35 | |
kvothe345 | 0:7677c6736b9f | 36 | float read_temp() |
kvothe345 | 0:7677c6736b9f | 37 | { |
kvothe345 | 0:7677c6736b9f | 38 | |
kvothe345 | 0:7677c6736b9f | 39 | if (sensor.open()) { |
kvothe345 | 0:7677c6736b9f | 40 | printf("Device detected!\n"); |
kvothe345 | 0:7677c6736b9f | 41 | |
kvothe345 | 0:7677c6736b9f | 42 | while (1) { |
kvothe345 | 0:7677c6736b9f | 43 | lcd.cls(); |
kvothe345 | 0:7677c6736b9f | 44 | lcd.locate(0,3); |
kvothe345 | 0:7677c6736b9f | 45 | lcd.printf("Temp = %.3f\n", (float)sensor); |
kvothe345 | 0:7677c6736b9f | 46 | return sensor; |
kvothe345 | 0:7677c6736b9f | 47 | } |
kvothe345 | 0:7677c6736b9f | 48 | } else { |
kvothe345 | 0:7677c6736b9f | 49 | error("Device not detected!\n"); |
kvothe345 | 0:7677c6736b9f | 50 | return -1; |
kvothe345 | 0:7677c6736b9f | 51 | } |
kvothe345 | 0:7677c6736b9f | 52 | |
kvothe345 | 0:7677c6736b9f | 53 | } |
kvothe345 | 0:7677c6736b9f | 54 | |
kvothe345 | 0:7677c6736b9f | 55 | |
kvothe345 | 0:7677c6736b9f | 56 | |
kvothe345 | 0:7677c6736b9f | 57 | void bluetoothReceive () |
kvothe345 | 0:7677c6736b9f | 58 | { |
kvothe345 | 0:7677c6736b9f | 59 | char caracter; |
kvothe345 | 0:7677c6736b9f | 60 | float t; |
kvothe345 | 0:7677c6736b9f | 61 | |
kvothe345 | 0:7677c6736b9f | 62 | memset (buff,'\0',sizeof(buff)); |
kvothe345 | 0:7677c6736b9f | 63 | lcd.locate(10,15); |
kvothe345 | 0:7677c6736b9f | 64 | lcd.printf(": wait msg"); |
kvothe345 | 0:7677c6736b9f | 65 | while (rn41.readable()) { |
kvothe345 | 0:7677c6736b9f | 66 | caracter = rn41.getc(); |
kvothe345 | 0:7677c6736b9f | 67 | rn41.putc(caracter); |
kvothe345 | 0:7677c6736b9f | 68 | buff[strlen(buff)]= caracter; |
kvothe345 | 0:7677c6736b9f | 69 | led3 = 1; |
kvothe345 | 0:7677c6736b9f | 70 | } |
kvothe345 | 0:7677c6736b9f | 71 | lcd.locate(10,15); |
kvothe345 | 0:7677c6736b9f | 72 | lcd.printf(": %s",buff); |
kvothe345 | 0:7677c6736b9f | 73 | led1 = 0; |
kvothe345 | 0:7677c6736b9f | 74 | if(buff[0] == 't') { |
kvothe345 | 0:7677c6736b9f | 75 | led2 = 1; |
kvothe345 | 0:7677c6736b9f | 76 | t = read_temp(); |
kvothe345 | 0:7677c6736b9f | 77 | caracter = t; |
kvothe345 | 0:7677c6736b9f | 78 | rn41.putc(caracter); |
kvothe345 | 0:7677c6736b9f | 79 | } |
kvothe345 | 0:7677c6736b9f | 80 | } |
kvothe345 | 0:7677c6736b9f | 81 | |
kvothe345 | 0:7677c6736b9f | 82 | void setupBluetooth () |
kvothe345 | 0:7677c6736b9f | 83 | { |
kvothe345 | 0:7677c6736b9f | 84 | lcd.locate(10,15); |
kvothe345 | 0:7677c6736b9f | 85 | lcd.printf(": setu"); |
kvothe345 | 0:7677c6736b9f | 86 | rn41.baud(115200); |
kvothe345 | 0:7677c6736b9f | 87 | rn41.format(8,SerialBase::None,1); |
kvothe345 | 0:7677c6736b9f | 88 | rn41.attach(&bluetoothReceive, Serial::RxIrq); |
kvothe345 | 0:7677c6736b9f | 89 | } |
kvothe345 | 0:7677c6736b9f | 90 | |
kvothe345 | 0:7677c6736b9f | 91 | |
kvothe345 | 0:7677c6736b9f | 92 | //void executing_thread(){ |
kvothe345 | 0:7677c6736b9f | 93 | |
kvothe345 | 0:7677c6736b9f | 94 | |
kvothe345 | 0:7677c6736b9f | 95 | |
kvothe345 | 0:7677c6736b9f | 96 | |
kvothe345 | 0:7677c6736b9f | 97 | //} |
kvothe345 | 0:7677c6736b9f | 98 | |
kvothe345 | 0:7677c6736b9f | 99 | |
kvothe345 | 0:7677c6736b9f | 100 | |
kvothe345 | 0:7677c6736b9f | 101 | //------------------------------------------------------------------------// |
kvothe345 | 0:7677c6736b9f | 102 | // Main // |
kvothe345 | 0:7677c6736b9f | 103 | //------------------------------------------------------------------------// |
kvothe345 | 0:7677c6736b9f | 104 | int main() |
kvothe345 | 0:7677c6736b9f | 105 | { |
kvothe345 | 0:7677c6736b9f | 106 | memset (buff,'\0',sizeof(buff)); |
kvothe345 | 0:7677c6736b9f | 107 | lcd.cls(); |
kvothe345 | 0:7677c6736b9f | 108 | |
kvothe345 | 0:7677c6736b9f | 109 | setupBluetooth(); |
kvothe345 | 0:7677c6736b9f | 110 | //Thread executing(executing_thread); |
kvothe345 | 0:7677c6736b9f | 111 | |
kvothe345 | 0:7677c6736b9f | 112 | pc.baud(9600); |
kvothe345 | 0:7677c6736b9f | 113 | |
kvothe345 | 0:7677c6736b9f | 114 | lcd.cls(); |
kvothe345 | 0:7677c6736b9f | 115 | lcd.locate(0,3); |
kvothe345 | 0:7677c6736b9f | 116 | lcd.printf("I'm the MBED board!"); |
kvothe345 | 0:7677c6736b9f | 117 | led1=1; |
kvothe345 | 0:7677c6736b9f | 118 | |
kvothe345 | 0:7677c6736b9f | 119 | |
kvothe345 | 0:7677c6736b9f | 120 | |
kvothe345 | 0:7677c6736b9f | 121 | } |