firmware.ino 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #include <esp_camera.h>
  2. #include "camera_model.h"
  3. #include "initialize.h"
  4. #include "process_image.h"
  5. #include "serial_commands.h"
  6. camera_config_t config;
  7. // Entry point of the program.
  8. void setup() {
  9. // Set up the camera model.
  10. CameraModel* model = CameraModel::getInstance();
  11. // Set up the model defaults.
  12. model->setIsDitheringDisabled(false);
  13. model->setIsInverted(false);
  14. model->setIsFlashEnabled(false);
  15. model->setIsStreamEnabled(true);
  16. model->setDitherAlgorithm(FLOYD_STEINBERG);
  17. // Set initial camera configurations for grayscale.
  18. config.ledc_channel = LEDC_CHANNEL_0;
  19. config.ledc_timer = LEDC_TIMER_0;
  20. config.pin_d0 = Y2_GPIO_NUM;
  21. config.pin_d1 = Y3_GPIO_NUM;
  22. config.pin_d2 = Y4_GPIO_NUM;
  23. config.pin_d3 = Y5_GPIO_NUM;
  24. config.pin_d4 = Y6_GPIO_NUM;
  25. config.pin_d5 = Y7_GPIO_NUM;
  26. config.pin_d6 = Y8_GPIO_NUM;
  27. config.pin_d7 = Y9_GPIO_NUM;
  28. config.pin_xclk = XCLK_GPIO_NUM;
  29. config.pin_pclk = PCLK_GPIO_NUM;
  30. config.pin_vsync = VSYNC_GPIO_NUM;
  31. config.pin_href = HREF_GPIO_NUM;
  32. config.pin_sscb_sda = SIOD_GPIO_NUM;
  33. config.pin_sscb_scl = SIOC_GPIO_NUM;
  34. config.pin_pwdn = PWDN_GPIO_NUM;
  35. config.pin_reset = RESET_GPIO_NUM;
  36. config.xclk_freq_hz = 20000000;
  37. config.pixel_format = PIXFORMAT_GRAYSCALE;
  38. config.frame_size = FRAMESIZE_QQVGA;
  39. config.fb_count = 1;
  40. // Begin serial communication.
  41. Serial.begin(230400); // 115200
  42. // Initialize the camera.
  43. initialize(&config);
  44. }
  45. // Main loop of the program.
  46. void loop() {
  47. // Get the camera model reference.
  48. CameraModel* model = CameraModel::getInstance();
  49. if (model->getIsStreamEnabled()) {
  50. camera_fb_t* frame_buffer = esp_camera_fb_get();
  51. if (frame_buffer) {
  52. process_image(frame_buffer);
  53. // Return the frame buffer back to the camera driver.
  54. esp_camera_fb_return(frame_buffer);
  55. }
  56. delay(25);
  57. }
  58. serial_commands();
  59. }