Controlling MIDI switch doesn't work

I'm trying to do sketch 9.6 in Arudino Cookbook and the switch seems to not even be registered while running it. Thought maybe I typed something wrong so I downloaded the file from the site and it didn't make a difference.
1 person has
this question
+1
Reply
  • Tai Hake (Official Rep) July 25, 2012 16:04
    Hi Jason,
    Sorry for the delay in responding to your query. I'd be happy to forward your issue to the editors to see if they have any insight as to why the code isn't working properly.
    Have you verified that all the physical components are functioning correctly?

    Cheers,
    Tai H.
    Customer Service Rep,
    O'Reilly Media
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. kidding, amused, unsure, silly indifferent, undecided, unconcerned sad, anxious, confused, frustrated happy, confident, thankful, excited

  • Tai Hake (Official Rep) July 25, 2012 18:55
    Hi Jason,
    The editor has suggested the following steps:
    * Check all the wires and connections
    * Check the type of switch; this example assumes a switch that is normally open and makes a connection when pressed
    * Add a println() to the loop() function to help debug:

    const int switchPin = 2;

    void setup() {
    Serial.begin(9600);
    pinMode(switchPin, INPUT);
    digitalWrite(switchPin, HIGH);
    }

    void loop() {
    if (digitalRead(switchPin == LOW)) {
    Serial.println("Switch closed");
    }
    }

    Also note that the two lines above are important:

    pinMode(switchPin, INPUT);
    digitalWrite(switchPin, HIGH);

    This sets the pull up resistor, which makes sure that the pin is high when the switch is open.

    Hope that helps!

    Cheers,
    Tai H.
    Customer Service Rep,
    O'Reilly Media
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. kidding, amused, unsure, silly indifferent, undecided, unconcerned sad, anxious, confused, frustrated happy, confident, thankful, excited

  • Thanks I'll go look into a switch just in case that's the issue. The code seems right, though I'll put in the printLn() to make sure.
    Thanks again.
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. kidding, amused, unsure, silly indifferent, undecided, unconcerned sad, anxious, confused, frustrated happy, confident, thankful, excited