rlogiacco / AnalogButtons

Arduino library to wire multiple buttons to one single analog pin
GNU Lesser General Public License v3.0
57 stars 14 forks source link

AnalogButtons for ESP32 #12

Open dikkehenk opened 5 years ago

dikkehenk commented 5 years ago

Hi Roberto, I already sent you an email (you answered). I am trying to use the AnalogButtons library with the ESP32 board (DOIT devkit 1) but I cannot get a result. I can read the analog values of the different buttons (3) but I cannot get the library to function. I have already used the library with an Arduino Leonardo and the code works perfect.

I am using 3 buttons which give values: 161 - 164 490 - 494 1808 - 1818

I also changed the debounce value 5 - 500

so far no results yet

regards Henk

pierrotm777 commented 5 years ago

Sorry, I am not Roberto. Please check the good mail.

Le mer. 8 mai 2019 à 14:59, dikkehenk notifications@github.com a écrit :

Hi Roberto, I already sent you an email (you answered). I am trying to use the AnalogButtons library with the ESP32 board (DOIT devkit 1) but I cannot get a result. I can read the analog values of the different buttons (3) but I cannot get the library to function. I have already used the library with an Arduino Leonardo and the code works perfect.

I am using 3 buttons which give values: 161 - 164 490 - 494 1808 - 1818

I also changed the debounce value 5 - 500

so far no results yet

regards Henk

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/rlogiacco/AnalogButtons/issues/12, or mute the thread https://github.com/notifications/unsubscribe-auth/AB6PQESN646TMLDFJ2QIEGTPULFD3ANCNFSM4HLRPGXA .

rlogiacco commented 5 years ago

Sorry, I am not Roberto. Please check the good mail. @pierrotm777 you received an email because you are watching this project: Henk didn't write an email directly to you

rlogiacco commented 5 years ago

I already sent you an email (you answered). I am trying to use the AnalogButtons library with the ESP32 board (DOIT devkit 1) but I cannot get a result.

I can read the analog values of the different buttons (3) but I cannot get the library to function. I have already used the library with an Arduino Leonardo and the code works perfect.

I am using 3 buttons which give values: 161 - 164 490 - 494 1808 - 1818

I also changed the debounce value 5 - 500 so far no results yet

Can you post your code, please?

dikkehenk commented 5 years ago

Hi,

With this code I am collecting presses from 2 x 3 buttons and convert them into RS232/Lanc double HEX commands (to control a camera) (for ESP testing purposses I have disconnected the Iris buttons and comented out the Iris buttons Tick functions. I have also commented out the functions for the RS232/Lanc commands so I could solely test the Analog Button Library. I am writing the double RS232/Lanc Hex commands to the serial monitor to check if the conversion works)

The code (library) works brilliantly for an Arduino Leonardo.

Henk

code for ESP32


include

define FOCUS_PIN 34 //pin 34 has no internal PULL_UP/DOWN: use external

define IRIS_PIN 35 //pin 35 has no internal PULL_UP/DOWN: use external

byte CmdRow; //byte CmdRow is used to parse the calculated row number

