Author Topic: helpe whit a arduino program to a ROV  (Read 398 times)

0 Members and 1 Guest are viewing this topic.

Offline Edwin the inductorTopic starter

  • Newbie
  • Posts: 6
  • Country: se
helpe whit a arduino program to a ROV
« on: July 09, 2020, 09:32:31 am »
Hello!
I need help. I am working on subwater ROV with one transmitter arduino and one recierver arduino. After a lot of work without getting the two boards to communicate reliably I have decided to use a principle that follows in the end of the text. Now the problem is that if I press a button I get output but when I release the button the output does not end but just continues.

Can somone help me understand what I´m doing wrong?



#include <Button.h>
// create a button objekt for each gpio in use:
Button btn1(48);
Button btn2(50);
Button btn3(52);
void setup() {

// starta buttons:
btn1.begin();
btn2.begin();
btn3.begin();

pinMode (22, OUTPUT);
}

void loop() {
  // if the 2 buttons is presed GPIO 22 goes HIGH:
}
  if (btn1.pressed() && btn2.pressed()){
   
    while(!btn1.released() && !btn2.released()){
   digitalWrite (22,HIGH);
  }
}
//if the 2 buttons is relased GPIO 22 goes LOW:
if (!btn1.pressed() && !btn2.pressed()){
   
    while(btn1.released() && btn2.released()){
   digitalWrite (22,LOW); 
}
 

Offline Manul

  • Super Contributor
  • ***
  • Posts: 1159
  • Country: lt
Re: helpe whit a arduino program to a ROV
« Reply #1 on: July 09, 2020, 02:59:36 pm »
Well, I see some mess with curly brackets. It should not even compile. Also button logic seems to me unnecessary complicated. I do not know how your button library works, but something like that should be possible and is more simple, because you already have a loop provided by arduino environment.

Code: [Select]
void loop() {
  if (btn1.pressed() && btn2.pressed()) {
    digitalWrite (22,HIGH);
  } else {
    digitalWrite (22,LOW);
  }
}
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf