Offline
Newbie
Karma: 0
Posts: 5
|
 |
« on: November 18, 2011, 05:28:39 pm » |
hi guys sorry for stupid question
i have a task, connect to arduino 15 analog buttons, when button is pushed send info to USB
for me is interesting which controller i need to buy and how can i connect so many buttons?
Thank you very much
|
|
|
|
|
Logged
|
|
|
|
|
Massachusetts, USA
Offline
Tesla Member
Karma: 96
Posts: 6331
|
 |
« Reply #1 on: November 18, 2011, 05:50:35 pm » |
Some more detail would be useful. What do you mean by "analog buttons"?
For regular on/off buttons, any Arduino with a USB-to-Serial adapter would do what you ask. The Arduino UNO is the most common,
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Edison Member
Karma: 21
Posts: 1353
Now, More Than Ever
|
 |
« Reply #2 on: November 18, 2011, 05:54:17 pm » |
"Analog buttons"? I assume by that you mean pushbuttons? 74HC165, parallel_in-serial_out shift register, "daisy-chain" two, each switch to '165 input; constantly read the shift register data. Here's a link to someone who "got it" - http://arduino.cc/forum/index.php/topic,10069.0.html
|
|
|
|
|
Logged
|
Don't Be Upset By The Results You Didn't Get With The Work You Didn't Do
|
|
|
|
CO, USA
Offline
God Member
Karma: 4
Posts: 706
|
 |
« Reply #3 on: November 18, 2011, 06:10:07 pm » |
There's also the analog buttons method, which could easily accomodate 15 buttons -- even on 1 analog pin, with careful choice of resistors, I think.
|
|
|
|
|
Logged
|
... it is poor civic hygiene to install technologies that could someday facilitate a police state. -- Bruce Schneier
|
|
|
|
0
Offline
Tesla Member
Karma: 50
Posts: 6526
Arduino rocks
|
 |
« Reply #4 on: November 18, 2011, 07:37:24 pm » |
If the buttons are pushed only one at a time, you could use a multiplexer like below to input a single analog pin. http://www.sparkfun.com/products/299
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
Boston area, metrowest
Offline
Brattain Member
Karma: 240
Posts: 16426
Available for Design & Build services
|
 |
« Reply #5 on: November 18, 2011, 08:04:14 pm » |
If one at a time, can also wire them up like a 4x4 matrix, and connect to just 8 pins using the keypad library, no external hardware needed. http://arduino.cc/playground/Code/Keypad
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Edison Member
Karma: 21
Posts: 1353
Now, More Than Ever
|
 |
