eamonb 1 Posted March 4, 2014 Share Posted March 4, 2014 This vcode below gice the following error Blink1_EB.ino: In function 'void loop()':Blink1_EB.ino:32:8: error: 'val' cannot appear in a constant-expressionBlink1_EB.ino:32:2: error: case label '<expression error>' not within a switch statementBlink1_EB.ino:32:13: error: expected ':' before '{' tokenBlink1_EB.ino:34:4: error: case label '1' not within a switch statementBlink1_EB.ino:41:4: error: break statement not within loop or switchBlink1_EB.ino:43:2: error: case label '0' not within a switch statementBlink1_EB.ino:50:2: error: break statement not within loop or switch /* This is not working yet - EB 4.02.2014 Blink The basic Energia example. Turns on an RED and Green LED when the switch is High and off if SW2 is LOW, repeatedly. Pin 2 has an LED connected on MSP430 boards, has a name 'RED_LED' in the code. Pin 14 has an LED connected on MSP430 boards, has a name 'GREEN_LED' in the code. Hardware Required: * MSP-EXP430G2 LaunchPad This example code is in the public domain.*/ int val=0; // the setup routine runs once when you press reset:void setup() { // initialize the digital pin as an output. pinMode(RED_LED, OUTPUT); pinMode(GREEN_LED, OUTPUT); pinMode(P1_3, INPUT); } // the loop routine runs over and over again forever:void loop() { val = digitalRead(P1_3); case (val) { case 1 : digitalWrite(RED_LED, HIGH); // turn the LED on (HIGH is the voltage level) // digitalWrite(GREEN_LED, LOW); digitalWrite(GREEN_LED, HIGH); delay(100); // wait for a second break; case 0 : digitalWrite(RED_LED, LOW); // turn the LED off by making the voltage LOW // digitalWrite(GREEN_LED, HIGH); digitalWrite(GREEN_LED, LOW); delay(100); // wait for a second break; }} I would appreciate advice on what is causing the problem Quote Link to post Share on other sites
energia 485 Posted March 4, 2014 Share Posted March 4, 2014 case (val) needs to be switch(val) Quote Link to post Share on other sites
eamonb 1 Posted March 5, 2014 Author Share Posted March 5, 2014 Thanks energia . That solved it . One other error in this code - Replace pinMode(P1_3, INPUT); with pinMode(P1_3, INPUT_PULLUP); Then it WORKS!!! Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.