Jump to content
43oh

Serial Switch


Recommended Posts

Hello Everyone:

 

I am a newbe to the MSP430G2 Launchpad,  I have been trying to get the Serial Switch project to work.  all that happens is all the led's light when the program starts, but I can not get them to go off and I am using a msp430g2452 chip, what am I missing or doing wrong I am using Energia to program.  I have had some other programs work, even receiving serial data from the launchpad (reading analog inputs and printing to the serial monitor), just not this one (serial switch).

 

Thanks for any and all help.

W8TFI

Link to post
Share on other sites

Thank you for the reply, this is the code I am trying to get to work. I am also using the board that is version 1.5 

 

W8TFI

 

/*
  Switch statement  with serial input
 
  Demonstrates the use of a switch statement.  The switch
  statement allows you to choose from among a set of discrete values
  of a variable.  It's like a series of if statements.
 
  To see this sketch in action, open the Serial monitor and send any character.
  The characters a, b, c, d, and e, will turn on LEDs.  Any other character will turn
  the LEDs off.
 
  The circuit:
  * 5 LEDs attached to digital pins 2 through 6 through 220-ohm resistors
 
  created 1 Jul 2009
  by Tom Igoe 
  modified 30 Apr 2013
  by Adrian Fernandez 
 
  This example code is in the public domain.
 
 */
 
void setup() {
  // initialize serial communication:
  Serial.begin(9600); 
  // initialize the LED pins:   
 
   for (int thisPin = 2; thisPin < 7; thisPin++) {
        digitalWrite(thisPin, LOW);
   }
}
 
void loop() {
  // read the sensor:
  if (Serial.available() > 0) {
    int inByte = Serial.read();
    // do something different depending on the character received.  
    // The switch statement expects single number values for each case;
    // in this exmaple, though, you're using single quotes to tell
    // the controller to get the ASCII value for the character.  For 
    // example 'a' = 97, 'b' = 98, and so forth:
 
    switch (inByte) {
    case 'a':    
      digitalWrite(2, HIGH);
      break;
    case 'b':    
      digitalWrite(3, HIGH);
      break;
    case 'c':    
      digitalWrite(4, HIGH);
      break;
    case 'd':    
      digitalWrite(5, HIGH);
      break;
    case 'e':    
      digitalWrite(6, HIGH);
      break;
    default:
      // turn all the LEDs off:
      for (int thisPin = 2; thisPin < 7; thisPin++) {
        digitalWrite(thisPin, LOW);
      }
    } 
  }
}
Link to post
Share on other sites

For starters - seems to be missing pinMode to set those pins to be outputs.  (So not sure that your code can change the pin state.)

 

How did you wire the LEDs - is a pin LOW going to turn them on, or off?

(i.e. LEDs connected through resistor to what - ground?  +3.3v?)

 

Might also try echoing a character to the serial line based on what character you received (e.g. a -> serial.print("A")).

Might help you see where you code is/isn't working.

Link to post
Share on other sites

So which code are you using, the one posted in the message above, or the one linked to on the web page?

(They are different - the one on the web page does 

pinMode(thisPin, OUTPUT);

in the setup, as it should.  The code in message above is missing the pinMode, and therefore should not work. ).

 

By the way - when posting code please use the code attribute, it is the <> icon in the editor.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...