Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Button problem
#11
From, your code I can see that you are reading the analog pin A4 for the buttons.

Code:
adc_key_in = analogRead(A4);      // read the value from the sensor

This cannot work as the key pin for the DFRobot shield is A0 (once again - check the official documentation for the DFRobot shield (the link you sent in your first post).

Your back-light pin is also wrong. you are using digital 9 and the correct one is digital 10.

Cheers,
Airic
Reply
#12
I am not an expert in programming.
In my version of ther code miniE
Code:
// Convert ADC value to key number
// ======================================================================================
int lcd_get_key(unsigned int input) {
  
  if (input < key_0_val) {
    return 0;
  } else if (input < key_1_val) {
    return 1;          
  } else if (input < key_2_val) {
    return 2;  
  } else if (input < key_3_val) {
    return 3;  
  } else if (input < key_4_val) {
    return 4;  
  } else {
    return KEY_NONE;    
  }
}

I don't see as "input" calculated

(06-30-2014, 02:16 PM)Airic Lenz Wrote: From, your code I can see that you are reading the analog pin A4 for the buttons.

Code:
adc_key_in = analogRead(A4);      // read the value from the sensor

This cannot work as the key pin for the DFRobot shield is A0 (once again - check the official documentation for the DFRobot shield (the link you sent in your first post).

Your back-light pin is also wrong. you are using digital 9 and the correct one is digital 10.

Cheers,
Airic
Sorry, I didn't see your message.
I use only the scheme of the DFRobot shield and my pin-mapping for Arduino Nano.
Reply
#13
Sorry but because I don't know you custom shield and your custom code (why did you re-implement anything?), I cannot help you.

Cheers,
Airic
Reply
#14
I connected mine shield as original DFRobot shield to Arduino Uno.
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
Back-light pin is digital 10.
adc_key_in = analogRead(A0);

The example from a DFRobot site works, but with the miniE code doesn't work.
Sorry, but the brain blows up Sad
Reply
#15
(06-30-2014, 03:05 PM)vvadim Wrote: I connected mine shield as original DFRobot shield to Arduino Uno.
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
Back-light pin is digital 10.
adc_key_in = analogRead(A0);

The example from a DFRobot site works, but with the miniE code doesn't work.
Sorry, but the brain blows up Sad

did you update the button calibration as well as I suggested earlier?
/Airic
Reply
#16
I tried

#define key_0_val 70
#define key_1_val 237
#define key_2_val 418
#define key_3_val 624
#define key_4_val 1023

and

#define key_0_val 50
#define key_1_val 250
#define key_2_val 450
#define key_3_val 650
#define key_4_val 850

Buttons don't react
Reply
#17
I made experiment.
I allocated from the code miniE only the part connected with buttons and I bring their indications to the lcd.
It works!
Strange that with a full code doesn't want to work?
Code:
#include <LiquidCrystal.h>
#define LCD_BACKLIGHT_PIN   10
#define LCD_KEY_PIN         A0  
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);

#define  KEY_NONE            255
#define  KEY_RIGHT           0
#define  KEY_UP              1
#define  KEY_DOWN            2
#define  KEY_LEFT            3
#define  KEY_SELECT          4
#define  KEY_MENU            5

#define  key_0_val           50    
#define  key_1_val           200  
#define  key_2_val           400  
#define  key_3_val           600  
#define  key_4_val           800  

byte lcd_key;
byte key = KEY_NONE;
int analogValue;

int lcd_key_pressed() {

  analogValue = analogRead(LCD_KEY_PIN);
  delay(4);
  if (5 < abs(analogRead(LCD_KEY_PIN) - analogValue)) {
    return KEY_NONE;
  }
  key = lcd_get_key(analogValue);
}

int lcd_get_key(unsigned int input) {

  if (input < key_0_val) {
    return 0;
  }
  else if (input < key_1_val) {
    return 1;          
  }
  else if (input < key_2_val) {
    return 2;  
  }
  else if (input < key_3_val) {
    return 3;  
  }
  else if (input < key_4_val) {
    return 4;  
  }
  else {
    return KEY_NONE;    
  }
}

void setup() {
  lcd.begin(16, 2);
  lcd.clear();
}

void loop() {
  analogWrite(LCD_BACKLIGHT_PIN, 150);
  
  lcd.setCursor(5,0);
  
  lcd_key = lcd_key_pressed();  

  if (lcd_key == KEY_NONE) {
    lcd.print("NONE  ");
  }
  if (lcd_key == KEY_RIGHT) {
    lcd.print("RIGHT ");
  }
  if (lcd_key == KEY_UP) {
    lcd.print("UP    ");
  }
  if (lcd_key == KEY_DOWN) {  
    lcd.print("DOWN  ");
  }
  if (lcd_key == KEY_LEFT) {
    lcd.print("LEFT   ");
  }
  if (lcd_key == KEY_SELECT) {
    lcd.print("SELECT");
  }
}
Reply
#18
(06-30-2014, 07:29 PM)vvadim Wrote: ...Strange that with a full code doesn't want to work?

If I understood correctly, then you implemented your own solution or at least changed the code. As it is working for all the other users, I guess that might be the issue.

Which parts of the code did you change?

/Airic
Reply
#19
I took only that part of a code from miniE which works with buttons
miniE.ino - initiation of the buttons and lcd (without changes)
mE_keys.ino - deleted single press detected and long-key-press
mE_ui.ino -void key_action(int key) and removed pressing of buttons to display .
Work.
Reply
#20
(07-01-2014, 03:12 PM)vvadim Wrote: I took only that part of a code from miniE which works with buttons
miniE.ino - initiation of the buttons and lcd (without changes)
mE_keys.ino - deleted single press detected and long-key-press
mE_ui.ino -void key_action(int key) and removed pressing of buttons to display .
Work.

Ok, you just took the code that handles the key-presses and implemented all the other things yourself?

Also, why did you delete the code for detecting single and long presses?

Sorry but now I am confused.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)