Pages: [1] 2   Go Down
Author Topic: Rotary Switch Colour Selector help needed  (Read 1332 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello all first off sorry if this is in the wrong Section I am new and thought this might be the best place if not Sorry admins and could you please move it to the Right Section thank you, now on to what I need help with

I have a 12 way 1 pole Rotary Switch which I am hoping to use as my selection changer for my blinkM I2C RGB LED I am using a Uno Board so you known what layout I have

now I will not need all 12 points on it but the colours I am setting to are in Hex value so I known them well thanks to my web site building days Below is the list of colours I am using.

I am not sure how to get the Switch to interact with the Arduino I am hoping I can use 1 or 2 pins for the input but as I am beginner at this I am not sure so any help you can offer would be most greatful

Colour List
  • Red FF0000
  • Green 00FF00
  • Blue 0000FF
  • Purple 8000FF
  • Orange FF8000
  • White FFFFFF
  • Random


Links to Items
BlinkMI2C LED
Rotary Switch Code  FF73Q
Logged

Finland
Offline Offline
Sr. Member
****
Karma: 1
Posts: 270
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You will need more than one or two pins.

One of the switch's pins is the center pole (or common terminal or something like that, I'm not sure what the correct English term is). When you rotate the switch, it connects the center pole with one of the 12 other terminals. Connect the center pole to the Arduino's ground and the other terminals (as many of them as you need) to different digital input pins, for example pins 2 to 8. In you sketch, put the pins to the input-mode and enable the internal pull-up resistors. Associate the colors with different pins, for example 2=red, 3=green, ... 8=random. Read the pin values. The pin that is LOW is the one that is selected.

« Last Edit: October 17, 2012, 02:02:43 pm by pekkaa » Logged

0
Offline Offline
Shannon Member
****
Karma: 199
Posts: 11671
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

It you use an analog input you can wire resistor between each switch position to make a multi-way voltage divider - the wiper terminal will then have a voltage that depends on the switch setting and can be read by analogRead () - the same way you would read a potentiometer (but with a fixed set of voltages, not continually varying).
Logged

