![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Camera program for buzz booth
main.cpp@0:a9083c11b10b, 2015-12-08 (annotated)
- Committer:
- bfoley13
- Date:
- Tue Dec 08 00:41:58 2015 +0000
- Revision:
- 0:a9083c11b10b
Camera for buzz booth
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
bfoley13 | 0:a9083c11b10b | 1 | #include "mbed.h" |
bfoley13 | 0:a9083c11b10b | 2 | #include "JPEGCamera.h" |
bfoley13 | 0:a9083c11b10b | 3 | #include "emic2.h" |
bfoley13 | 0:a9083c11b10b | 4 | |
bfoley13 | 0:a9083c11b10b | 5 | DigitalOut myled1(LED1); //show successful picture was taken |
bfoley13 | 0:a9083c11b10b | 6 | DigitalOut myled2(LED2); //show end of sequence |
bfoley13 | 0:a9083c11b10b | 7 | DigitalOut myled3(LED3); //show picture take failed |
bfoley13 | 0:a9083c11b10b | 8 | DigitalOut myled4(LED4); //show camera is not ready |
bfoley13 | 0:a9083c11b10b | 9 | Serial pc(USBTX, USBRX); |
bfoley13 | 0:a9083c11b10b | 10 | |
bfoley13 | 0:a9083c11b10b | 11 | DigitalIn handShake(p21); |
bfoley13 | 0:a9083c11b10b | 12 | JPEGCamera camera(p9, p10); // TX, RX |
bfoley13 | 0:a9083c11b10b | 13 | emic2 myTTS(p13, p14); //serial RX,TX pins to emic |
bfoley13 | 0:a9083c11b10b | 14 | int picNum = 0; |
bfoley13 | 0:a9083c11b10b | 15 | char filename[32]; |
bfoley13 | 0:a9083c11b10b | 16 | |
bfoley13 | 0:a9083c11b10b | 17 | char* takePic(){ |
bfoley13 | 0:a9083c11b10b | 18 | LocalFileSystem local("local"); //save images on mbed |
bfoley13 | 0:a9083c11b10b | 19 | Timer timer; |
bfoley13 | 0:a9083c11b10b | 20 | timer.start(); |
bfoley13 | 0:a9083c11b10b | 21 | |
bfoley13 | 0:a9083c11b10b | 22 | camera.setPictureSize(JPEGCamera::SIZE320x240); |
bfoley13 | 0:a9083c11b10b | 23 | |
bfoley13 | 0:a9083c11b10b | 24 | if (camera.isReady()) { |
bfoley13 | 0:a9083c11b10b | 25 | sprintf(filename, "/local/pict%03d.jpg", picNum++); |
bfoley13 | 0:a9083c11b10b | 26 | printf("Picture: %s ", filename); |
bfoley13 | 0:a9083c11b10b | 27 | if (camera.takePicture(filename)) { |
bfoley13 | 0:a9083c11b10b | 28 | while (camera.isProcessing()) { |
bfoley13 | 0:a9083c11b10b | 29 | camera.processPicture(); |
bfoley13 | 0:a9083c11b10b | 30 | } |
bfoley13 | 0:a9083c11b10b | 31 | myled1 = 1; //show successful picture was taken |
bfoley13 | 0:a9083c11b10b | 32 | wait(2.0); |
bfoley13 | 0:a9083c11b10b | 33 | myled1 = 0; |
bfoley13 | 0:a9083c11b10b | 34 | } else { |
bfoley13 | 0:a9083c11b10b | 35 | printf("take picture failed\n"); |
bfoley13 | 0:a9083c11b10b | 36 | myled3 = 1; //show picture take failed |
bfoley13 | 0:a9083c11b10b | 37 | wait(2.0); |
bfoley13 | 0:a9083c11b10b | 38 | myled3 = 0; |
bfoley13 | 0:a9083c11b10b | 39 | } |
bfoley13 | 0:a9083c11b10b | 40 | } else { |
bfoley13 | 0:a9083c11b10b | 41 | printf("camera is not ready\n"); |
bfoley13 | 0:a9083c11b10b | 42 | myled4 = 1; //show camera is not ready |
bfoley13 | 0:a9083c11b10b | 43 | wait(2.0); |
bfoley13 | 0:a9083c11b10b | 44 | myled4 = 0; |
bfoley13 | 0:a9083c11b10b | 45 | } |
bfoley13 | 0:a9083c11b10b | 46 | |
bfoley13 | 0:a9083c11b10b | 47 | myled2 = 1; //show end of sequence |
bfoley13 | 0:a9083c11b10b | 48 | wait(2.0); |
bfoley13 | 0:a9083c11b10b | 49 | myled2 = 0; |
bfoley13 | 0:a9083c11b10b | 50 | printf("time = %f\n", timer.read()); |
bfoley13 | 0:a9083c11b10b | 51 | |
bfoley13 | 0:a9083c11b10b | 52 | return filename; |
bfoley13 | 0:a9083c11b10b | 53 | } |
bfoley13 | 0:a9083c11b10b | 54 | |
bfoley13 | 0:a9083c11b10b | 55 | |
bfoley13 | 0:a9083c11b10b | 56 | int main() |
bfoley13 | 0:a9083c11b10b | 57 | { |
bfoley13 | 0:a9083c11b10b | 58 | myTTS.volume(18); //max volume |
bfoley13 | 0:a9083c11b10b | 59 | while(1) { |
bfoley13 | 0:a9083c11b10b | 60 | if (handShake == 0) { |
bfoley13 | 0:a9083c11b10b | 61 | wait(0.5); |
bfoley13 | 0:a9083c11b10b | 62 | //Buzz speaks |
bfoley13 | 0:a9083c11b10b | 63 | myTTS.speakf("S");//Speak command starts with "S" |
bfoley13 | 0:a9083c11b10b | 64 | myTTS.speakf("Hello! My name is Buzz, the GT Yellow Jacket. I am going to take a picture. Smile!", 8); // Send the desired string to convert to speech |
bfoley13 | 0:a9083c11b10b | 65 | myTTS.speakf("\r"); //marks end of speak command |
bfoley13 | 0:a9083c11b10b | 66 | myTTS.ready(); //ready waits for speech to finish from last command with a ":" response |
bfoley13 | 0:a9083c11b10b | 67 | |
bfoley13 | 0:a9083c11b10b | 68 | char* file = takePic(); |
bfoley13 | 0:a9083c11b10b | 69 | |
bfoley13 | 0:a9083c11b10b | 70 | } |
bfoley13 | 0:a9083c11b10b | 71 | |
bfoley13 | 0:a9083c11b10b | 72 | } |
bfoley13 | 0:a9083c11b10b | 73 | } |