![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
my code as off 16/12/2018
Dependencies: mbed BMP280 ELEC350-Practicals-FZ429_2
main.cpp@1:e274a5cc021d, 2018-12-16 (annotated)
- Committer:
- ChrisHayes
- Date:
- Sun Dec 16 15:25:04 2018 +0000
- Revision:
- 1:e274a5cc021d
- Parent:
- 0:d01bf1d73c6e
this is my code up two 16/12/2018
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ChrisHayes | 0:d01bf1d73c6e | 1 | #include "mbed.h" |
ChrisHayes | 0:d01bf1d73c6e | 2 | #include "TextLCD.h" |
ChrisHayes | 0:d01bf1d73c6e | 3 | #include "sample_hardware.hpp" |
ChrisHayes | 1:e274a5cc021d | 4 | #include "sample_buffer.hpp" |
ChrisHayes | 1:e274a5cc021d | 5 | //#include "mbed_events.h" |
ChrisHayes | 1:e274a5cc021d | 6 | #include "take_a_sample_queue.hpp" |
ChrisHayes | 1:e274a5cc021d | 7 | #include "set_time_on_startup.hpp" |
ChrisHayes | 1:e274a5cc021d | 8 | |
ChrisHayes | 1:e274a5cc021d | 9 | //#include "stdio.h" |
ChrisHayes | 1:e274a5cc021d | 10 | |
ChrisHayes | 1:e274a5cc021d | 11 | |
ChrisHayes | 1:e274a5cc021d | 12 | Ticker timing; |
ChrisHayes | 0:d01bf1d73c6e | 13 | |
ChrisHayes | 0:d01bf1d73c6e | 14 | |
ChrisHayes | 0:d01bf1d73c6e | 15 | TextLCD lcd(D9, D8, D7, D6, D4, D2); // rs, e, d4 |
ChrisHayes | 0:d01bf1d73c6e | 16 | DigitalOut myled(LED1); |
ChrisHayes | 1:e274a5cc021d | 17 | //AnalogIn LDRin(PA0); |
ChrisHayes | 0:d01bf1d73c6e | 18 | |
ChrisHayes | 0:d01bf1d73c6e | 19 | EventQueue queue; |
ChrisHayes | 1:e274a5cc021d | 20 | EventQueue remove_sample; |
ChrisHayes | 0:d01bf1d73c6e | 21 | |
ChrisHayes | 1:e274a5cc021d | 22 | |
ChrisHayes | 1:e274a5cc021d | 23 | |
ChrisHayes | 1:e274a5cc021d | 24 | //-------------------------------------------------------------------------------- |
ChrisHayes | 1:e274a5cc021d | 25 | |
ChrisHayes | 1:e274a5cc021d | 26 | |
ChrisHayes | 1:e274a5cc021d | 27 | |
ChrisHayes | 1:e274a5cc021d | 28 | Thread t1; //sample event queue |
ChrisHayes | 1:e274a5cc021d | 29 | Thread t2; //counting up time |
ChrisHayes | 1:e274a5cc021d | 30 | Thread t3; //website |
ChrisHayes | 1:e274a5cc021d | 31 | Thread t4; //serial |
ChrisHayes | 1:e274a5cc021d | 32 | |
ChrisHayes | 1:e274a5cc021d | 33 | void take_sample (void) |
ChrisHayes | 0:d01bf1d73c6e | 34 | { |
ChrisHayes | 1:e274a5cc021d | 35 | queue.call_every(1, takeSampleFun); |
ChrisHayes | 1:e274a5cc021d | 36 | queue.dispatch(); |
ChrisHayes | 1:e274a5cc021d | 37 | } |
ChrisHayes | 1:e274a5cc021d | 38 | |
ChrisHayes | 1:e274a5cc021d | 39 | void display_sample_lcd (void) |
ChrisHayes | 1:e274a5cc021d | 40 | { |
ChrisHayes | 1:e274a5cc021d | 41 | while(1) |
ChrisHayes | 1:e274a5cc021d | 42 | { |
ChrisHayes | 1:e274a5cc021d | 43 | greenLED = !greenLED; |
ChrisHayes | 1:e274a5cc021d | 44 | float pressure = takeDataFromBuffer(2); |
ChrisHayes | 1:e274a5cc021d | 45 | |
ChrisHayes | 1:e274a5cc021d | 46 | float light = takeDataFromBuffer(1); |
ChrisHayes | 0:d01bf1d73c6e | 47 | |
ChrisHayes | 1:e274a5cc021d | 48 | float temp = takeDataFromBuffer(0); |
ChrisHayes | 1:e274a5cc021d | 49 | |
ChrisHayes | 1:e274a5cc021d | 50 | lcd.printf("T=%5.1f", temp); |
ChrisHayes | 1:e274a5cc021d | 51 | lcd.printf("L=%5.1f\n", light); |
ChrisHayes | 1:e274a5cc021d | 52 | lcd.printf(" P=%1.5f\n", pressure); |
ChrisHayes | 1:e274a5cc021d | 53 | Thread::wait(2000); |
ChrisHayes | 1:e274a5cc021d | 54 | } |
ChrisHayes | 1:e274a5cc021d | 55 | } |
ChrisHayes | 1:e274a5cc021d | 56 | |
ChrisHayes | 1:e274a5cc021d | 57 | void test3 (void) |
ChrisHayes | 1:e274a5cc021d | 58 | { |
ChrisHayes | 1:e274a5cc021d | 59 | while(1) |
ChrisHayes | 1:e274a5cc021d | 60 | { |
ChrisHayes | 1:e274a5cc021d | 61 | redLED = !redLED; |
ChrisHayes | 1:e274a5cc021d | 62 | Thread::wait(1000); |
ChrisHayes | 1:e274a5cc021d | 63 | } |
ChrisHayes | 1:e274a5cc021d | 64 | } |
ChrisHayes | 1:e274a5cc021d | 65 | |
ChrisHayes | 1:e274a5cc021d | 66 | void test4 (void) |
ChrisHayes | 1:e274a5cc021d | 67 | { |
ChrisHayes | 1:e274a5cc021d | 68 | while(1) |
ChrisHayes | 1:e274a5cc021d | 69 | { |
ChrisHayes | 1:e274a5cc021d | 70 | //yellowLED = !yellowLED; |
ChrisHayes | 1:e274a5cc021d | 71 | Thread::wait(1000); |
ChrisHayes | 1:e274a5cc021d | 72 | } |
ChrisHayes | 1:e274a5cc021d | 73 | } |
ChrisHayes | 0:d01bf1d73c6e | 74 | |
ChrisHayes | 0:d01bf1d73c6e | 75 | |
ChrisHayes | 0:d01bf1d73c6e | 76 | int main() { |
ChrisHayes | 0:d01bf1d73c6e | 77 | |
ChrisHayes | 1:e274a5cc021d | 78 | post(); |
ChrisHayes | 1:e274a5cc021d | 79 | |
ChrisHayes | 1:e274a5cc021d | 80 | lcd.printf("Hello World!\n"); |
ChrisHayes | 1:e274a5cc021d | 81 | lcd.printf("Uhhhh\n"); |
ChrisHayes | 0:d01bf1d73c6e | 82 | wait(1); |
ChrisHayes | 0:d01bf1d73c6e | 83 | |
ChrisHayes | 0:d01bf1d73c6e | 84 | lcd.cls(); |
ChrisHayes | 1:e274a5cc021d | 85 | // timing.attach(&takeSampleFun, 2.0); |
ChrisHayes | 1:e274a5cc021d | 86 | button_time(); |
ChrisHayes | 0:d01bf1d73c6e | 87 | |
ChrisHayes | 0:d01bf1d73c6e | 88 | |
ChrisHayes | 1:e274a5cc021d | 89 | t1.start(take_sample); |
ChrisHayes | 1:e274a5cc021d | 90 | t2.start(display_sample_lcd); |
ChrisHayes | 1:e274a5cc021d | 91 | t3.start(test3); |
ChrisHayes | 1:e274a5cc021d | 92 | t4.start(test4); |
ChrisHayes | 1:e274a5cc021d | 93 | |
ChrisHayes | 1:e274a5cc021d | 94 | |
ChrisHayes | 0:d01bf1d73c6e | 95 | } |