Pages: [1]   Go Down
Author Topic: DIP switch?  (Read 525 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 23
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
if (dip-switch-value == '1')
{
light LED 1;
...
}
if (dip-switch-value == '2')
{
light LED 2;
...
}
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 238
Posts: 24305
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The chances of dip minus switch minus value being the same as an ASCII '1' seem pretty remote  smiley-wink
Logged

"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.

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 436
Posts: 23623
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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
...
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

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

Thanks
Logged

Offline Offline
Edison Member
*
Karma: 17
Posts: 1041
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I think your code may look a little more like this:
Code:
if (digitalRead(switch1Pin)) {
  digitalWrite(LED1Pin);
}
else if (digitalRead(switch2Pin)) {
  digitalWrite(LED2Pin);
}
Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 436
Posts: 23623
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

reading of the pins was not actually shown anywhere, assumed to have been done earlier ...
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

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

Thanks again to everybody.
Logged

Pages: [1]   Go Up
Jump to: