I feel so stupid asking this question... but here I am:
I have the Romeo V1.1 All in one Controller and it has 5 built-in buttons (s1-s5). I know at the beginning of my sketch i have to say something like
int key_s4 = [number];
but how do i know what integer to assign to it??
thanks for helping a noob.
Wouldn't worry about it - none of us knew until we found out. Some people even worked it out, the majority of us asked or were told.
It looks quite similar to the button setup that you can find on many 1602 LCD shields. In that setup, You just use 1 pin to handle all 5 buttons - at the expense that
only 1 of them can be pressed at a time. On my display shield, it's analog pin zero - pin A0.
By using a voltage divider, each button just connects a resistor of a different value to a single fixed value one - so 6 resistors. You then get an analog voltage that corresponds to
the pressed button. The range of the ADC is 10 bits, so values will fall in the range [0..1023]. If I divide the value I get from an analogRead on pin A0 by 10, I get a number in the
range [0..10] - on my shield, 10 (1023) is the value returned when no buttons are pressed. I Just read from pin A0 in loop() and printed the result to the serial port.
This told me what the expected values are for each of the buttons.
There's a schematic here: http://www.dfrobot.com/image/data/DFR0004/RoMeo_Schematic_V1.pdf
though this is for a 7 button variant. I do notice however, that the 'extra' two buttons have a dedicated (digital) i/o line each. - I also notice that it appears to indicate that pin A7 reads buttons
S1 - S5 and that D2 and D3 correspond to S6 and S7 (In squares B4,B5 and B6 of the pdf I linked)
I've only had the boards for a month or two, you'll pick it up in no time - MAKE SURE YOU KEEP GOOD NOTES!!! It's all to easy to forget which add-on ebay module needs which pins and
resistors to both work and perhaps more importantly, keep the magic smoke from escaping. Arduino shields don't generally present the same problem, though at times they can 'hog'
pins that would be useful for other things. I can't hook-up SPI or I2C if I plug the lcd shield I have into the arduino, for example. So, I just breadboard it and get access to all of the pins.
The ProMini is smaler than my thumb and doesn't exactly plug in, so again more bread-boarding.
Okay, I tried to do that: "read from pin A0 in loop() and print the result to the serial port"
my sketch was:
int key_pin = A0;
int val;
void setup(){
val = analogRead(key_pin);
Serial.begin(9600);
Serial.println("working");
}
void loop(){
Serial.println(val);
delay(1000);
}
i just got "492" over and over and the number didn't change when i pressed the buttons. I tried reading from pin A1 and also using "digitalRead" instead and same result.
thank you for all of your help, if you have time to reply to this
You are welcome. Please remember to post link to your hardware and not have everyone else search for it. There are so many arduino components that no a single person knows everything, or even a few percent of what's out there. Also if you build a circuit and it doesn't work, post hi-res pictures of the circuit so that someone else can trace every single wire you placed and help you.