Go Down

Topic: DIP switch? (Read 846 times) previous topic - next topic

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

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.

CrossRoads

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.


WizenedEE

I think your code may look a little more like this:
Code: [Select]

if (digitalRead(switch1Pin)) {
  digitalWrite(LED1Pin);
}
else if (digitalRead(switch2Pin)) {
  digitalWrite(LED2Pin);
}

CrossRoads

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.

Thanks again to everybody.

Go Up