[ I won't respond to messages, use the forum please ]

Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

It you use an analog input you can wire resistor between each switch position to make a multi-way voltage divider - the wiper terminal will then have a voltage that depends on the switch setting and can be read by analogRead () - the same way you would read a potentiometer (but with a fixed set of voltages, not continually varying).

your way is very confusing to me I am new to electronics so I think it would be best to do it with the first suggestion thank you though I am sure it makes sence just not to a noobie like me
Logged

Valencia, Spain
Offline Offline
Faraday Member
**
Karma: 143
Posts: 5301
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello all first off sorry if this is in the wrong Section I am new and thought this might be the best place if not Sorry admins and could you please move it to the Right Section thank you, now on to what I need help with

I have a 12 way 1 pole Rotary Switch which I am hoping to use as my selection changer for my blinkM I2C RGB LED I am using a Uno Board so you known what layout I have

A switch like that needs an awful lot of Arduino pins to connect it (12 of them).

If pins are important you'd be much better off with a "rotary encoder". This will do the same thing but only needs two pins for the shaft rotation. You also get a built-in push button (push the shaft down) which you can connect to a third pin.

« Last Edit: October 20, 2012, 05:00:24 pm by fungus » Logged

No, I don't answer questions sent in private messages (but I do accept thank-you notes...)

Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


A switch like that needs an awful lot of Arduino pins to connect it (12 of them).

If pins are important you'd be much better off with a "rotary encoder". This will do the same thing but only needs two pins for the shaft rotation. You also get a built-in push button (push the shaft down) which you can connect to a third pin.

thank you that is what I need I was not sure now I known just got to work out how to do the data from that to it now
Logged

Finland
Offline Offline
Sr. Member
****
Karma: 1
Posts: 270
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

A switch like that needs an awful lot of Arduino pins to connect it (12 of them).

He only needs to connect 7 pins. He can leave the rest of the pins disconnected.

If pins are important you'd be much better off with a "rotary encoder". This will do the same thing but only needs two pins for the shaft rotation. You also get a built-in push button (push the shaft down) which you can connect to a third pin.

I believe it is a bit more complicated to read gray code/ rotary encoder. But perhaps there are Arduino libraries for that, though.
Logged

USA
Offline Offline
God Member
*****
Karma: 14
Posts: 644
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I believe it is a bit more complicated to read gray code/ rotary encoder. But perhaps there are Arduino libraries for that, though.

Yes, there is a whole section of the Playground with different examples of how to use rotary encoders with Arduinos.
Logged

Finland
Offline Offline
Sr. Member
****
Karma: 1
Posts: 270
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I believe it is a bit more complicated to read gray code/ rotary encoder. But perhaps there are Arduino libraries for that, though.
Yes, there is a whole section of the Playground with different examples of how to use rotary encoders with Arduinos.

Yes, but it would still be more complicated than using a rotary switch with each pin connected a different input pin. If this is Kobra299's fist Arduino project, I suggest going with the simpler alternative.
Logged

Valencia, Spain
Offline Offline
Faraday Member
**
Karma: 143
Posts: 5301
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Yes, but it would still be more complicated than using a rotary switch with each pin connected a different input pin. If this is Kobra299's fist Arduino project, I suggest going with the simpler alternative.

I don't think a rotary switch is as easy as you think... it would need quite a lot of code and I bet there's no library for it.

A rotary encoder library with examples is probably easier for a novice to get working.
Logged

No, I don't answer questions sent in private messages (but I do accept thank-you notes...)

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 361
Posts: 17259
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Yes, but it would still be more complicated than using a rotary switch with each pin connected a different input pin. If this is Kobra299's fist Arduino project, I suggest going with the simpler alternative.

I don't think a rotary switch is as easy as you think... it would need quite a lot of code and I bet there's no library for it.

Why in the world would a library be needed to check a fixed number of input pins (he listed seven choices) to see which is active? He needs to wire up seven input pins from his single pole switch and do a series of if tests, that hardly justifies a library solution does it?

A rotary encoder library with examples is probably easier for a novice to get working.

I would dispute that unless the OP has requirements above the simple one he defined.

Lefty


Logged

USA
Offline Offline
God Member
*****
Karma: 14
Posts: 644
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

A rotary switch is going to be like a bunch of non-matrixed buttons/switches, so in this case seven input pins will be required.  These pins will also need either be polled or have pin-change interrupts setup.  The code might be fairly simple, but fungus is right that there will be significantly more of it to deal with.  On the other hand, there is code applicable avialable for using a rotary encoder, it would only need a couple of pins, and introduces the concept of using I/O pins to represent binary integers (AKA bit banging) which can be useful later on.
Logged

Valencia, Spain
Offline Offline
Faraday Member
**
Karma: 143
Posts: 5301
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I would dispute that unless the OP has requirements above the simple one he defined.

Ah, he only wants seven fixed choices...I guess that's not difficult to code...  smiley-grin

(Not very future-proof though)


« Last Edit: October 23, 2012, 02:02:40 pm by fungus » Logged

No, I don't answer questions sent in private messages (but I do accept thank-you notes...)

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 361
Posts: 17259
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

A rotary switch is going to be like a bunch of non-matrixed buttons/switches, so in this case seven input pins will be required.  These pins will also need either be polled or have pin-change interrupts setup.  The code might be fairly simple, but fungus is right that there will be significantly more of it to deal with.  On the other hand, there is code applicable avialable for using a rotary encoder, it would only need a couple of pins, and introduces the concept of using I/O pins to represent binary integers (AKA bit banging) which can be useful later on.

Not saying a rotary encoder wouldn't work and might very well even be a more elegant and resource saving solution, but to say a simple 7 input pin polling sketch is other then a very simple task is assuming more requirements then the OP stated. Recall also that the OP stated that he already has the switch in hand. I would think it's a very good method for a beginner first learning programming and hardware electronics, rather then relying on a library based solution.
Lefty
« Last Edit: October 23, 2012, 01:59:42 pm by retrolefty » Logged

USA
Offline Offline
God Member
*****
Karma: 14
Posts: 644
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Not saying a rotary encoder wouldn't work and might very well even be a more elegant and resource saving solution, but to say a simple 7 input pin polling sketch is other then a very simple task is assuming more requirements then the OP stated. Recall that the OP stated that he already has the switch in hand. I would think it's a very good method for a beginner first learning programming and hardware electronics, rather then relying on a library based solution.

Well from a programming stand point, I think a seven level deep block of nested if-then-else statements evaluating if each pin is TRUE would be fairly simple.  However, it would take up quite a few lines by itself and be somewhat cumbersome if you ever had to debug it. smiley-wink  Furthermore it's perhaps the most compact ways to express the logic without getting into rather arcane tricks.

Yet, you are correct that using the available hardware is probably the best approach for this particular device since it's definately a workable solution.  Still it doesn't hurt to bring up the alternatives, even if they aren't used.  There's always the next project... smiley
Logged

Pages: [1] 2   Go Up
Jump to: