Go Down

### Topic: DIP switch? (Read 1 time)previous topic - next topic

#### vbsaltydog

##### Dec 02, 2011, 10:19 pm
I am doing an arduino build that has several possible programming scenarios. I want to have 4 different scenarios and an indicator LED to signify which scenario is active. Is this as simple as adding a proto shield and wiring the LEDs and DIP switch to the proto shield, running the proper logic based on the DIP switch value and lighting the proper LED in each logic code block?

Code: [Select]
`if (dip-switch-value == '1'){light LED 1;...}if (dip-switch-value == '2'){light LED 2;...}`

#### AWOL

#1
##### Dec 02, 2011, 10:23 pm
The chances of dip minus switch minus value being the same as an ASCII '1' seem pretty remote
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.
I speak for myself, not Arduino.

#2
##### Dec 02, 2011, 10:32 pm
Yep, little syntax work needed

Otherwise, just need 8 switches
'1' = B00110010  www.asciitable.com

Maybe use Hex instead, and 2 switches
if (dip_switch = 0x00){  // 0x00, 0x01, 0x02, 0x03
...
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

#3
Thanks

#### WizenedEE

#4
##### Dec 03, 2011, 06:50 am
I think your code may look a little more like this:
Code: [Select]
`if (digitalRead(switch1Pin)) {  digitalWrite(LED1Pin);}else if (digitalRead(switch2Pin)) {  digitalWrite(LED2Pin);}`

#5
##### Dec 03, 2011, 07:12 am
reading of the pins was not actually shown anywhere, assumed to have been done earlier ...
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

#### vbsaltydog

#6
##### Dec 04, 2011, 01:49 am
Thanks again to everybody.

Go Up