VC0706 driver for radio shack camera shield

Dependencies:   MODSERIAL

Sample Code

#include "mbed.h"
#include "SDFileSystem.h"
#include "CameraShield.h"
#include <stdio.h>


unsigned char VC0706_rx_buffer[80];
    

SDFileSystem sd(PTE3, PTE1, PTE2, PTE4, "sd", PTE6, SDFileSystem::SWITCH_POS_NO, 25000000); // MOSI, MISO, SCLK, SSEL
CameraShield camera(PTC17, PTC16);


void CapturePhoto()
{
    uint32_t    frame_length = camera.VC0706_get_frame_buffer_length();        //get frame buffer length
    uint32_t    vc_frame_address = READ_DATA_BLOCK_NO;    
        
    FILE* camFile = fopen("/sd/temp.jpg", "w");
        
    while(vc_frame_address<frame_length)
    {   
        camera.VC0706_read_frame_buffer(vc_frame_address - READ_DATA_BLOCK_NO, READ_DATA_BLOCK_NO);
        wait_ms(9);

        //get the data with length=READ_DATA_BLOCK_NObytes 
        camera.buffer_read(VC0706_rx_buffer, 80);

        // write data to temp.jpg
        fwrite(VC0706_rx_buffer + 5, sizeof(char), READ_DATA_BLOCK_NO, camFile);
    
        //read next READ_DATA_BLOCK_NO bytes from frame buffer
        vc_frame_address = vc_frame_address + READ_DATA_BLOCK_NO;
    }

    // get the last data
    vc_frame_address = vc_frame_address - READ_DATA_BLOCK_NO;
    uint32_t last_data_length = frame_length - vc_frame_address;
    
    camera.VC0706_read_frame_buffer(vc_frame_address, last_data_length);
    wait_ms(9);
    //get the data 
    camera.buffer_read(VC0706_rx_buffer, 80);
            
    fwrite(VC0706_rx_buffer+5, sizeof(char), last_data_length, camFile);
    
    fclose(camFile);
}

 
int main (void) 
{                      
    // Check to see if the file exists: 
    // if exists,delete the file:
    sd.remove("/sd/temp.jpg");
    
    camera.Init();  
    camera.VC0706_image_size(VC0706_640x480);
    camera.ResumeVideo();   
    wait_ms(500);   
    
    
    while(1)
    {
        camera.ResumeVideo();   
        wait_ms(1000);
        
        camera.TakeSnapShot();
        CapturePhoto(); 
    }
}

Revision graph

The revision graph only works with JavaScript-enabled browsers.