



Hi,
I added some code to the example program to send an alphaumeric string to com port to identify the input but the iF statement does not work as expected and cannot understand why ? It always goes to else line regardless of buttonState being 0 or 1
Advice would be appreciated
Cheers
/*
DigitalReadSerial with on-board Pushbutton
Reads a digital input on pin 5, prints the result to the serial monitor
Harware Required:
* MSP-EXP430G2 LaunchPad
This example code is in the public domain.
*/
// digital pin 5 has a pushbutton attached to it. Give it a name:
int pushButton = 5;
// the setup routine runs once when you press reset:
void setup() {
// initialize serial communication at 4800 bits per second:
Serial.begin(4800); // msp430g2231 must use 4800
// make the on-board pushbutton's pin an input pullup:
pinMode(pushButton, INPUT_PULLUP);
}
// the loop routine runs over and over again forever:
void loop() {
// read the input pin:
int buttonState = digitalRead(pushButton);
// print out the state of the button:
Serial.print(buttonState);
if (buttonState =0)
{
Serial.print("p1");
}
else
{
Serial.print("P1");
}
delay(1000); // delay in between reads for stability
}
I added some code to the example program to send an alphaumeric string to com port to identify the input but the iF statement does not work as expected and cannot understand why ? It always goes to else line regardless of buttonState being 0 or 1
Advice would be appreciated
Cheers
/*
DigitalReadSerial with on-board Pushbutton
Reads a digital input on pin 5, prints the result to the serial monitor
Harware Required:
* MSP-EXP430G2 LaunchPad
This example code is in the public domain.
*/
// digital pin 5 has a pushbutton attached to it. Give it a name:
int pushButton = 5;
// the setup routine runs once when you press reset:
void setup() {
// initialize serial communication at 4800 bits per second:
Serial.begin(4800); // msp430g2231 must use 4800
// make the on-board pushbutton's pin an input pullup:
pinMode(pushButton, INPUT_PULLUP);
}
// the loop routine runs over and over again forever:
void loop() {
// read the input pin:
int buttonState = digitalRead(pushButton);
// print out the state of the button:
Serial.print(buttonState);
if (buttonState =0)
{
Serial.print("p1");
}
else
{
Serial.print("P1");
}
delay(1000); // delay in between reads for stability
}