77*/
88
99#include < Arduino_OV767X.h>
10-
11- #define BUTTON_PIN 13
10+ #include < TinyMLShield.h>
1211
1312bool commandRecv = false ; // flag used for indicating receipt of commands from serial port
1413bool liveFlag = false ; // flag as true to live stream raw camera bytes, set as false to take single images on command
1514bool captureFlag = false ;
1615
17- // Variables for button debouncing
18- unsigned long lastDebounceTime = 0 ;
19- unsigned long debounceDelay = 50 ;
20- bool lastButtonState = HIGH;
21- bool buttonState;
22-
2316// Image buffer;
2417byte image[176 * 144 * 2 ]; // QCIF: 176x144 x 2 bytes per pixel (RGB565)
2518int bytesPerFrame;
@@ -28,9 +21,7 @@ void setup() {
2821 Serial.begin (9600 );
2922 while (!Serial);
3023
31- pinMode (BUTTON_PIN, OUTPUT);
32- digitalWrite (BUTTON_PIN, HIGH);
33- nrf_gpio_cfg_out_with_input (digitalPinToPinName (BUTTON_PIN));
24+ initializeShield ();
3425
3526 // Initialize camera
3627 if (!Camera.begin (QCIF, RGB565, 1 )) {
@@ -50,28 +41,15 @@ void loop() {
5041 int i = 0 ;
5142 String command;
5243
53- bool buttonRead = nrf_gpio_pin_read (digitalPinToPinName (BUTTON_PIN));
54-
55- if (buttonRead != lastButtonState) {
56- lastDebounceTime = millis ();
57- }
58-
59- if (millis () - lastDebounceTime >= debounceDelay) {
60- if (buttonRead != buttonState) {
61- buttonState = buttonRead;
62-
63- if (!buttonState) {
64- if (!liveFlag) {
65- if (!captureFlag) {
66- captureFlag = true ;
67- }
68- }
44+ bool clicked = readShieldButton ();
45+ if (clicked) {
46+ if (!liveFlag) {
47+ if (!captureFlag) {
48+ captureFlag = true ;
6949 }
7050 }
7151 }
7252
73- lastButtonState = buttonRead;
74-
7553 // Read incoming commands from serial monitor
7654 while (Serial.available ()) {
7755 char c = Serial.read ();
@@ -132,14 +110,4 @@ void loop() {
132110 Serial.println ();
133111 }
134112 }
135- }
136-
137- void nrf_gpio_cfg_out_with_input (uint32_t pin_number) {
138- nrf_gpio_cfg (
139- pin_number,
140- NRF_GPIO_PIN_DIR_OUTPUT,
141- NRF_GPIO_PIN_INPUT_CONNECT,
142- NRF_GPIO_PIN_PULLUP,
143- NRF_GPIO_PIN_S0S1,
144- NRF_GPIO_PIN_NOSENSE);
145- }
113+ }
0 commit comments