Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main.cpp
- Committer:
- jplunkett
- Date:
- 2017-07-07
- Revision:
- 3:520f682abfab
- Parent:
- 1:67a9d5cee87c
- Child:
- 4:327a3341b5f3
File content as of revision 3:520f682abfab:
#include "CameraOV528.h"
#include "mbed.h"
#include "FATFileSystem.h"
#include "SDBlockDevice.h"
#include <stdio.h>
CameraOV528 camera(D1, D0);// DX, RX
SDBlockDevice bd(PTE3, PTE1, PTE2, PTE4); // MOSI, MISO, SCLK, CS
FATFileSystem fs("fs");
DigitalOut led(LED_GREEN);
DigitalIn btn(SW2);
int picture_count;
int format_fs(){
int error = 0;
printf("Welcome to the filesystem example.\r\n"
"Formatting a FAT, RAM-backed filesystem. ");
error = FATFileSystem::format(&bd);
if (error)
printf("Failure. %d\r\n", error);
else
printf("done.\r\n");
return error;
}
int mount_fs() {
printf("Mounting the filesystem on \"/fs\". ");
int error = fs.mount(&bd);
if (error)
printf("Failure. %d\r\n", error);
else
printf("done.\r\n");
return error;
}
void init_fs() {
if (mount_fs()) {
format_fs();
mount_fs();
}
}
void blink() {
led = !led;
}
void take_and_store_photo() {
blink();
if(camera.take_picture() == 0) {
printf("Picture taken.\r\n");
uint32_t size = camera.get_picture_size();
uint8_t* data_buff = (uint8_t*)malloc(size);
uint32_t bytes_read = camera.read_picture_data(data_buff, size);
char filename[30];
sprintf(filename, "/fs/img%d.jpg", picture_count++);
printf("Opening a new file, %s.\r\n", filename);
FILE* fd = fopen(filename, "wb");
fwrite(data_buff, sizeof(uint8_t), bytes_read, fd);
fclose(fd);
printf("Picture saved.\r\n\n");
free(data_buff);
}
else {
printf("Failed to take photo.\r\n\n");
}
}
int main() {
picture_count = 0;
init_fs();
camera.powerup();
while (true) {
if (!btn.read()) {
take_and_store_photo();
}
}
}

Camera OV528