Start adding LEDs

This commit is contained in:
Matt McWilliams 2023-03-26 16:06:08 -04:00
parent 1528dec668
commit 461add1cda
1 changed files with 13 additions and 22 deletions

View File

@ -16,7 +16,6 @@
#include "CanonBLERemote.h" #include "CanonBLERemote.h"
#include <Arduino.h> #include <Arduino.h>
#include "TickTwo.h"
#include "McopySerial.h" #include "McopySerial.h"
#define LOG_LOCAL_LEVEL ESP_LOG_INFO #define LOG_LOCAL_LEVEL ESP_LOG_INFO
@ -25,14 +24,15 @@
#define SHUTTTER_BTN 12 #define SHUTTTER_BTN 12
#define RELAY_PIN 14 #define RELAY_PIN 14
#define LED 22 #define RED_LED 23
#define GREEN_LED 22
void blink(); void blink();
volatile bool ledState; volatile bool greenLEDstate;
const String name_remote = "mcopy"; const String name_remote = "mcopy";
CanonBLERemote canon_ble(name_remote); CanonBLERemote canon_ble(name_remote);
TickTwo blinker(blink, 500);
McopySerial mc; McopySerial mc;
volatile boolean connected = false; volatile boolean connected = false;
@ -43,8 +43,8 @@ volatile long last = -1;
volatile byte cmd; volatile byte cmd;
void blink(){ void blink(){
digitalWrite(LED, ledState); digitalWrite(GREEN_LED, greenLEDstate);
ledState = !ledState; greenLEDstate = !greenLEDstate;
} }
void setup() void setup()
@ -52,13 +52,13 @@ void setup()
esp_log_level_set("*", ESP_LOG_INFO); esp_log_level_set("*", ESP_LOG_INFO);
pinMode(SHUTTTER_BTN, INPUT_PULLUP); pinMode(SHUTTTER_BTN, INPUT_PULLUP);
pinMode(LED, OUTPUT); pinMode(GREEN_LED, OUTPUT);
mc.begin();
mc.begin(mc.CAMERA_IDENTIFIER);
digitalWrite(GREEN_LED, HIGH);
canon_ble.init(); canon_ble.init();
delay(1000); delay(1000);
blinker.start();
} }
void connectBLE () { void connectBLE () {
@ -68,10 +68,8 @@ void connectBLE () {
while(!canon_ble.pair(10)); while(!canon_ble.pair(10));
connected = true; connected = true;
blinker.pause();
blinker.interval(100);
digitalWrite(LED, HIGH); digitalWrite(GREEN_LED, HIGH);
delay(1000); delay(1000);
mc.log("Camera paired"); mc.log("Camera paired");
@ -92,27 +90,20 @@ void loop()
shutter(); shutter();
} }
blinker.update();
if (connected && !canon_ble.isConnected()) { if (connected && !canon_ble.isConnected()) {
connected = false; connected = false;
//mc.log("Disconnected");
blinker.interval(500);
blinker.resume();
} }
} }
void shutter () { void shutter () {
digitalWrite(LED, LOW); digitalWrite(GREEN_LED, LOW);
blinker.resume();
mc.log("Shutter pressed"); mc.log("Shutter pressed");
if(!canon_ble.trigger()){ if(!canon_ble.trigger()){
mc.log("Trigger Failed"); mc.log("Trigger Failed");
} }
blinker.pause(); digitalWrite(GREEN_LED, HIGH);
digitalWrite(LED, HIGH);
last = millis(); last = millis();
mc.confirm(mc.CAMERA); mc.confirm(mc.CAMERA);
} }