Hi Guys. I decided to have a go at using an Arduino uno. I have an LCD shield with 5 buttons on it. I have had the LCD screen print test messages, but i a m having trouble getting what I want to work. There are 5 buttons on the shield, connected to Analog_0 with various voltage dividers. I have worked out their values. Select, 721 : Left, 479 : Down, 306 : Up,131 : Right,0.
What I wanted to do was to display the button being pressed and have it latch until another button is selected. Here is the code
~~~
; MAIN PROGRAM
WAIT 2 S
set LCDBacklight on
PRINT " PRESS A BUTTON"
Do Forever
BTTNPUSH = READAD12(ANALOG_0)
Select Case BTTNPUSH
Case < 50
CLS
PRINT "RIGHT"
Case > 150 & BTTNPUSH < 350
CLS
PRINT "UP"
Case > 350 & BTTNPUSH < 500
CLS
PRINT "DOWN"
Case > 500 & BTTNPUSH < 700
CLS
PRINT "LEFT"
Case > 700 & BTTNPUSH < 900
CLS
PRINT "SELECT"
End Select
LOOP
~~~
Any Ideas what I am doing wrong?
Thanks.
Marz
edit: Added ~~~ tags to assist code readability
Last edit: Chris Roper 2019-07-22
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
You did not say what the failure is in your code, i.e. what is it doing that is not expected?
As I don't have your hardware setup so I can't test your code myself but two suggestions spring to mind from reading it.
1) What happens if the ADC Reading is > 900? May I suggest you have a Case Else To catch any unexpected values.
2) Take a look at the SCALE() Function it may suit your application better than a Select Case Construct.
Cheers
Chris
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
and, there is a demo that also shows this. Some of the clone LCD will damage your chip. if you do not modify. This information is also in your demo folders.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Thanks everyone for your replies. I did have it with READAD10 at one point but not latching the button push. As usual I didnt think to keep the different iterations of what I did so I could back up to something close to working. Dont know why I changed to READAD12. Probably just a typo that i just kept doing. @mmotte The pin is active high when no button pushed. I did have an else statement to cover that to do nothing, but again It went missing in the constant code changes trying to get it to work. Thanks again everyone.
Marz.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi Guys. I decided to have a go at using an Arduino uno. I have an LCD shield with 5 buttons on it. I have had the LCD screen print test messages, but i a m having trouble getting what I want to work. There are 5 buttons on the shield, connected to Analog_0 with various voltage dividers. I have worked out their values. Select, 721 : Left, 479 : Down, 306 : Up,131 : Right,0.
What I wanted to do was to display the button being pressed and have it latch until another button is selected. Here is the code
~~~
chip mega328P, 16
#option explicit
#include <uno_mega328p.h>
;setup Lcd Parameters
#define LCD_IO 4
#define LCD_NO_RW
#define LCD_Speed SLow
#define LCD_DB4 DIGITAL_4
#define LCD_DB5 DIGITAL_5
#define LCD_DB6 DIGITAL_6
#define LCD_DB7 DIGITAL_7
#define LCD_RS DIGITAL_8
#define LCD_ENABLE DIGITAL_9
#DEFINE LCDBacklight DIGITAL_10
DIM BTTNPUSH AS Word</uno_mega328p.h>
; MAIN PROGRAM
WAIT 2 S
set LCDBacklight on
PRINT " PRESS A BUTTON"
Do Forever
BTTNPUSH = READAD12(ANALOG_0)
Select Case BTTNPUSH
Case < 50
CLS
PRINT "RIGHT"
End Select
LOOP
~~~
Any Ideas what I am doing wrong?
Thanks.
Marz
edit: Added ~~~ tags to assist code readability
Last edit: Chris Roper 2019-07-22
You did not say what the failure is in your code, i.e. what is it doing that is not expected?
As I don't have your hardware setup so I can't test your code myself but two suggestions spring to mind from reading it.
1) What happens if the ADC Reading is > 900? May I suggest you have a Case Else To catch any unexpected values.
2) Take a look at the SCALE() Function it may suit your application better than a Select Case Construct.
Cheers
Chris
Marz,
The problem is the READAD12, it should be READAD10.
also I had to edit the ranges slightly. But it works on mine.
BR
Mike
and, there is a demo that also shows this. Some of the clone LCD will damage your chip. if you do not modify. This information is also in your demo folders.
Thanks everyone for your replies. I did have it with READAD10 at one point but not latching the button push. As usual I didnt think to keep the different iterations of what I did so I could back up to something close to working. Dont know why I changed to READAD12. Probably just a typo that i just kept doing. @mmotte The pin is active high when no button pushed. I did have an else statement to cover that to do nothing, but again It went missing in the constant code changes trying to get it to work. Thanks again everyone.
Marz.