camera testing
main.cpp@0:7fe6e8b6aaba, 2015-01-31 (annotated)
- Committer:
- John5049
- Date:
- Sat Jan 31 17:23:41 2015 +0000
- Revision:
- 0:7fe6e8b6aaba
Added the code for the Infrared Camera, this code takes 4 photos each separated by ~5 seconds, and stores the photos in the mbed directory on one's computer.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
John5049 | 0:7fe6e8b6aaba | 1 | #include "mbed.h" |
John5049 | 0:7fe6e8b6aaba | 2 | #include "JPEGCamera.h" |
John5049 | 0:7fe6e8b6aaba | 3 | |
John5049 | 0:7fe6e8b6aaba | 4 | DigitalOut myled1(LED1); //show successful picture was taken |
John5049 | 0:7fe6e8b6aaba | 5 | DigitalOut myled2(LED2); //show end of sequence |
John5049 | 0:7fe6e8b6aaba | 6 | DigitalOut myled3(LED3); //show picture take failed |
John5049 | 0:7fe6e8b6aaba | 7 | DigitalOut myled4(LED4); //show camera is not ready |
John5049 | 0:7fe6e8b6aaba | 8 | |
John5049 | 0:7fe6e8b6aaba | 9 | int main() { |
John5049 | 0:7fe6e8b6aaba | 10 | JPEGCamera camera(p9, p10); // TX, RX |
John5049 | 0:7fe6e8b6aaba | 11 | LocalFileSystem local("local"); //save images on mbed |
John5049 | 0:7fe6e8b6aaba | 12 | Timer timer; |
John5049 | 0:7fe6e8b6aaba | 13 | timer.start(); |
John5049 | 0:7fe6e8b6aaba | 14 | camera.setPictureSize(JPEGCamera::SIZE320x240); |
John5049 | 0:7fe6e8b6aaba | 15 | |
John5049 | 0:7fe6e8b6aaba | 16 | for (int i = 1; i < 5; i++) { |
John5049 | 0:7fe6e8b6aaba | 17 | if (camera.isReady()) { |
John5049 | 0:7fe6e8b6aaba | 18 | char filename[32]; |
John5049 | 0:7fe6e8b6aaba | 19 | sprintf(filename, "/local/pict%03d.jpg", i); |
John5049 | 0:7fe6e8b6aaba | 20 | printf("Picture: %s ", filename); |
John5049 | 0:7fe6e8b6aaba | 21 | if (camera.takePicture(filename)) { |
John5049 | 0:7fe6e8b6aaba | 22 | while (camera.isProcessing()) { |
John5049 | 0:7fe6e8b6aaba | 23 | camera.processPicture(); |
John5049 | 0:7fe6e8b6aaba | 24 | } |
John5049 | 0:7fe6e8b6aaba | 25 | myled1 = 1; //show successful picture was taken |
John5049 | 0:7fe6e8b6aaba | 26 | wait(2.0); |
John5049 | 0:7fe6e8b6aaba | 27 | myled1 = 0; |
John5049 | 0:7fe6e8b6aaba | 28 | } else { |
John5049 | 0:7fe6e8b6aaba | 29 | printf("take picture failed\n"); |
John5049 | 0:7fe6e8b6aaba | 30 | myled3 = 1; //show picture take failed |
John5049 | 0:7fe6e8b6aaba | 31 | wait(2.0); |
John5049 | 0:7fe6e8b6aaba | 32 | myled3 = 0; |
John5049 | 0:7fe6e8b6aaba | 33 | } |
John5049 | 0:7fe6e8b6aaba | 34 | } else { |
John5049 | 0:7fe6e8b6aaba | 35 | printf("camera is not ready\n"); |
John5049 | 0:7fe6e8b6aaba | 36 | myled4 = 1; //show camera is not ready |
John5049 | 0:7fe6e8b6aaba | 37 | wait(2.0); |
John5049 | 0:7fe6e8b6aaba | 38 | myled4 = 0; |
John5049 | 0:7fe6e8b6aaba | 39 | } |
John5049 | 0:7fe6e8b6aaba | 40 | } |
John5049 | 0:7fe6e8b6aaba | 41 | myled2 = 1; //show end of sequence |
John5049 | 0:7fe6e8b6aaba | 42 | wait(2.0); |
John5049 | 0:7fe6e8b6aaba | 43 | myled2 = 0; |
John5049 | 0:7fe6e8b6aaba | 44 | printf("time = %f\n", timer.read()); |
John5049 | 0:7fe6e8b6aaba | 45 | } |