« Reply #6 on: November 18, 2011, 08:22:11 pm » |
Oh-ho, Analog buttons -- there you go. So, I guess the only "controller" ilinsky needs is any Arduino, 15 resistors (I guess), and, as far as "sending info to USB" goes, serial.print (and don't press anymore than one button at a time.)
|
|
|
|
|
Logged
|
Don't Be Upset By The Results You Didn't Get With The Work You Didn't Do
|
|
|
|
Global Moderator
Boston area, metrowest
Offline
Brattain Member
Karma: 240
Posts: 16426
Available for Design & Build services
|
 |
« Reply #7 on: November 18, 2011, 09:06:46 pm » |
Have 18 digital I/O available outside of Rx/Tx that are commited to serial port in this case. Use 15 of them: D2,3,4,5,6,7,8,9,10,11,12,13,14,15,16 (A0-A5 are also D14-D19) Why resistors at all? Use internal pullups on input pins, buttons close to ground. // I'm totally winging it here, may need to check the Reference page for syntax on a couple of things...
byte D[15]; // declare 15 element array D[ ] = {2,3,4,5,6,7,8,9,10,11,12,13,14,15,16}; // map the Dx pins into the array, D[0] represents D2 ... D[14] represents D16 int x; // variable we'll use a bunch
void setup(){ for (x = 0; x<15; x=x+1){ // setup a loop to go from 0 to 14 to access the array elements pinMode (D[x], INPUT); // set the pins as inputs, recall: D[0] = D2 digitalWrite (D[x], HIGH); // enables internal pullup
Serial.begin(9600); // library takes care of setting D0, D1 as needed } // end setup
void loop(){
for (int x =0; x<15; x=x+1){ // set to read D[0] to D[14], if (digitalRead (D[x]) == 0){ // is a button pushed? value = x; // store the array index (?) that was found low, i.e. button was pushed // now act on the button that was pushed
switch (value){ // use this to jump to the code for the button that was pushed case 0: // code for D2 Serial.println(" button on D2 was pressed"); break;
case 1: // code for D3 Serial.println(" button on D3 was pressed"); break;
//etc
case 14: //code for D16 Serial.println(" button on D16 was pressed"); break; } // end switch
} // end if button pushed, go read the next one
} // end void loop
Give it a shot, see how it goes
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Edison Member
Karma: 21
Posts: 1353
Now, More Than Ever
|
 |
« Reply #8 on: November 18, 2011, 09:38:37 pm » |
"Why resistors at all?" With the "Analog buttons" the 15 resistors effect 15 voltage levels to an Analog input pin (they're all different values tied HI and with contact each effects a different voltage there) - one pin versus many. A straight digitalRead or a shift register data shift routine will probably go a lot faster though.
|
|
|
|
|
Logged
|
Don't Be Upset By The Results You Didn't Get With The Work You Didn't Do
|
|
|
|
Global Moderator
Boston area, metrowest
Offline
Brattain Member
Karma: 240
Posts: 16426
Available for Design & Build services
|
 |
« Reply #9 on: November 18, 2011, 09:43:50 pm » |
Given that no other IO is specified, go the straightforward route: digitalReads of "[push]buttons" being Hi/Lo.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 5
|
 |
« Reply #10 on: November 22, 2011, 02:29:20 pm » |
Great, thank you guys for great reply. well yeah is my fault to call pushbutton as Analog haha i will try to use matrix 4X4 i guess is the most easy solution
|
|
|
|
|
Logged
|
|
|
|
|
Western New York, USA
Offline
Faraday Member
Karma: 17
Posts: 3456
|
 |
« Reply #11 on: November 22, 2011, 10:45:32 pm » |
well yeah is my fault to call pushbutton as Analog haha No, the problem is that pushbuttons are being called buttons.Don
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 5
|
 |
« Reply #12 on: November 25, 2011, 12:12:14 am » |
Thank you a lot, now i understand more less how it work, appriciate your help! Have 18 digital I/O available outside of Rx/Tx that are commited to serial port in this case. Use 15 of them: D2,3,4,5,6,7,8,9,10,11,12,13,14,15,16 (A0-A5 are also D14-D19) Why resistors at all? Use internal pullups on input pins, buttons close to ground. // I'm totally winging it here, may need to check the Reference page for syntax on a couple of things...
byte D[15]; // declare 15 element array D[ ] = {2,3,4,5,6,7,8,9,10,11,12,13,14,15,16}; // map the Dx pins into the array, D[0] represents D2 ... D[14] represents D16 int x; // variable we'll use a bunch
void setup(){ for (x = 0; x<15; x=x+1){ // setup a loop to go from 0 to 14 to access the array elements pinMode (D[x], INPUT); // set the pins as inputs, recall: D[0] = D2 digitalWrite (D[x], HIGH); // enables internal pullup
Serial.begin(9600); // library takes care of setting D0, D1 as needed } // end setup
void loop(){
for (int x =0; x<15; x=x+1){ // set to read D[0] to D[14], if (digitalRead (D[x]) == 0){ // is a button pushed? value = x; // store the array index (?) that was found low, i.e. button was pushed // now act on the button that was pushed
switch (value){ // use this to jump to the code for the button that was pushed case 0: // code for D2 Serial.println(" button on D2 was pressed"); break;
case 1: // code for D3 Serial.println(" button on D3 was pressed"); break;
//etc
case 14: //code for D16 Serial.println(" button on D16 was pressed"); break; } // end switch
} // end if button pushed, go read the next one
} // end void loop
Give it a shot, see how it goes
|
|
|
|
|
Logged
|
|
|
|
|
|