I have a touch screen. I have a menu and sub menu that works well.
The arduino and the screen are integrated in a montage very difficult to open.
The touch screen can be touch via a window.
If later the screen is no longer touch, I would use 2 buttons to use the menus.
The first makes a choice and the second validates the choice.
I do not know how I could do it.
I think there should be a pin for each button and maybe a pull-up or pull-down .
As the reset button is not accessible either, I would like that pressing both buttons at the same time, it does the same as pressing the reset button.
I think there must be a logic IC to be added to do this function, but again I'm ignorant.
padouet:
If later the screen is no longer touch, I would use 2 buttons to use the menus.
The first makes a choice and the second validates the choice.
I do not know how I could do it.
I think there should be a pin for each button and maybe a pull-up or pull-down .
int selecPin = 7; // choose the input pin (for a select pushbutton)
int validPin = 8; // choose the input pin (for a validate pushbutton)
int selec = 0; // variable for reading the pin 7 status
int valid = 0; // variable for reading the pin 8 status
void setup() {
pinMode(selecPin, INPUT); // declare select pushbutton as input
pinMode(validPin, INPUT); // declare validate pushbutton as input
}
void loop(){
selec = digitalRead(selecPin); // read input value
if (selec == HIGH) { // check if the input is HIGH - pressed
//
} else {
//
}
selec = digitalRead(validPin); // read input value
if (valid == HIGH) { // check if the input is HIGH - pressed
//
} else {
//
}
}
padouet:
As the reset button is not accessible either, I would like that pressing both buttons at the same time, it does the same as pressing the reset button.
I think there must be a logic IC to be added to do this function, but again I'm ignorant.
It's better to write your code so that you never need to reset but there is a way to reset the Arduino via your code. For your purposes it should work as well as a hardware reset. It's called a watchdog reset. The microcontroller has a watchdog timer (wdt) you can turn on with a configurable timeout duration. If that timer isn't reset within the timeout period then it resets the microcontroller. Here's an example sketch:
// WARNING!!! The bootloader used on the Pro Mini and Nano has a bug that causes it to go in to an endless reset loop after a watchdog reset.
// Do not use this code on those boards until you have replaced the bootloader with Optiboot.
// The bootloaders on the Uno and Mega (unless a very old Mega) do not have this bug and will work fine with this code.
#include <avr/wdt.h>
void setup() {
Serial.begin(9600);
Serial.println("starting");
pinMode(2, INPUT_PULLUP);
wdt_enable(WDTO_1S); //enable the watchdog timer with a 1 second timeout duration
}
void loop() {
wdt_reset(); //reset the watchdog timer
while (digitalRead(2) == LOW) {} //if pin 2 is held low for longer than 1 second the microcontroller will reset
}
The benefit of the above code is that if your Arduino freezes it will automatically reset (which is the main purpose of the watchdog timer). This does mean that you need to write your code so that wdt_reset() will always be called within the timeout duration. That should be no problem if you write proper non-blocking code and in fact you could set the timer duration much lower.
If you don't want to have the watchdog on all the time you can use this sort of code, which only enables the watchdog timer when needed for a reset:
// WARNING!!! The bootloader used on the Pro Mini and Nano has a bug that causes it to go in to an endless reset loop after a watchdog reset.
// Do not use this code on those boards until you have replaced the bootloader with Optiboot.
// The bootloaders on the Uno and Mega (unless a very old Mega) do not have this bug and will work fine with this code.
#include <avr/wdt.h>
void setup() {
Serial.begin(9600);
Serial.println("starting");
pinMode(2, INPUT_PULLUP);
}
void loop() {
if (digitalRead(2) == LOW) {
wdt_enable(WDTO_1S); //enable the watchdog timer with a 1 second timeout duration
wdt_reset(); //reset the watchdog timer
while (digitalRead(2) == LOW) {} //if pin 2 is held low for longer than 1 second the microcontroller will reset
wdt_disable();
}
}
Keep in mind that if your Arduino freezes then the reset button handling code will never run and so this version of the code will not help you to recover from that situation.
Thank you every body for your answer and all links.
pert:
It's better to write your code so that you never need to reset but there is a way to reset the Arduino via your code. For your purposes it should work as well as a hardware reset. It's called a watchdog reset. The microcontroller has a watchdog timer (wdt) you can turn on with a configurable timeout duration. If that timer isn't reset within the timeout period then it resets the microcontroller.
Of course, but I am learner in Arduino.
I think my problem is overflow of memory ...
When I press reset button on arduino, nothing happend, I need to unplugg it.
mybrain_iq55:
I undestand he want a physical reset by logical circuit.
maybe with
but I am not sure ...
It is my mind but I do not know how can I do this.
Out is wired to reset pin,
A and B to each button (valid and select), but same wire than pin 7 and pin 8 ?
With Arduino, witch one ? 74HC08 or 4081 or other ? Add some resistor ?