const byte LANCmds[24][2] = { // LANC Zoomspeed Tele commands: { 0x28, 0x00 }, // Row 0 - Zoom Tele0 slowest Tele { 0x28, 0x02 }, // Row 1 - Zoom Tele1 { 0x28, 0x04 }, // Row 2 - Zoom Tele2 { 0x28, 0x06 }, // Row 3 - Zoom Tele3 { 0x28, 0x08 }, // Row 4 - Zoom Tele4 { 0x28, 0x0A }, // Row 5 - Zoom Tele5 { 0x28, 0x0C }, // Row 6 - Zoom Tele6 { 0x28, 0x0E }, // Row 7 - Zoom Tele7 fastest Tele //LANC Zoomspeed Wide commands: { 0x28, 0x10 }, // Row 8 - Zoom Wide0 slowest Wide { 0x28, 0x12 }, // Row 9 - Zoom Wide1 { 0x28, 0x14 }, // Row 10 - Zoom Wide2 { 0x28, 0x16 }, // Row 11 - Zoom Wide3 { 0x28, 0x18 }, // Row 12 - Zoom Wide4 { 0x28, 0x1A }, // Row 13 - Zoom Wide5 { 0x28, 0x1C }, // Row 14 - Zoom Wide6 { 0x28, 0x1E }, // Row 15 - Zoom Wide7 fastest Wide // LANC Focus Nudge-Near/Nudge-Far/Auto commands: { 0x28, 0x45 }, // Row 16 - Focus Near(nudge) { 0x28, 0x47 }, // Row 17 - Focus Far(nudge) { 0X28, 0x41 }, // Row 18 - Focus Auto // LANC Iris Nudge-Near/Nudge-Far/Auto commands: { 0x28, 0x53 }, // Row 19 - Iris -(nudge) { 0x28, 0x55 }, // Row 20 - Iris +(nudge) { 0x28, 0xAF }, // Row 21 - Iris Auto // LANC misc. { 0x18, 0x33 }, // Row 22 START/STOP { 0x18, 0xBC }, // Row 23 STANDBY };

AnalogButtons FcusButtons(FOCUS_PIN, 50); //Analog PIN A1, debounce 3 ms (still fiddle with the debounce) Button FcsPls = Button(160, &fcsPlsNdg, &fcsPlsRpt,500,100); // Repeats after 500ms, 100ms repeat interval Button FcsMin = Button(490, &fcsMinNdg, &fcsMinRpt,500,100); // Repeats after 500ms, 100ms repeat interval Button FcsAut = Button(1808, &fcsAuto,&fcsAuto,5000,5000); // No repeat (toggle) Repeat wait & interval are set very long

AnalogButtons IrisButtons(IRIS_PIN, 20); //Analog PIN A2, debounce 3 ms (still fiddle with the debounce) Button IrsPls = Button(170, &irsPlsNdg, &irsPlsRpt,500,100); Button IrsMin = Button(500, &irsMinNdg, &irsMinRpt,500,100); Button IrsAut = Button(1808, &irsAuto, &irsAuto,5000,5000); // No repeat (toggle) Repeat wait & interval are set very long

//HardwareSerial ELM624serial(1); //has been improved in ESP32-HardwareSerial-library no need to declare, just use Serial1, Serial2

void setup() { pinMode(FOCUS_PIN, INPUT); // pinMode(IRIS_PIN, INPUT); Serial.begin(115200); //ELM624serial.begin(9600,SERIAL_8N1,16,17); //ELMserial auf Pin 16 und 17 //Serial1.begin(9600,SERIAL_8N1,16,17); //Serial1 auf Pin 16(RX) und 17(TX)

FcusButtons.add(FcsPls); FcusButtons.add(FcsMin); FcusButtons.add(FcsAut);

IrisButtons.add(IrsPls); IrisButtons.add(IrsMin); IrisButtons.add(IrsAut);

//InitELM624(); // Call the ELM624 init function }

void loop() {
// To check values when Iris- & Focus buttons are pressed FcusButtons.check(); // IrisButtons.check(); // delay(200); // configure(); }

void configure() { unsigned int value = analogRead(FOCUS_PIN); Serial.println(value); delay(250); }

//Callback functions that you pass into the constructor of AnalogButtons void fcsPlsNdg() { Serial.print("Focus+Nudge\t"); CmdRow = 16; SndLANCmd(CmdRow);} void fcsPlsRpt() { Serial.print("Focus+Repeat\t"); CmdRow = 16; SndLANCmd(CmdRow);} void fcsMinNdg() { Serial.print("Focus-Nudge\t"); CmdRow = 17; SndLANCmd(CmdRow);} void fcsMinRpt() { Serial.print("Focus-Repeat\t"); CmdRow = 17; SndLANCmd(CmdRow);} void fcsAuto() { Serial.print("Focus-Auto\t"); CmdRow = 18; SndLANCmd(CmdRow);}

void irsPlsNdg() { Serial.print("Iris+Nudge\t"); CmdRow = 19; SndLANCmd(CmdRow);} void irsPlsRpt() { Serial.print("Iris+Repeat\t"); CmdRow = 19; SndLANCmd(CmdRow);} void irsMinNdg() { Serial.print("Iris-Nudge\t"); CmdRow = 20; SndLANCmd(CmdRow);} void irsMinRpt() { Serial.print("Iris-Repeat\t"); CmdRow = 20; SndLANCmd(CmdRow);} void irsAuto() { Serial.print("Iris-Auto\t"); CmdRow = 21; SndLANCmd(CmdRow);}

/--------------------------------------------------------------------------- Function: send LANC command to the ELM624(LANC chip) + ">" handshake -----------------------------------------------------------------------------/ void SndLANCmd(byte CmdRow) { // Leading Handshake //if(ELM624serial.find(">")) //Find the '>' character as response //if(Serial1.find(">")) //Find the '>' character as response //{ //If '>' found send the actual command line to the device //while(ELM624Serial.available()) ELM624Serial.read(); //Clear ELM624serial.IN buffer for next handshake (">"char) //while(Serial1.available()) Serial1.read(); //Clear Serial1.IN buffer for next handshake (">"char) //{

Serial.print (CmdRow); //temp debug
Serial.print('\t');    //temp debug  

   for (int i = 0; i < 2; i++)                                //loop 2 times for the 2 byte command row
     {
      //ELM624serial.print((const byte) LANCmds[CmdRow][i],HEX); //Send the actual variable LANC command to the ELM624
      //Serial1.print((const byte) LANCmds[CmdRow][i],HEX);     //Send the actual variable LANC command to the ELM624
      Serial.print((const byte) LANCmds[CmdRow][i],HEX);     // Print the 2 byte command to the serial monitor (one Hex byte at the time)
     }                                                       // both print terminations not ready yet
//ELM624serial.write("\r");// terminate the command: the ELM624 only needs a cariage return: "\r"
//Serial1.print("\r"); // terminate the command: the ELM624 only needs a cariage return: "\r"
Serial.print("\r\n"); // terminate the command to the serial monitor

// Trailing Handshake -prefered for now- //if(ELM624serial.find(">")) //Wait for the '>' character as handshake //if(Seria1l.find(">")) //Wait for the '>' character as handshake //{
// while(ELM624serial.available()) ELM624serial.read(); // Clear ELM624serial.IN buffer for next handshake (">"char) // while(Serial1.available()) Serial1.read(); // Clear Serial1.IN buffer for next handshake (">"char) //} // ">" char has not been found "LANC error" } // end SndLANCmd

rlogiacco commented 5 years ago

Henk, I understand you are new to Github: in the future, can you please avoid using the email reply and edit your answers here on github using the proper markdown? That will allow, among other, to use proper code formatting which makes my life much easier.

For now I'm copy/pasting to ease my task:

#include <AnalogButtons.h>
#define FOCUS_PIN 34 //pin 34 has no internal PULL_UP/DOWN: use external
#define IRIS_PIN 35 //pin 35 has no internal PULL_UP/DOWN: use external

byte CmdRow; //byte CmdRow is used to parse the calculated row number

const byte LANCmds[24][2] = {
// LANC Zoomspeed Tele commands:
{ 0x28, 0x00 }, // Row 0 - Zoom Tele0 slowest Tele
{ 0x28, 0x02 }, // Row 1 - Zoom Tele1
{ 0x28, 0x04 }, // Row 2 - Zoom Tele2
{ 0x28, 0x06 }, // Row 3 - Zoom Tele3
{ 0x28, 0x08 }, // Row 4 - Zoom Tele4
{ 0x28, 0x0A }, // Row 5 - Zoom Tele5
{ 0x28, 0x0C }, // Row 6 - Zoom Tele6
{ 0x28, 0x0E }, // Row 7 - Zoom Tele7 fastest Tele
//LANC Zoomspeed Wide commands:
{ 0x28, 0x10 }, // Row 8 - Zoom Wide0 slowest Wide
{ 0x28, 0x12 }, // Row 9 - Zoom Wide1
{ 0x28, 0x14 }, // Row 10 - Zoom Wide2
{ 0x28, 0x16 }, // Row 11 - Zoom Wide3
{ 0x28, 0x18 }, // Row 12 - Zoom Wide4
{ 0x28, 0x1A }, // Row 13 - Zoom Wide5
{ 0x28, 0x1C }, // Row 14 - Zoom Wide6
{ 0x28, 0x1E }, // Row 15 - Zoom Wide7 fastest Wide
// LANC Focus Nudge-Near/Nudge-Far/Auto commands:
{ 0x28, 0x45 }, // Row 16 - Focus Near(nudge)
{ 0x28, 0x47 }, // Row 17 - Focus Far(nudge)
{ 0X28, 0x41 }, // Row 18 - Focus Auto
// LANC Iris Nudge-Near/Nudge-Far/Auto commands:
{ 0x28, 0x53 }, // Row 19 - Iris -(nudge)
{ 0x28, 0x55 }, // Row 20 - Iris +(nudge)
{ 0x28, 0xAF }, // Row 21 - Iris Auto
// LANC misc.
{ 0x18, 0x33 }, // Row 22 START/STOP
{ 0x18, 0xBC }, // Row 23 STANDBY
};

AnalogButtons FcusButtons(FOCUS_PIN, 50); //Analog PIN A1, debounce 3 ms (still fiddle with the debounce)
Button FcsPls = Button(160, &fcsPlsNdg, &fcsPlsRpt,500,100); // Repeats after 500ms, 100ms repeat interval
Button FcsMin = Button(490, &fcsMinNdg, &fcsMinRpt,500,100); // Repeats after 500ms, 100ms repeat interval
Button FcsAut = Button(1808, &fcsAuto,&fcsAuto,5000,5000); // No repeat (toggle) Repeat wait & interval are set very long

AnalogButtons IrisButtons(IRIS_PIN, 20); //Analog PIN A2, debounce 3 ms (still fiddle with the debounce)
Button IrsPls = Button(170, &irsPlsNdg, &irsPlsRpt,500,100);
Button IrsMin = Button(500, &irsMinNdg, &irsMinRpt,500,100);
Button IrsAut = Button(1808, &irsAuto, &irsAuto,5000,5000); // No repeat (toggle) Repeat wait & interval are set very long

//HardwareSerial ELM624serial(1); //has been improved in ESP32-HardwareSerial-library no need to declare, just use Serial1, Serial2

void setup()
{
pinMode(FOCUS_PIN, INPUT);
// pinMode(IRIS_PIN, INPUT);
Serial.begin(115200);
//ELM624serial.begin(9600,SERIAL_8N1,16,17); //ELMserial auf Pin 16 und 17
//Serial1.begin(9600,SERIAL_8N1,16,17); //Serial1 auf Pin 16(RX) und 17(TX)

FcusButtons.add(FcsPls);
FcusButtons.add(FcsMin);
FcusButtons.add(FcsAut);

IrisButtons.add(IrsPls);
IrisButtons.add(IrsMin);
IrisButtons.add(IrsAut);

//InitELM624(); // Call the ELM624 init function
}

void loop()
{
// To check values when Iris- & Focus buttons are pressed
FcusButtons.check();
// IrisButtons.check();
// delay(200);
// configure();
}

void configure() {
unsigned int value = analogRead(FOCUS_PIN);
Serial.println(value);
delay(250);
}

//Callback functions that you pass into the constructor of AnalogButtons
void fcsPlsNdg() { Serial.print("Focus+Nudge\t"); CmdRow = 16; SndLANCmd(CmdRow);}
void fcsPlsRpt() { Serial.print("Focus+Repeat\t"); CmdRow = 16; SndLANCmd(CmdRow);}
void fcsMinNdg() { Serial.print("Focus-Nudge\t"); CmdRow = 17; SndLANCmd(CmdRow);}
void fcsMinRpt() { Serial.print("Focus-Repeat\t"); CmdRow = 17; SndLANCmd(CmdRow);}
void fcsAuto() { Serial.print("Focus-Auto\t"); CmdRow = 18; SndLANCmd(CmdRow);}

void irsPlsNdg() { Serial.print("Iris+Nudge\t"); CmdRow = 19; SndLANCmd(CmdRow);}
void irsPlsRpt() { Serial.print("Iris+Repeat\t"); CmdRow = 19; SndLANCmd(CmdRow);}
void irsMinNdg() { Serial.print("Iris-Nudge\t"); CmdRow = 20; SndLANCmd(CmdRow);}
void irsMinRpt() { Serial.print("Iris-Repeat\t"); CmdRow = 20; SndLANCmd(CmdRow);}
void irsAuto() { Serial.print("Iris-Auto\t"); CmdRow = 21; SndLANCmd(CmdRow);}

/*---------------------------------------------------------------------------
Function: send LANC command to the ELM624(LANC chip) + ">" handshake
-----------------------------------------------------------------------------*/
void SndLANCmd(byte CmdRow)
{
//**** Leading Handshake ****
//if(ELM624serial.find(">")) //Find the '>' character as response
//if(Serial1.find(">")) //Find the '>' character as response
//{ //If '>' found send the actual command line to the device
//while(ELM624Serial.available()) ELM624Serial.read(); //Clear ELM624serial.IN buffer for next handshake (">"char)
//while(Serial1.available()) Serial1.read(); //Clear Serial1.IN buffer for next handshake (">"char)
//{

Serial.print (CmdRow); //temp debug
Serial.print('\t'); //temp debug

for (int i = 0; i < 2; i++) //loop 2 times for the 2 byte command row
{
//ELM624serial.print((const byte) LANCmds[CmdRow][i],HEX); //Send the actual variable LANC command to the ELM624
//Serial1.print((const byte) LANCmds[CmdRow][i],HEX); //Send the actual variable LANC command to the ELM624
Serial.print((const byte) LANCmds[CmdRow][i],HEX); // Print the 2 byte command to the serial monitor (one Hex byte at the time)
} // both print terminations not ready yet
//ELM624serial.write("\r");// terminate the command: the ELM624 only needs a cariage return: "\r"
//Serial1.print("\r"); // terminate the command: the ELM624 only needs a cariage return: "\r"
Serial.print("\r\n"); // terminate the command to the serial monitor

//**** Trailing Handshake **** -prefered for now-
//if(ELM624serial.find(">")) //Wait for the '>' character as handshake
//if(Seria1l.find(">")) //Wait for the '>' character as handshake
//{
// while(ELM624serial.available()) ELM624serial.read(); // Clear ELM624serial.IN buffer for next handshake (">"char)
// while(Serial1.available()) Serial1.read(); // Clear Serial1.IN buffer for next handshake (">"char)
//}
// ">" char has not been found "LANC error"
} // end SndLANCmd
dikkehenk commented 5 years ago

Roberto, Sorry I tried to set up an issue on Github but then I got a reply from pierrotm777 https://github.com/pierrotm777 that he is not Roberto.

** Sorry, I am not Roberto. Please check the good mail.

Le mer. 8 mai 2019 à 14:59, dikkehenk notifications@github.com a écrit : **

I will try again

Henk

rlogiacco commented 5 years ago

Henk, your issue is correctly open on Github, you guys are mixing up personal emails with github notification emails

https://github.com/rlogiacco/AnalogButtons/issues/12