This works:
// ArduCAM Mini demo (C)2017 Lee
// Web: http://www.ArduCAM.com
// This program is a demo of how to use most of the functions
// of the library with ArduCAM Mini camera, and can run on any Arduino platform.
// This demo was made for ArduCAM_Mini_5MP_Plus.
// It needs to be used in combination with PC software.
// It can test OV5642 functions.
//
// This program requires the ArduCAM V4.0.0 (or later) library and ArduCAM_Mini_5MP_Plus
// and use Arduino IDE 1.6.8 compiler or above
/*
MCU to Device Pinout with Description Layout
MCU (Arduino Uno/Mega) ArduCAM Mini 5MP OV5642 Pin Description Color
---------------------- --------------------------------------- -----
28(A5)/21 SCL Orange - Clock (I2C)
27(A4)/20 SDA Green - Data (I2C)
5V VCC Red - VCC (voltage common collector)
GND GND Black - GND
13/52 SCK Orange - Clock (SPI)
12/50 MISO Green - MISO (SPI)
11/51 MOSI Yellow - MOSI (SPI)
10/53 CS Blue - Device CS (can be any pin)
Where:
SCL = I2C Clock
SDA = I2C Data
VCC = 5V in
GND = ground
SCK = SPI Clock; max SPI bus speed is 8MHz
MISO = SPI MISO
MOSI = SPI MISO
CS = chip select
*/
#include <Wire.h>
#include <SPI.h>
#include <ArduCAM.h>
// This file is modified version of the generic library; it is custom configured for the ArduCAM_Mini_5MP_Plus (OV5642)
#include <memorysaver.h>
// This demo only works on the OV5642_MINI_5MP_Plus platform
#if !(defined OV5642_MINI_5MP_PLUS)
#error Please select the hardware platform and camera module in the ../libraries/ArduCAM/memorysaver.h file
#endif
#define BMPIMAGEOFFSET 66
const char bmp_header[BMPIMAGEOFFSET] PROGMEM =
{
0x42, 0x4D, 0x36, 0x58, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x42, 0x00, 0x00, 0x00, 0x28, 0x00,
0x00, 0x00, 0x40, 0x01, 0x00, 0x00, 0xF0, 0x00, 0x00, 0x00, 0x01, 0x00, 0x10, 0x00, 0x03, 0x00,
0x00, 0x00, 0x00, 0x58, 0x02, 0x00, 0xC4, 0x0E, 0x00, 0x00, 0xC4, 0x0E, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF8, 0x00, 0x00, 0xE0, 0x07, 0x00, 0x00, 0x1F, 0x00,
0x00, 0x00
};
// Set pin 53 as the slave select (can be any pin)
const int CS = 53;
bool is_header = false;
int mode = 0;
uint8_t start_capture = 0;
ArduCAM myCAM( OV5642, CS );
uint8_t read_fifo_burst(ArduCAM myCAM);
void setup() {
uint8_t vid, pid;
uint8_t temp;
#if defined(__SAM3X8E__)
Wire1.begin();
Serial.begin(115200);
#else
Wire.begin();
Serial.begin(921600);
#endif
Serial.println(F("ACK CMD ArduCAM Start! END"));
// Set the CS as an output:
pinMode(CS, OUTPUT);
digitalWrite(CS, HIGH);
// Initialize SPI:
SPI.begin();
// Reset the CPLD
myCAM.write_reg(0x07, 0x80);
delay(100);
myCAM.write_reg(0x07, 0x00);
delay(100);
while(1){
// Check if the ArduCAM SPI bus is OK
myCAM.write_reg(ARDUCHIP_TEST1, 0x55);
temp = myCAM.read_reg(ARDUCHIP_TEST1);
if (temp != 0x55) {
Serial.println(F("ACK CMD SPI interface Error! END"));
delay(1000);
continue;
} else {
Serial.println(F("ACK CMD SPI interface OK. END"));
break;
}
}
while(1) {
// Check if the camera module type is OV5642
myCAM.wrSensorReg16_8(0xff, 0x01);
myCAM.rdSensorReg16_8(OV5642_CHIPID_HIGH, &vid);
myCAM.rdSensorReg16_8(OV5642_CHIPID_LOW, &pid);
if((vid != 0x56) || (pid != 0x42)) {
Serial.println(F("ACK CMD Can't find OV5642 module! END"));
delay(1000);
continue;
}
else {
Serial.println(F("ACK CMD OV5642 detected. END"));
break;
}
}
// Change to JPEG capture mode and initialize the OV5642 module
myCAM.set_format(JPEG);
myCAM.InitCAM();
myCAM.write_reg(ARDUCHIP_TIM, VSYNC_LEVEL_MASK); // VSYNC is active HIGH
myCAM.OV5642_set_JPEG_size(OV5642_320x240);
delay(1000);
myCAM.clear_fifo_flag();
myCAM.write_reg(ARDUCHIP_FRAMES,0x00);
}
void loop() {
uint8_t temp = 0xff, temp_last = 0;
bool is_header = false;
if (Serial.available()) {
temp = Serial.read();
switch (temp) {
case 0:
myCAM.OV5642_set_JPEG_size(OV5642_320x240);
delay(1000);
Serial.println(F("ACK CMD switch to OV5642_320x240 END"));
temp = 0xff;
break;
case 1:
myCAM.OV5642_set_JPEG_size(OV5642_640x480);
delay(1000);
Serial.println(F("ACK CMD switch to OV5642_640x480 END"));
temp = 0xff;
break;
case 2:
myCAM.OV5642_set_JPEG_size(OV5642_1024x768);
delay(1000);
Serial.println(F("ACK CMD switch to OV5642_1024x768 END"));
temp = 0xff;
break;
case 3:
temp = 0xff;
myCAM.OV5642_set_JPEG_size(OV5642_1280x960);
delay(1000);
Serial.println(F("ACK CMD switch to OV5642_1280x960 END"));
break;
case 4:
temp = 0xff;
myCAM.OV5642_set_JPEG_size(OV5642_1600x1200);
delay(1000);
Serial.println(F("ACK CMD switch to OV5642_1600x1200 END"));
break;
case 5:
temp = 0xff;
myCAM.OV5642_set_JPEG_size(OV5642_2048x1536);
delay(1000);
Serial.println(F("ACK CMD switch to OV5642_2048x1536 END"));
break;
case 6:
temp = 0xff;
myCAM.OV5642_set_JPEG_size(OV5642_2592x1944);
delay(1000);
Serial.println(F("ACK CMD switch to OV5642_2592x1944 END"));
break;
case 0x10:
mode = 1;
temp = 0xff;
start_capture = 1;
Serial.println(F("ACK CMD CAM start single shoot. END"));
break;
case 0x11:
temp = 0xff;
myCAM.set_format(JPEG);
myCAM.InitCAM();
#if !(defined (OV2640_MINI_2MP))
myCAM.set_bit(ARDUCHIP_TIM, VSYNC_LEVEL_MASK);
#endif
break;
case 0x20:
mode = 2;
temp = 0xff;
start_capture = 2;
Serial.println(F("ACK CMD CAM start video streaming. END"));
break;
case 0x30:
mode = 3;
temp = 0xff;
start_capture = 3;
Serial.println(F("ACK CMD CAM start single shoot. END"));
break;
case 0x31:
temp = 0xff;
myCAM.set_format(BMP);
myCAM.InitCAM();
myCAM.clear_bit(ARDUCHIP_TIM, VSYNC_LEVEL_MASK);
myCAM.wrSensorReg16_8(0x3818, 0x81);
myCAM.wrSensorReg16_8(0x3621, 0xA7);
break;
case 0x40:
myCAM.OV5642_set_Light_Mode(Advanced_AWB);
temp = 0xff;
Serial.println(F("ACK CMD Set to Advanced_AWB END"));
break;
case 0x41:
myCAM.OV5642_set_Light_Mode(Simple_AWB);
temp = 0xff;
Serial.println(F("ACK CMD Set to Simple_AWB END"));
break;
case 0x42:
myCAM.OV5642_set_Light_Mode(Manual_day);
temp = 0xff;
Serial.println(F("ACK CMD Set to Manual_day END"));
break;
case 0x43:
myCAM.OV5642_set_Light_Mode(Manual_A);
temp = 0xff;
Serial.println(F("ACK CMD Set to Manual_A END"));
break;
case 0x44:
myCAM.OV5642_set_Light_Mode(Manual_cwf);
temp = 0xff;
Serial.println(F("ACK CMD Set to Manual_cwf END"));
break;
case 0x45:
myCAM.OV5642_set_Light_Mode(Manual_cloudy);
temp = 0xff;
Serial.println(F("ACK CMD Set to Manual_cloudy END"));
break;
case 0x50:
myCAM.OV5642_set_Color_Saturation(Saturation4);
temp = 0xff;
Serial.println(F("ACK CMD Set to Saturation+4 END"));
break;
case 0x51:
myCAM.OV5642_set_Color_Saturation(Saturation3);
temp = 0xff;
Serial.println(F("ACK CMD Set to Saturation+3 END"));
break;
case 0x52:
myCAM.OV5642_set_Color_Saturation(Saturation2);
temp = 0xff;
Serial.println(F("ACK CMD Set to Saturation+2 END"));
break;
case 0x53:
myCAM.OV5642_set_Color_Saturation(Saturation1);
temp = 0xff;
Serial.println(F("ACK CMD Set to Saturation+1 END"));
break;
case 0x54:
myCAM.OV5642_set_Color_Saturation(Saturation0);
temp = 0xff;
Serial.println(F("ACK CMD Set to Saturation+0 END"));
break;
case 0x55:
myCAM.OV5642_set_Color_Saturation(Saturation_1);
temp = 0xff;
Serial.println(F("ACK CMD Set to Saturation-1 END"));
break;
case 0x56:
myCAM.OV5642_set_Color_Saturation(Saturation_2);
temp = 0xff;
Serial.println(F("ACK CMD Set to Saturation-2"));
break;
case 0x57:
myCAM.OV5642_set_Color_Saturation(Saturation_3);
temp = 0xff;
Serial.println(F("ACK CMD Set to Saturation-3 END"));
break;
case 0x58:
myCAM.OV5642_set_Light_Mode(Saturation_4);
temp = 0xff;
Serial.println(F("ACK CMD Set to Saturation-4 END"));
break;
case 0x60:
myCAM.OV5642_set_Brightness(Brightness4);
temp = 0xff;
Serial.println(F("ACK CMD Set to Brightness+4 END"));
break;
case 0x61:
myCAM.OV5642_set_Brightness(Brightness3);
temp = 0xff;
Serial.println(F("ACK CMD Set to Brightness+3 END"));
break;
case 0x62:
myCAM.OV5642_set_Brightness(Brightness2);
temp = 0xff;
Serial.println(F("ACK CMD Set to Brightness+2 END"));
break;
case 0x63:
myCAM.OV5642_set_Brightness(Brightness1);
temp = 0xff;
Serial.println(F("ACK CMD Set to Brightness+1 END"));
break;
case 0x64:
myCAM.OV5642_set_Brightness(Brightness0);
temp = 0xff;
Serial.println(F("ACK CMD Set to Brightness+0 END"));
break;
case 0x65:
myCAM.OV5642_set_Brightness(Brightness_1);
temp = 0xff;
Serial.println(F("ACK CMD Set to Brightness-1 END"));
break;
case 0x66:
myCAM.OV5642_set_Brightness(Brightness_2);
temp = 0xff;
Serial.println(F("ACK CMD Set to Brightness-2 END"));
break;
case 0x67:
myCAM.OV5642_set_Brightness(Brightness_3);
temp = 0xff;
Serial.println(F("ACK CMD Set to Brightness-3 END"));
break;
case 0x68:
myCAM.OV5642_set_Brightness(Brightness_4);
temp = 0xff;
Serial.println(F("ACK CMD Set to Brightness-4 END"));
break;
case 0x70:
myCAM.OV5642_set_Contrast(Contrast4);
temp = 0xff;
Serial.println(F("ACK CMD Set to Contrast+4 END"));
break;
case 0x71:
myCAM.OV5642_set_Contrast(Contrast3);
temp = 0xff;
Serial.println(F("ACK CMD Set to Contrast+3 END"));
break;
case 0x72:
myCAM.OV5642_set_Contrast(Contrast2);
temp = 0xff;
Serial.println(F("ACK CMD Set to Contrast+2 END"));
break;
case 0x73:
myCAM.OV5642_set_Contrast(Contrast1);
temp = 0xff;
Serial.println(F("ACK CMD Set to Contrast+1 END"));
break;
case 0x74:
myCAM.OV5642_set_Contrast(Contrast0);
temp = 0xff;
Serial.println(F("ACK CMD Set to Contrast+0 END"));
break;
case 0x75:
myCAM.OV5642_set_Contrast(Contrast_1);
temp = 0xff;
Serial.println(F("ACK CMD Set to Contrast-1 END"));
break;
case 0x76:
myCAM.OV5642_set_Contrast(Contrast_2);
temp = 0xff;
Serial.println(F("ACK CMD Set to Contrast-2 END"));
break;
case 0x77:
myCAM.OV5642_set_Contrast(Contrast_3);
temp = 0xff;
Serial.println(F("ACK CMD Set to Contrast-3 END"));
break;
case 0x78:
myCAM.OV5642_set_Contrast(Contrast_4);
temp = 0xff;
Serial.println(F("ACK CMD Set to Contrast-4 END"));
break;
case 0x80:
myCAM.OV5642_set_hue(degree_180);
temp = 0xff;
Serial.println(F("ACK CMD Set to -180 degree END"));
break;
case 0x81:
myCAM.OV5642_set_hue(degree_150);
temp = 0xff;
Serial.println(F("ACK CMD Set to -150 degree END"));
break;
case 0x82:
myCAM.OV5642_set_hue(degree_120);
temp = 0xff;
Serial.println(F("ACK CMD Set to -120 degree END"));
break;
case 0x83:
myCAM.OV5642_set_hue(degree_90);
temp = 0xff;
Serial.println(F("ACK CMD Set to -90 degree END"));
break;
case 0x84:
myCAM.OV5642_set_hue(degree_60);
temp = 0xff;
Serial.println(F("ACK CMD Set to -60 degree END"));
break;
case 0x85:
myCAM.OV5642_set_hue(degree_30);
temp = 0xff;
Serial.println(F("ACK CMD Set to -30 degree END"));
break;
case 0x86:
myCAM.OV5642_set_hue(degree_0);
temp = 0xff;
Serial.println(F("ACK CMD Set to 0 degree END"));
break;
case 0x87:
myCAM.OV5642_set_hue(degree30);
temp = 0xff;
Serial.println(F("ACK CMD Set to 30 degree END"));
break;
case 0x88:
myCAM.OV5642_set_hue(degree60);
temp = 0xff;
Serial.println(F("ACK CMD Set to 60 degree END"));
break;
case 0x89:
myCAM.OV5642_set_hue(degree90);
temp = 0xff;
Serial.println(F("ACK CMD Set to 90 degree END"));
break;
case 0x8a:
myCAM.OV5642_set_hue(degree120);
temp = 0xff;
Serial.println(F("ACK CMD Set to 120 degree END"));
break;
case 0x8b:
myCAM.OV5642_set_hue(degree150);
temp = 0xff;
Serial.println(F("ACK CMD Set to 150 degree END"));
break;
case 0x90:
myCAM.OV5642_set_Special_effects(Normal);
temp = 0xff;
Serial.println(F("ACK CMD Set to Normal END"));
break;
case 0x91:
myCAM.OV5642_set_Special_effects(BW);
temp = 0xff;
Serial.println(F("ACK CMD Set to BW END"));
break;
case 0x92:
myCAM.OV5642_set_Special_effects(Bluish);
temp = 0xff;
Serial.println(F("ACK CMD Set to Bluish END"));
break;
case 0x93:
myCAM.OV5642_set_Special_effects(Sepia);
temp = 0xff;
Serial.println(F("ACK CMD Set to Sepia END"));
break;
case 0x94:
myCAM.OV5642_set_Special_effects(Reddish);
temp = 0xff;
Serial.println(F("ACK CMD Set to Reddish END"));
break;
case 0x95:
myCAM.OV5642_set_Special_effects(Greenish);
temp = 0xff;
Serial.println(F("ACK CMD Set to Greenish END"));
break;
case 0x96:
myCAM.OV5642_set_Special_effects(Negative);
temp = 0xff;
Serial.println(F("ACK CMD Set to Negative END"));
break;
case 0xA0:
myCAM.OV5642_set_Exposure_level(Exposure_17_EV);
temp = 0xff;
Serial.println(F("ACK CMD Set to -1.7EV"));
break;
case 0xA1:
myCAM.OV5642_set_Exposure_level(Exposure_13_EV);
temp = 0xff;
Serial.println(F("ACK CMD Set to -1.3EV END"));
break;
case 0xA2:
myCAM.OV5642_set_Exposure_level(Exposure_10_EV);
temp = 0xff;
Serial.println(F("ACK CMD Set to -1.0EV END"));
break;
case 0xA3:
myCAM.OV5642_set_Exposure_level(Exposure_07_EV);
temp = 0xff;
Serial.println(F("ACK CMD Set to -0.7EV END"));
break;
case 0xA4:
myCAM.OV5642_set_Exposure_level(Exposure_03_EV);
temp = 0xff;
Serial.println(F("ACK CMD Set to -0.3EV END"));
break;
case 0xA5:
myCAM.OV5642_set_Exposure_level(Exposure_default);
temp = 0xff;
Serial.println(F("ACK CMD Set to -Exposure_default END"));
break;
case 0xA6:
myCAM.OV5642_set_Exposure_level(Exposure07_EV);
temp = 0xff;
Serial.println(F("ACK CMD Set to 0.7EV END"));
break;
case 0xA7:
myCAM.OV5642_set_Exposure_level(Exposure10_EV);
temp = 0xff;
Serial.println(F("ACK CMD Set to 1.0EV END"));
break;
case 0xA8:
myCAM.OV5642_set_Exposure_level(Exposure13_EV);
temp = 0xff;
Serial.println(F("ACK CMD Set to 1.3EV END"));
break;
case 0xA9:
myCAM.OV5642_set_Exposure_level(Exposure17_EV);
temp = 0xff;
Serial.println(F("ACK CMD Set to 1.7EV END"));
break;
case 0xB0:
myCAM.OV5642_set_Sharpness(Auto_Sharpness_default);
temp = 0xff;
Serial.println(F("ACK CMD Set to Auto Sharpness default END"));
break;
case 0xB1:
myCAM.OV5642_set_Sharpness(Auto_Sharpness1);
temp = 0xff;
Serial.println(F("ACK CMD Set to Auto Sharpness +1 END"));
break;
case 0xB2:
myCAM.OV5642_set_Sharpness(Auto_Sharpness2);
temp = 0xff;
Serial.println(F("ACK CMD Set to Auto Sharpness +2 END"));
break;
case 0xB3:
myCAM.OV5642_set_Sharpness(Manual_Sharpnessoff);
temp = 0xff;
Serial.println(F("ACK CMD Set to Auto Manual Sharpness off END"));
break;
case 0xB4:
myCAM.OV5642_set_Sharpness(Manual_Sharpness1);
temp = 0xff;
Serial.println(F("ACK CMD Set to Auto Manual Sharpness +1 END"));
break;
case 0xB5:
myCAM.OV5642_set_Sharpness(Manual_Sharpness2);
temp = 0xff;
Serial.println(F("ACK CMD Set to Auto Manual Sharpness +2 END"));
break;
case 0xB6:
myCAM.OV5642_set_Sharpness(Manual_Sharpness3);
temp = 0xff;
Serial.println(F("ACK CMD Set to Auto Manual Sharpness +3 END"));
break;
case 0xB7:
myCAM.OV5642_set_Sharpness(Manual_Sharpness4);
temp = 0xff;
Serial.println(F("ACK CMD Set to Auto Manual Sharpness +4 END"));
break;
case 0xB8:
myCAM.OV5642_set_Sharpness(Manual_Sharpness5);
temp = 0xff;
Serial.println(F("ACK CMD Set to Auto Manual Sharpness +5 END"));
break;
case 0xC0:
myCAM.OV5642_set_Mirror_Flip(MIRROR);
temp = 0xff;
Serial.println(F("ACK CMD Set to MIRROR END"));
break;
case 0xC1:
myCAM.OV5642_set_Mirror_Flip(FLIP);
temp = 0xff;
Serial.println(F("ACK CMD Set to FLIP END"));
break;
case 0xC2:
myCAM.OV5642_set_Mirror_Flip(MIRROR_FLIP);
temp = 0xff;
Serial.println(F("ACK CMD Set to MIRROR&FLIP END"));
break;
case 0xC3:
myCAM.OV5642_set_Mirror_Flip(Normal);
temp = 0xff;
Serial.println(F("ACK CMD Set to Normal END"));
break;
case 0xD0:
myCAM.OV5642_set_Compress_quality(high_quality);
temp = 0xff;
Serial.println(F("ACK CMD Set to high quality END"));
break;
case 0xD1:
myCAM.OV5642_set_Compress_quality(default_quality);
temp = 0xff;
Serial.println(F("ACK CMD Set to default quality END"));
break;
case 0xD2:
myCAM.OV5642_set_Compress_quality(low_quality);
temp = 0xff;
Serial.println(F("ACK CMD Set to low quality END"));
break;
case 0xE0:
myCAM.OV5642_Test_Pattern(Color_bar);
temp = 0xff;
Serial.println(F("ACK CMD Set to Color bar END"));
break;
case 0xE1:
myCAM.OV5642_Test_Pattern(Color_square);
temp = 0xff;
Serial.println(F("ACK CMD Set to Color square END"));
break;
case 0xE2:
myCAM.OV5642_Test_Pattern(BW_square);
temp = 0xff;
Serial.println(F("ACK CMD Set to BW square END"));
break;
case 0xE3:
myCAM.OV5642_Test_Pattern(DLI);
temp = 0xff;
Serial.println(F("ACK CMD Set to DLI END"));
break;
default:
break;
}
}
if (mode == 1) {
if (start_capture == 1) {
myCAM.flush_fifo();
myCAM.clear_fifo_flag();
// Start capture
myCAM.start_capture();
start_capture = 0;
}
if (myCAM.get_bit(ARDUCHIP_TRIG, CAP_DONE_MASK)) {
Serial.println(F("ACK CMD CAM Capture Done. END"));
delay(50);
read_fifo_burst(myCAM);
// Clear the capture done flag
myCAM.clear_fifo_flag();
}
} else if (mode == 2) {
while (1) {
temp = Serial.read();
if (temp == 0x21) {
start_capture = 0;
mode = 0;
Serial.println(F("ACK CMD CAM stop video streaming. END"));
break;
}
switch(temp) {
case 0x40:
myCAM.OV5642_set_Light_Mode(Advanced_AWB);
temp = 0xff;
Serial.println(F("ACK CMD Set to Advanced_AWB END"));
break;
case 0x41:
myCAM.OV5642_set_Light_Mode(Simple_AWB);
temp = 0xff;
Serial.println(F("ACK CMD Set to Simple_AWB END"));
break;
case 0x42:
myCAM.OV5642_set_Light_Mode(Manual_day);
temp = 0xff;
Serial.println(F("ACK CMD Set to Manual_day END"));
break;
case 0x43:
myCAM.OV5642_set_Light_Mode(Manual_A);
temp = 0xff;
Serial.println(F("ACK CMD Set to Manual_A END"));
break;
case 0x44:
myCAM.OV5642_set_Light_Mode(Manual_cwf);
temp = 0xff;
Serial.println(F("ACK CMD Set to Manual_cwf END"));
break;
case 0x45:
myCAM.OV5642_set_Light_Mode(Manual_cloudy);
temp = 0xff;
Serial.println(F("ACK CMD Set to Manual_cloudy END"));
break;
case 0x50:
myCAM.OV5642_set_Color_Saturation(Saturation4);
temp = 0xff;
Serial.println(F("ACK CMD Set to Saturation+4 END"));
break;
case 0x51:
myCAM.OV5642_set_Color_Saturation(Saturation3);
temp = 0xff;
Serial.println(F("ACK CMD Set to Saturation+3 END"));
break;
case 0x52:
myCAM.OV5642_set_Color_Saturation(Saturation2);
temp = 0xff;
Serial.println(F("ACK CMD Set to Saturation+2 END"));
break;
case 0x53:
myCAM.OV5642_set_Color_Saturation(Saturation1);
temp = 0xff;
Serial.println(F("ACK CMD Set to Saturation+1 END"));
break;
case 0x54:
myCAM.OV5642_set_Color_Saturation(Saturation0);
temp = 0xff;
Serial.println(F("ACK CMD Set to Saturation+0 END"));
break;
case 0x55:
myCAM.OV5642_set_Color_Saturation(Saturation_1);
temp = 0xff;
Serial.println(F("ACK CMD Set to Saturation-1 END"));
break;
case 0x56:
myCAM.OV5642_set_Color_Saturation(Saturation_2);
temp = 0xff;
Serial.println(F("ACK CMD Set to Saturation-2 END"));
break;
case 0x57:
myCAM.OV5642_set_Color_Saturation(Saturation_3);
temp = 0xff;
Serial.println(F("ACK CMD Set to Saturation-3 END"));
break;
case 0x58:
myCAM.OV5642_set_Light_Mode(Saturation_4);
temp = 0xff;
Serial.println(F("ACK CMD Set to Saturation-4 END"));
break;
case 0x60:
myCAM.OV5642_set_Brightness(Brightness4);
temp = 0xff;
Serial.println(F("ACK CMD Set to Brightness+4 END"));
break;
case 0x61:
myCAM.OV5642_set_Brightness(Brightness3);
temp = 0xff;
Serial.println(F("ACK CMD Set to Brightness+3 END"));
break;
case 0x62:
myCAM.OV5642_set_Brightness(Brightness2);
temp = 0xff;
Serial.println(F("ACK CMD Set to Brightness+2 END"));
break;
case 0x63:
myCAM.OV5642_set_Brightness(Brightness1);
temp = 0xff;
Serial.println(F("ACK CMD Set to Brightness+1 END"));
break;
case 0x64:
myCAM.OV5642_set_Brightness(Brightness0);
temp = 0xff;
Serial.println(F("ACK CMD Set to Brightness+0 END"));
break;
case 0x65:
myCAM.OV5642_set_Brightness(Brightness_1);
temp = 0xff;
Serial.println(F("ACK CMD Set to Brightness-1 END"));
break;
case 0x66:
myCAM.OV5642_set_Brightness(Brightness_2);
temp = 0xff;
Serial.println(F("ACK CMD Set to Brightness-2 END"));
break;
case 0x67:
myCAM.OV5642_set_Brightness(Brightness_3);
temp = 0xff;
Serial.println(F("ACK CMD Set to Brightness-3 END"));
break;
case 0x68:
myCAM.OV5642_set_Brightness(Brightness_4);
temp = 0xff;
Serial.println(F("ACK CMD Set to Brightness-4 END"));
break;
case 0x70:
myCAM.OV5642_set_Contrast(Contrast4);
temp = 0xff;
Serial.println(F("ACK CMD Set to Contrast+4 END"));
break;
case 0x71:
myCAM.OV5642_set_Contrast(Contrast3);
temp = 0xff;
Serial.println(F("ACK CMD Set to Contrast+3 END"));
break;
case 0x72:
myCAM.OV5642_set_Contrast(Contrast2);
temp = 0xff;
Serial.println(F("ACK CMD Set to Contrast+2 END"));
break;
case 0x73:
myCAM.OV5642_set_Contrast(Contrast1);
temp = 0xff;
Serial.println(F("ACK CMD Set to Contrast+1 END"));
break;
case 0x74:
myCAM.OV5642_set_Contrast(Contrast0);
temp = 0xff;
Serial.println(F("ACK CMD Set to Contrast+0 END"));
break;
case 0x75:
myCAM.OV5642_set_Contrast(Contrast_1);
temp = 0xff;
Serial.println(F("ACK CMD Set to Contrast-1 END"));
break;
case 0x76:
myCAM.OV5642_set_Contrast(Contrast_2);
temp = 0xff;
Serial.println(F("ACK CMD Set to Contrast-2 END"));
break;
case 0x77:
myCAM.OV5642_set_Contrast(Contrast_3);
temp = 0xff;
Serial.println(F("ACK CMD Set to Contrast-3 END"));
break;
case 0x78:
myCAM.OV5642_set_Contrast(Contrast_4);
temp = 0xff;
Serial.println(F("ACK CMD Set to Contrast-4 END"));
break;
case 0x80:
myCAM.OV5642_set_hue(degree_180);
temp = 0xff;
Serial.println(F("ACK CMD Set to -180 degree END"));
break;
case 0x81:
myCAM.OV5642_set_hue(degree_150);
temp = 0xff;
Serial.println(F("ACK CMD Set to -150 degree END"));
break;
case 0x82:
myCAM.OV5642_set_hue(degree_120);
temp = 0xff;
Serial.println(F("ACK CMD Set to -120 degree END"));
break;
case 0x83:
myCAM.OV5642_set_hue(degree_90);
temp = 0xff;
Serial.println(F("ACK CMD Set to -90 degree END"));
break;
case 0x84:
myCAM.OV5642_set_hue(degree_60);
temp = 0xff;
Serial.println(F("ACK CMD Set to -60 degree END"));
break;
case 0x85:
myCAM.OV5642_set_hue(degree_30);
temp = 0xff;
Serial.println(F("ACK CMD Set to -30 degree END"));
break;
case 0x86:
myCAM.OV5642_set_hue(degree_0);
temp = 0xff;
Serial.println(F("ACK CMD Set to 0 degree END"));
break;
case 0x87:
myCAM.OV5642_set_hue(degree30);
temp = 0xff;
Serial.println(F("ACK CMD Set to 30 degree END"));
break;
case 0x88:
myCAM.OV5642_set_hue(degree60);
temp = 0xff;
Serial.println(F("ACK CMD Set to 60 degree END"));
break;
case 0x89:
myCAM.OV5642_set_hue(degree90);
temp = 0xff;
Serial.println(F("ACK CMD Set to 90 degree END"));
break;
case 0x8a:
myCAM.OV5642_set_hue(degree120);
temp = 0xff;
Serial.println(F("ACK CMD Set to 120 degree END"));
break;
case 0x8b:
myCAM.OV5642_set_hue(degree150);
temp = 0xff;
Serial.println(F("ACK CMD Set to 150 degree END"));
break;
case 0x90:
myCAM.OV5642_set_Special_effects(Normal);
temp = 0xff;
Serial.println(F("ACK CMD Set to Normal END"));
break;
case 0x91:
myCAM.OV5642_set_Special_effects(BW);
temp = 0xff;
Serial.println(F("ACK CMD Set to BW END"));
break;
case 0x92:
myCAM.OV5642_set_Special_effects(Bluish);
temp = 0xff;
Serial.println(F("ACK CMD Set to Bluish END"));
break;
case 0x93:
myCAM.OV5642_set_Special_effects(Sepia);
temp = 0xff;
Serial.println(F("ACK CMD Set to Sepia END"));
break;
case 0x94:
myCAM.OV5642_set_Special_effects(Reddish);
temp = 0xff;
Serial.println(F("ACK CMD Set to Reddish END"));
break;
case 0x95:
myCAM.OV5642_set_Special_effects(Greenish);
temp = 0xff;
Serial.println(F("ACK CMD Set to Greenish END"));
break;
case 0x96:
myCAM.OV5642_set_Special_effects(Negative);
temp = 0xff;
Serial.println(F("ACK CMD Set to Negative END"));
break;
case 0xA0:
myCAM.OV5642_set_Exposure_level(Exposure_17_EV);
temp = 0xff;
Serial.println(F("ACK CMD Set to -1.7EV END"));
break;
case 0xA1:
myCAM.OV5642_set_Exposure_level(Exposure_13_EV);
temp = 0xff;
Serial.println(F("ACK CMD Set to -1.3EV END"));
break;
case 0xA2:
myCAM.OV5642_set_Exposure_level(Exposure_10_EV);
temp = 0xff;
Serial.println(F("ACK CMD Set to -1.0EV END"));
break;
case 0xA3:
myCAM.OV5642_set_Exposure_level(Exposure_07_EV);
temp = 0xff;
Serial.println(F("ACK CMD Set to -0.7EV END"));
break;
case 0xA4:
myCAM.OV5642_set_Exposure_level(Exposure_03_EV);
temp = 0xff;
Serial.println(F("ACK CMD Set to -0.3EV END"));
break;
case 0xA5:
myCAM.OV5642_set_Exposure_level(Exposure_default);
temp = 0xff;
Serial.println(F("ACK CMD Set to -Exposure_default END"));
break;
case 0xA6:
myCAM.OV5642_set_Exposure_level(Exposure07_EV);
temp = 0xff;
Serial.println(F("ACK CMD Set to 0.7EV END"));
break;
case 0xA7:
myCAM.OV5642_set_Exposure_level(Exposure10_EV);
temp = 0xff;
Serial.println(F("ACK CMD Set to 1.0EV END"));
break;
case 0xA8:
myCAM.OV5642_set_Exposure_level(Exposure13_EV);
temp = 0xff;
Serial.println(F("ACK CMD Set to 1.3EV END"));
break;
case 0xA9:
myCAM.OV5642_set_Exposure_level(Exposure17_EV);
temp = 0xff;
Serial.println(F("ACK CMD Set to 1.7EV END"));
break;
case 0xB0:
myCAM.OV5642_set_Sharpness(Auto_Sharpness_default);
temp = 0xff;
Serial.println(F("ACK CMD Set to Auto Sharpness default END"));
break;
case 0xB1:
myCAM.OV5642_set_Sharpness(Auto_Sharpness1);
temp = 0xff;
Serial.println(F("ACK CMD Set to Auto Sharpness +1 END"));
break;
case 0xB2:
myCAM.OV5642_set_Sharpness(Auto_Sharpness2);
temp = 0xff;
Serial.println(F("ACK CMD Set to Auto Sharpness +2 END"));
break;
case 0xB3:
myCAM.OV5642_set_Sharpness(Manual_Sharpnessoff);
temp = 0xff;
Serial.println(F("ACK CMD Set to Auto Manual Sharpness off END"));
break;
case 0xB4:
myCAM.OV5642_set_Sharpness(Manual_Sharpness1);
temp = 0xff;
Serial.println(F("ACK CMD Set to Auto Manual Sharpness +1 END"));
break;
case 0xB5:
myCAM.OV5642_set_Sharpness(Manual_Sharpness2);
temp = 0xff;
Serial.println(F("ACK CMD Set to Auto Manual Sharpness +2 END"));
break;
case 0xB6:
myCAM.OV5642_set_Sharpness(Manual_Sharpness3);
temp = 0xff;
Serial.println(F("ACK CMD Set to Auto Manual Sharpness +3 END"));
break;
case 0xB7:
myCAM.OV5642_set_Sharpness(Manual_Sharpness4);
temp = 0xff;
Serial.println(F("ACK CMD Set to Auto Manual Sharpness +4 END"));
break;
case 0xB8:
myCAM.OV5642_set_Sharpness(Manual_Sharpness5);
temp = 0xff;
Serial.println(F("ACK CMD Set to Auto Manual Sharpness +5 END"));
break;
case 0xC0:
myCAM.OV5642_set_Mirror_Flip(MIRROR);
temp = 0xff;
Serial.println(F("ACK CMD Set to MIRROR END"));
break;
case 0xC1:
myCAM.OV5642_set_Mirror_Flip(FLIP);
temp = 0xff;
Serial.println(F("ACK CMD Set to FLIP END"));
break;
case 0xC2:
myCAM.OV5642_set_Mirror_Flip(MIRROR_FLIP);
temp = 0xff;
Serial.println(F("ACK CMD Set to MIRROR&FLIP END"));
break;
case 0xC3:
myCAM.OV5642_set_Mirror_Flip(Normal);
temp = 0xff;
Serial.println(F("ACK CMD Set to Normal END"));
break;
case 0xD0:
myCAM.OV5642_set_Compress_quality(high_quality);
temp = 0xff;
Serial.println(F("ACK CMD Set to high quality END"));
break;
case 0xD1:
myCAM.OV5642_set_Compress_quality(default_quality);
temp = 0xff;
Serial.println(F("ACK CMD Set to default quality END"));
break;
case 0xD2:
myCAM.OV5642_set_Compress_quality(low_quality);
temp = 0xff;
Serial.println(F("ACK CMD Set to low quality END"));
break;
case 0xE0:
myCAM.OV5642_Test_Pattern(Color_bar);
temp = 0xff;
Serial.println(F("ACK CMD Set to Color bar END"));
break;
case 0xE1:
myCAM.OV5642_Test_Pattern(Color_square);
temp = 0xff;
Serial.println(F("ACK CMD Set to Color square END"));
break;
case 0xE2:
myCAM.OV5642_Test_Pattern(BW_square);
temp = 0xff;
Serial.println(F("ACK CMD Set to BW square END"));
break;
case 0xE3:
myCAM.OV5642_Test_Pattern(DLI);
temp = 0xff;
Serial.println(F("ACK CMD Set to DLI END"));
break;
}
if (start_capture == 2) {
myCAM.flush_fifo();
myCAM.clear_fifo_flag();
// Start capture
myCAM.start_capture();
start_capture = 0;
}
if (myCAM.get_bit(ARDUCHIP_TRIG, CAP_DONE_MASK)) {
uint32_t length = 0;
length = myCAM.read_fifo_length();
if ((length >= MAX_FIFO_SIZE) | (length == 0)) {
myCAM.clear_fifo_flag();
start_capture = 2;
continue;
}
myCAM.CS_LOW();
myCAM.set_fifo_burst();//Set fifo burst mode
temp = SPI.transfer(0x00);
length --;
while ( length-- ) {
temp_last = temp;
temp = SPI.transfer(0x00);
if (is_header == true) {
Serial.write(temp);
} else if ((temp == 0xD8) & (temp_last == 0xFF)) {
is_header = true;
Serial.println(F("ACK IMG END"));
Serial.write(temp_last);
Serial.write(temp);
}
if ( (temp == 0xD9) && (temp_last == 0xFF) ) // If find the end, break while
break;
delayMicroseconds(15);
}
myCAM.CS_HIGH();
myCAM.clear_fifo_flag();
start_capture = 2;
is_header = false;
}
}
} else if (mode == 3) {
if (start_capture == 3) {
// Flush the FIFO
myCAM.flush_fifo();
myCAM.clear_fifo_flag();
// Start capture
myCAM.start_capture();
start_capture = 0;
}
if (myCAM.get_bit(ARDUCHIP_TRIG, CAP_DONE_MASK)) {
Serial.println(F("ACK CMD CAM Capture Done. END"));
delay(50);
uint8_t temp, temp_last;
uint32_t length = 0;
length = myCAM.read_fifo_length();
if (length >= MAX_FIFO_SIZE ) {
Serial.println(F("ACK CMD Over size. END"));
myCAM.clear_fifo_flag();
return;
}
if (length == 0 ) { // 0 kb
Serial.println(F("ACK CMD Size is 0. END"));
myCAM.clear_fifo_flag();
return;
}
myCAM.CS_LOW();
myCAM.set_fifo_burst(); // Set fifo burst mode
Serial.write(0xFF);
Serial.write(0xAA);
for (temp = 0; temp < BMPIMAGEOFFSET; temp++) {
Serial.write(pgm_read_byte(&bmp_header[temp]));
}
// SPI.transfer(0x00);
char VH, VL;
int i = 0, j = 0;
for (i = 0; i < 240; i++) {
for (j = 0; j < 320; j++) {
VH = SPI.transfer(0x00);;
VL = SPI.transfer(0x00);;
Serial.write(VL);
delayMicroseconds(12);
Serial.write(VH);
delayMicroseconds(12);
}
}
Serial.write(0xBB);
Serial.write(0xCC);
myCAM.CS_HIGH();
// Clear the capture done flag
myCAM.clear_fifo_flag();
}
}
}
uint8_t read_fifo_burst(ArduCAM myCAM) {
uint8_t temp = 0, temp_last = 0;
uint32_t length = 0;
length = myCAM.read_fifo_length();
Serial.println(length, DEC);
if (length >= MAX_FIFO_SIZE) { // 512 kb
Serial.println(F("ACK CMD Over size. END"));
return 0;
}
if (length == 0 ) { // 0 kb
Serial.println(F("ACK CMD Size is 0. END"));
return 0;
}
myCAM.CS_LOW();
myCAM.set_fifo_burst(); // Set fifo burst mode
temp = SPI.transfer(0x00);
length --;
while ( length-- ) {
temp_last = temp;
temp = SPI.transfer(0x00);
if (is_header == true) {
Serial.write(temp);
} else if ((temp == 0xD8) & (temp_last == 0xFF)) {
is_header = true;
Serial.println(F("ACK IMG END"));
Serial.write(temp_last);
Serial.write(temp);
}
if ( (temp == 0xD9) && (temp_last == 0xFF) ) // If find the end, break while
break;
delayMicroseconds(15);
}
myCAM.CS_HIGH();
is_header = false;
return 1;
}
This also works:
// Adafruit_ImageReader test for 3.5" TFT FeatherWing. Demonstrates loading
// images from SD card or flash memory to the screen, to RAM, and how to
// query image file dimensions. OPEN THE ARDUINO SERIAL MONITOR WINDOW TO
// START PROGRAM. Requires one JPEG and three BMP files in root directory of
// the SD card or flash: 1.bmp, 1.jpg, adabot.bmp, parrot.bmp and wales.bmp.
/*
MCU to Device Pinout with Description Layout
Adafruit TFT LCD Breakout Pin Description
MCU (Arduino Uno/Mega) HX8357D, SPI Mode, 320w x 480h Color
---------------------- ----------------------------------------- -----
GND GND Black - GND
5V 3-5V Red - VCC (voltage common collector)
not connected 3.3V out (connect to IM2) Red - VCO (voltage common collector)
13/52 CLK Orange - Clock (SPI)
12/50 MISO Green - MISO (SPI)
11/51 MOSI Yellow - MOSI (SPI)
9/46 CS Blue - Device CS (can be any pin) (swapped with D/C when TFT LCD Micro SD reader used at same time)
10/47 D/C Blue - Device DC (can be any pin) (swapped with CS when TFT LCD Micro SD reader used at same time)
4/44 RST White - Reset (can be any pin)
not connected Light White - Backlignt
A2/A2 Y+ Yellow - 4-wire resistive touch screen (can be any analog pin)
8/42 X+ Yellow - 4-wire resistive touch screen (can be any pin)
7/40 Y- Green - 4-wire resistive touch screen (can be any pin)
A3/A3 X- Green - 4-wire resistive touch screen (can be any analog pin)
GND GND Black - GND
not connected IM2 (connect to 3.3V out) Red - VCO - interface control set (SPI mode; short to 3.3V to enable)
not connected IM1 White - interface control set
not connected IM0 White - interface control set
5/45 Card CS Blue - Device CS (can be any pin)
6/43 Card Detect (connect to 3.3V through 10K pullup?) Blue - Device CD (can be any pin)
Where: GND = ground
3-5V = 5V in
3.3V out = 3.3V out
CLK = Clock (SPI)
MISO = MISO (SPI)
MOSI = MOSI (SPI)
CS = chip select
D/C = data/command
RST = TFT LCD reset
Light = TFT LCD backlight (3.3V)
Y+ = 4-wire resistive touch screen
X+ = 4-wire resistive touch screen
Y- = 4-wire resistive touch screen
X- = 4-wire resistive touch screen
GND = ground
IM2 = interface control set
IM1 = interface control set
IM0 = interface control set
Card CS = TFT LCD Micro SD Card chip select
Card Detect = TFT LCD Micro SD Card card detect
MCU to Device Pinout with Description Layout
MCU (Arduino Uno/Mega) Adafruit MicroSD Breakout Pin Description Color
---------------------- ----------------------------------------- -----
5V 5V Red - VCC (voltage common collector)
3.3V (not connected) 3V Red - VCC (voltage common collector)
GND GND Black - GND
13/52 CLK Orange - Clock
12/50 D0 Green - MOSI
11/51 D1 Yellow - MISO
10/49 CS Blue - Device CS (can be any pin)
9/48 CD White - Device CD (can be any pin)
Where: CD = chip detect
CS = chip select
D0 = SPI MOSI
D1 = SPI MISO
CLK = SPI clock
GND = ground
3V = 3.3V in
5V = 5V in
*/
#include <Adafruit_GFX.h> // Core graphics library
#include <Adafruit_HX8357.h> // Hardware-specific library
#include <SdFat.h> // SD card & FAT filesystem library
#include <Adafruit_SPIFlash.h> // SPI / QSPI flash library
#include <Adafruit_ImageReader.h> // Image-reading functions
// Comment out the next line to load from SPI/QSPI flash instead of SD card:
#define USE_SD_CARD
// Pin definitions for 2.4" TFT FeatherWing vary among boards...
#if defined(ESP8266)
#define TFT_CS 0
#define TFT_DC 15
#define SD_CS 2
#elif defined(ESP32)
#define TFT_CS 15
#define TFT_DC 33
#define SD_CS 14
#elif defined(TEENSYDUINO)
#define TFT_DC 10
#define TFT_CS 4
#define SD_CS 8
#elif defined(ARDUINO_STM32_FEATHER)
#define TFT_DC PB4
#define TFT_CS PA15
#define SD_CS PC5
#elif defined(ARDUINO_NRF52832_FEATHER) // BSP 0.6.5 and higher!
#define TFT_DC 11
#define TFT_CS 31
#define SD_CS 27
#elif defined(ARDUINO_MAX32620FTHR) || defined(ARDUINO_MAX32630FTHR)
#define TFT_DC P5_4
#define TFT_CS P5_3
#define STMPE_CS P3_3
#define SD_CS P3_2
#else // Anything else!
//#define TFT_CS 9
#define TFT_CS 46
//#define TFT_DC 10
#define TFT_DC 47
//#define SD_CS 5
#define SD_CS 49
#endif
#if defined(USE_SD_CARD)
SdFat SD; // SD card filesystem
Adafruit_ImageReader reader(SD); // Image-reader object, pass in SD filesys
#else
// SPI or QSPI flash filesystem (i.e. CIRCUITPY drive)
#if defined(__SAMD51__) || defined(NRF52840_XXAA)
Adafruit_FlashTransport_QSPI flashTransport(PIN_QSPI_SCK, PIN_QSPI_CS,
PIN_QSPI_IO0, PIN_QSPI_IO1, PIN_QSPI_IO2, PIN_QSPI_IO3);
#else
#if (SPI_INTERFACES_COUNT == 1)
Adafruit_FlashTransport_SPI flashTransport(SS, &SPI);
#else
Adafruit_FlashTransport_SPI flashTransport(SS1, &SPI1);
#endif
#endif
Adafruit_SPIFlash flash(&flashTransport);
FatFileSystem filesys;
Adafruit_ImageReader reader(filesys); // Image-reader, pass in flash filesys
#endif
Adafruit_HX8357 tft = Adafruit_HX8357(TFT_CS, TFT_DC);
Adafruit_Image img; // An image loaded into RAM
int32_t width = 0, // BMP image dimensions
height = 0;
void setup(void) {
ImageReturnCode stat; // Status from image-reading functions
Serial.begin(9600);
#if !defined(ESP32)
while(!Serial); // Wait for Serial Monitor before continuing
#endif
tft.begin(); // Initialize screen
// The Adafruit_ImageReader constructor call (above, before setup())
// accepts an uninitialized SdFat or FatFileSystem object. This MUST
// BE INITIALIZED before using any of the image reader functions!
Serial.print(F("Initializing filesystem..."));
#if defined(USE_SD_CARD)
// SD card is pretty straightforward, a single call...
if(!SD.begin(SD_CS, SD_SCK_MHZ(25))) { // ESP32 requires 25 MHz limit
Serial.println(F("SD begin() failed"));
for(;;); // Fatal error, do not continue
}
#else
// SPI or QSPI flash requires two steps, one to access the bare flash
// memory itself, then the second to access the filesystem within...
if(!flash.begin()) {
Serial.println(F("flash begin() failed"));
for(;;);
}
if(!filesys.begin(&flash)) {
Serial.println(F("filesys begin() failed"));
for(;;);
}
#endif
Serial.println(F("OK!"));
// Fill screen blue. Not a required step, this just shows that we're
// successfully communicating with the screen.
tft.fillScreen(HX8357_BLUE);
// Load BMP file '1.bmp' at position (0,0) (top left).
// Notice the 'reader' object performs this, with 'tft' as an argument.
tft.setRotation(3); // Set rotation
Serial.print(F("Loading 1.bmp to screen..."));
stat = reader.drawBMP("/1.bmp", tft, 0, 0);
// (Absolute path isn't necessary on most devices, but something
// with the ESP32 SD library seems to require it.)
reader.printStatus(stat); // How'd we do?
// Load full-screen BMP file 'adabot.bmp' at position (0,0) (top left).
// Notice the 'reader' object performs this, with 'tft' as an argument.
tft.setRotation(2); // Set rotation
Serial.print(F("Loading adabot.bmp to screen..."));
stat = reader.drawBMP("/adabot.bmp", tft, 0, 0);
// (Absolute path isn't necessary on most devices, but something
// with the ESP32 SD library seems to require it.)
reader.printStatus(stat); // How'd we do?
// Query the dimensions of image 'parrot.bmp' WITHOUT loading to screen:
Serial.print(F("Querying parrot.bmp image size..."));
stat = reader.bmpDimensions("/parrot.bmp", &width, &height);
reader.printStatus(stat); // How'd we do?
if(stat == IMAGE_SUCCESS) { // If it worked, print image size...
Serial.print(F("Image dimensions: "));
Serial.print(width);
Serial.write('x');
Serial.println(height);
}
// Load small BMP 'wales.bmp' into a GFX canvas in RAM. This should
// fail gracefully on AVR and other small devices, meaning the image
// will not load, but this won't make the program stop or crash, it
// just continues on without it.
Serial.print(F("Loading wales.bmp to canvas..."));
stat = reader.loadBMP("/wales.bmp", img);
reader.printStatus(stat); // How'd we do?
delay(2000); // Pause 2 seconds before moving on to loop()
}
void loop() {
for(int r=0; r<4; r++) { // For each of 4 rotations...
tft.setRotation(r); // Set rotation
tft.fillScreen(0); // and clear screen
// Load 4 copies of the 'parrot.bmp' image to the screen, some
// partially off screen edges to demonstrate clipping. Globals
// 'width' and 'height' were set by bmpDimensions() call in setup().
for(int i=0; i<4; i++) {
reader.drawBMP("/parrot.bmp", tft,
(tft.width() * i / 3) - (width / 2),
(tft.height() * i / 3) - (height / 2));
}
delay(1000); // Pause 1 sec.
// Draw 50 Welsh dragon flags in random positions. This has no effect
// on memory-constrained boards like the Arduino Uno, where the image
// failed to load due to insufficient RAM, but it's NOT fatal.
for(int i=0; i<50; i++) {
// Rather than reader.drawBMP() (which works from SD card),
// a different function is used for RAM-resident images:
img.draw(tft, // Pass in tft object
(int16_t)random(-img.width() , tft.width()) , // Horiz pos.
(int16_t)random(-img.height(), tft.height())); // Vert pos
// Reiterating a prior point: img.draw() does nothing and returns
// if the image failed to load. It's unfortunate but not disastrous.
}
delay(1000); // Pause 2 sec.
}
}
Now I want to show video direct on the TFT and not use SD. How to do that?